How to enable or disable SELinux on centOS

The SELinux stands for Security-Enhanced Linux where it is a linux kernel security module. It is enabled by default on most of the linux distribution that we use for servers like centOS. It provides  enhanced security measurements. It gives you fine control over all programs and daemons  on their activities like communicating with out side programs  or controlling whether to establish a outside connections for a particular program.

It is always recommended to have SELinux enabled on a server to avoid common security glitches.

To query the current status of SELinux  use the following commands

The above command will report the current status  of SELinux. Whether SELinux is enforcing, permissive, or disabled. If it is already disabled.

Disabling SELinux

Open the file  /etc/selinux/config  and change the option SELINUX to disabled

if you open file you would see something like

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing – SELinux security policy is enforced.
# permissive – SELinux prints warnings instead of enforcing.
# disabled – No SELinux policy is loaded.
# SELINUXTYPE= can take one of these two values:
# targeted – Targeted processes are protected,
# mls – Multi Level Security protection.

If SELinux is enabled you would see enforcing replace it with disabled.

You should restart the machine to take effect If you change SELINUX status from Enabled to Disabled or vice versa.

Enabling SELInux

To enable SELinux follow the below instructions,

  1. Open the file /etc/selinux/config  
  2. Change option SELINUX from disabled to enforcing
  3. Restart the machine

Change mode

To change the mode of SELinux which is running


Note: You need administrator privileges to either enable or disable SELinux

SIP Request Methods Response Codes

SIP Request Methods Response Codes.

SIP Request Methods

There are several different Request methods to server different purposes. SIP borrowed headers and body format from the protocol HTTP. Like HTTP SIP also has different methods. following table will describe those request methods


SIP Request Methods
S.No Method Description
1 REGISTER Registers to receive inbound calls on registrar or SIP server
2 INVITE Established a new session
3 ACK Confirms that message/request has been received
4 BYE Ends Session
5 CANCEL Cancels establishing session
6 OPTIONS Queries capabilities of server
7 PARK Provisional Acknowledgement
8 SUBSCRIBE Subsribes for an Notifications from the Notifier
9 NOTIFY Notify the subscriber a new Event
10 PUBLISH Publish and event to the Server
11 INFO Sends mid-session information
12 REFERER Asks the recipient to issue call transfer
13 MESSAGE Transport Insant Message
14 UPDATE Modifies the state of a session without changing the state of the dialog.


SIP Responses

Like I mentioned earlier, SIP protocol borrowed few things from protocol HTTP. SIP borrowed response code from HTTP. Most of response codes are similar to HTTP and  SIP extends them codes to 6xx.

SIP Response Codes
S.No Code Description
1 1xx Informational responses
2 2xx Success Responses
3 3xx Redirect Responses
4 4xx Request Failure/Client Error
5 5xx Server Error
6 6xx Global Failures

How to send email command line in linux

We all know that email plays a vital role in our communication system. We will see how to send mail from command line in this article.

Assuming that you have postfix instaled on your machine. You can send the mail from command line by connecting to your local mail server. You will get the utility sendmail with postfix.

send email using sendmail

Send email using telnet

We all now about telnet command. It is very helpful to debug and understand the protocols. Here is the simple mail sent using telnet

In the above example we connected to the SMTP server as a client which is running on localhost. We gave commands to the server to send a mail. Please note that  the data ends with   <CR><LF>.<CR><LF> . to indicated it is the end of data. As you can see  . (dot) we mentioned  at the end.

Once we connected, we pass the set commands to server to write and send a mail. Here are the few SMTP commands

SMTP Commands

  •  HELO
  • MAIL
  • RCPT
  • DATA
  • RSET
  • VRFY
  • EXPN
  • HELP
  • NOOP
  • QUIT

We used MAIL, RCPT and QUIT commands in the above example. To understand these commands go through rfc . You may not need to understand low level protocol concepts of SMTP unless if you are really interested or you are working with SMTP.



How to edit or change commit history using git rebase

