06 December 2010

HowTo: Display IP Address at console login screen (Debian, *buntu)

This setup allows you to display the IP Address at the text login screen. The utility of this is somewhat limited but it works great for Virtual Machines (VirtualBox, VMware, etc) which may require people to log in from your network, but which don't really need a static IP Address.
The console login screen reads something like this:
Debian GNU/Linux <releasename> <hostname.domain.com> tty1
Note that the above <releasename> and <hostname.domain.com> will depend on your own setup. This information is generated in the file at /etc/issue so we just want to append the IP Address to this file.
Start with creating a script; I put myne at /etc/init.d/boot_prompt.sh since it gets run at bootup. Edit the file to include this info, which will get the IP Address and put it to the end of /etc/issue :
#!/bin/bash
IPADD=`/sbin/ifconfig | sed '/Bcast/!d' | awk '{print $2}'| awk '{print $2}' FS=":"`
echo " $IPADD" >> /etc/issue
We then want that scrip to run at boot up, so we run it from /etc/rc.local by putting the above script's path into /etc/rc.local above the line reading exit 0 :
/etc/init.d/boot_prompt.sh
We also need to make sure these scripts CAN run, so we make them both executable:
shell# chmod +x /etc/init.d/boot_prompt.sh
shell# chmod +x /etc/rc.local
Now, you no longer need to log in and run the 'ifconfig' command to get the dynamic IP Address of your virtual machine — the information is right there at the login prompt! Enjoy.

=-=-=-=-=
Powered by Blogilo