Linux : How to show interface IP address at boot on the console with CentOS/RHEL7?

By | March 23, 2017

Particularly useful when building appliances or when you ship pre-build systems to a remote location where technical knowledge of people at the remote site is limited, you can easily make the system “print” the IP acquired by DHCP or even the static assigned one to the system console login.

You will need to create two scripts in order to have this working.

1. Create the script that will get the information from the “ifconfig” output :

vi /usr/local/bin/get-ipaddr.sh

2. Append the following (this example assume that the interface is eth0) :

ifconfig eth0 | awk '/inet/ {print $2}' | cut -f2 -d:

3. Change the permissions :

chmod 755 /usr/local/bin/get-ipaddr.sh

4. Create the second script that will invoque the first one and then send the information to the “issue” file :

vi /sbin/ifup-local

5. Append the following :

#!/bin/sh

if [ "$1" = lo ]; then
exit 0
fi

/usr/local/bin/get-ipaddr.sh >> /etc/issue
echo "" >> /etc/issue

6. Change the permissions :

chmod 755 /sbin/ifup-local

You can now reboot your system, it should print the IP below the system information.