Do you ever wonder about rewriting git commit history. Here is how you can do. One great advantage we get with git version control system is that, we can edit or rewrite the history of commits. Some times may be you want to publish the different commit history or for some reason you may want to edit the few chunks for commit history.

There are different ways to edit the history of commits. There is one quick way to edit the very last commit or HEAD. Using following command

If you want to edit selected commits in the history, you can do it using feature called rebasing in git. Rebasing is a great feature in git. Other than process called merging  we can use rebasing to merge different branches in different way other than usual git merge. One of the advantage is we can rewrite the history to make sure commit history looks like the way you want.

We have to use interactive rebasing to edit the commit history, using the following command

where we specify the commit  which is parent of the commit  from which you want to edit the commit history

Lets say I chosen the commit from where I want to edit the history, I would type the following command

If you perform above command, you wold see the following content in the default editor,

The above content is self explanatory, if you want to remove commits just remove corresponding commit line. if you want to abort interactive rebase any time use git rebase –abort. You should notice that your last commit is at bottom. These commits from chronological from top to bottom.

If you chose to edit the selected commits, let’s say want to change author, you have to replace the word pick with word edit for that corresponding commits and quit the editor by saving. Then you will stop at the first commit, you can change the author using following command

Like wise you can change the commit message as well. Of course you can also change the content of files to commit

and then to continue rewriting history using following command,

You have to  repeat these steps for each commit that you change the  word pick to edit. Git will stop to let you amend the commit. Once you are finished with specific commit, you can proceed further by using rebase command using command line argument –continue. 

Once you finished with rebase, you may see the following message

If you get conflicts, you have to resolve them in the way you resolve for merging process. Once you resolved the conflicts by removing conflict markers(>>>>>> ======= <<<<<<<). Use to git add  to mark them resolved. Then continue to rebase using command



Beware of rebase,  you may corrupt the commit history  of your team members and it may leads to confusion.

If you are learning don’t try to experiment it on real repository. Instead you create the dummy repo and get hands on experience.

You may produce merge conflicts sometimes, you may have to resolve to proceed the rebase

Want to read more?





How to truncate empty lines using sed

Sed command is very helpful  for text processing. It’s just matter of regular expression. Here is how you can  truncate empty lines  in the file using command sed.

The above command will give you the output by deleting empty lines. If you want to modify the original file itself. You use the option -i


I have a file with following data and named as numbers

Now see, the way to truncate empty lines using sed

The above command won’t change the original file. If you want to change original use option -i


Sed interprets ‘/^s*$/d’  and giving us the desired output. Here  text between slashes(/regular expression/) represent the regular expression followed by sed command “d”  means delete.  So command sed matches the lines with given regular expression. If it finds the match it applies the command.


How to change hostname of the linux machine

Host name is the name or label which is assigned to your computer that is used to identify and communicate. Usually you can choose your hostname while installation of operating system. If you take a server you may get machine with pre labeled hostname. It is always possible to change the hostname.

Note: You need root or sudo access to change the hostname of the machine.

There are different ways to changes the hostname of the computer. you  canchoose one of them. There is a volatile way and not volatile way. If you want change host name of the computer permanently you need to write your hostname in couple of files. If you want to change instantly (temporarily) you can change using couple of commands, but this change is volatile you will loose your hostname after reboot.

Using command hostname

Now, we will see  the way to change hostname instantly. This is not a persistent change. You will loose after reboot

The command hostname without arguments will display the current hostname of the system

Where you can give qualified hostname in the place of If you are using desktop linux(ubuntu) you can observer your change on (new session)shell, ie, user@hostname

Using sysctl

sysctl is the command that we use to configure kernel parameter at runtime. We can change hostname using this command as well. You can query the hostname using sysctl  as

To change hostname,

Changes made using either way are volatile. To make permanent change. Follow the below steps.

Edit hostname file

You have to edit the file /etc/hostname to make persistent change. This file contains only the hostname. To update hostname,

Including the above change you may need to edit /etc/hosts file. Change the   old_hostname  section. Replace old hostname with new hostname if you find.

it could be something like

Restart the machine to get your changes applied. You can combine both ways to get new hostname now and then after reboot.

