One liner command to insert IP and hostname in /etc/hosts

This a very useful One liner command to insert IP and hostname into /etc/hosts file and is particularly useful when it comes to kickstart scripts wherein you need to have /etc/hosts entry for the newly provisioned VM and get it enrolled to various applications that include Red Hat IDM/ FreeIPA and Puppet to start with.

Run the following command to insert IP and hostname in /etc/hosts

# echo -n `ifconfig eth0 | grep inet | awk 'NR==1{print $2}' | cut -c6-18`" ";hostname;

Output:

172.16.66.212 rasst.vh.local

echo -n = "Does not output the trailing newline and thats why you can print IP and Hostname in 1 line".

That's it and please do let us know via Contact Us if you come across any issues.

Linux Related Articles . . .

To generate a SHA256 certficate in linux all you need to do is run this openssl command and you will...
This a very useful One liner command to insert IP and hostname into /etc/hosts file and is particularly useful when...
Its possible to use awk in Alias command. I did that by simply just modifying some parenthesis and there you...
Its possible to run a script via Alias command. All you need is to modify the .bashrc and then source...
This article will guide you on creating a custom Self-signed SSL Certificate in no time. For creating one you would...