Using hostnamectl

The linux distributions are also providing the command called hostnamectl to manage and set the hostname.

hostamectl with out any arguments will give the system hostname and other misc details

Check hostname

Set the hostname using hostnamectl

Chaging hostname using nmcli

Oh yeah, you can change the hostname using command nmcli as well. This command can be used to set the static hostname.

Query the hostname

Change the hostname


How to listen on an arbitrary port and print the data which is coming using netcat

We are well known about  telnet which is pretty much handy tool to debug and open a TCP connection to remote server:port. But we want the tool which will listen on given port for connections unlike telnet. Yeah, there is tool called netcat. Usually it comes with many linux distributions by default, also called nc. There is also a windows version . According to the scope of the article we will see how to open a TCP or UDP connection and print the data sent by connected clients, but this tool  is more than capable of just listening on port for a connection.


nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port] [-s source_ip_address] [-T ToS] [-wtimeout] [-X proxy_protocol] [ -x proxy_address[ :port]] [hostname] [port[s]]


Listen for UDP on specific host and port using netcat

Listen for the connections and print the data sent by the clients

nc -lvu [IP Address] 5060

nc is the command alias for netcat.

The break down of above command

l        Forcing netcat to listen on given host and port instead of opening/making  connection with remote host and port

v          Give verbose output

u          Use UDP. That is, listen for UDP on give port, by default it listens for TCP unless we give this option.

Ip Address   It is optional, if it is not specified localhost will be used

Port                You must specify the port on which nc should listen on.

Listen for TCP on specific host and port using netcat

This is same as UDP mentioned above except we haven’t specified the option -u . Where netcat will listen on TCP port by default with out that option.

Now netcat is listening on the given port on localhost. You can connect to this TCP port from the other  tab(terminal)   using either netcat or telnet

Connect Using Telnet

After  connected, type “Hello”, you should see that text in the tab where netcat is listening

Connect Using NetCat

After   connected,  we sent some text. It should be displayed on tab where nc is listening.

You can quit the client by sending interrupt  CTRL + D. If you quit the client, the server(nc command) will also stop listening. We can use the option -k     to forces nc to stay listening for another connection after its current connection is completed.  It is an error to use this option without the -l option.

I hope, these examples gave you some good understanding. As you can see, we can use nc as both server and client. Practically it is more capable than you think. If you are networking geek or dealing with network application or protocols. You can find this handy for your debugging purpose.

Case Studies

Let’s say, I have web hook URL configured on other 3rd party website. I want to check whether that server is sending events or not. If sending, I would like to see how is API and message format and I don’t have my program ready yet. In such a case, you simply listen on host and port which are configured on 3rd party web site to receive events and simply you can check the data received by nc 

Something like,

The tool netcat (nc) is very powerful tool, it is very simple tool but there are lot of possibilities. Anti-viruses on windows will detect this program as malware sometimes. Where it can also be used as a backdoor.

How to find width and height of the terminal in linux

You may wonder how do I find the number of characters will fit in a line in the terminal or size of the window. There are several ways to figure out the size of the window. Let’s go through the different ways to find size of terminal

First lets see different ways that you can use to figure out width and height of terminal in terms of characters

  1. Using command tput
  2. Using command stty
  3. Using environment variables

    Using command tput

The command tput is very helpful to query the terminal information and to do some other simple operations like placing cursor at required random position.

Here is how you can find the width and height of terminal. You may call it as number of rows and columns

Using command stty

This is also one of the command which useful to query,change and print terminal line settings.

The simple output of stty command regarding information of terminal

Command to get lines and columns count in characters


Using environment variables

On you terminal always you can query the size of the terminal using the environment variables $COLUMNS

Values of those environment variables will change if size of the terminal window changes.

How to check certificate information of web server using openssl

In this article we will see how to check certificate information of webserver using command line tool openssl

The below command will get you the valid period of the ssl certificate.

To check the certificate information of web server, use the following command. Here I’m using in this example

Export certificate into a file

If you want to extract the public key from the certificate, here is how you can do


[1] Certificates and Encodings