Buddy of mine asked me a question over chat today: “how do I show my machines’ IP at login prompt with out logging in?” He is referring to his Virtual Machine in this case. He does not want to have to log in to the server to see what ip it has (since its on dhcp) for him to ssh in or hit it from the browser. I could have answered him with a simple how to but what is the fun in that? So I decided to give some background on how login prompts are done and show what can be done.
When Linux server boots up, it calls a program called mingetty. This program creates that infamous login prompt as show in a screenshot:
You can see how server calls the mingetty program by looking at /etc/inittab. You will see a block like below:
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
When mingetty is called, it reads a file called /etc/issue. There are a lot of existing variables you use. For example the prompt shown above in example is:
CentOS release 5 (Final)
Kernel \r on an \m
All of the available variables are list here on this page: http://www.lamp-tips.com/man-pages/mingetty/
If you were paying attention in the beginning of the post and looked at all of the available variables you can use, you would notice there is nothing in there which talks about IP. Since there is no variables available, you would have to sort of hack it. Put following in your /etc/rc.local file:
echo "CentOS release 5 (Final)" > /etc/issue
echo "Kernel \r on an \m" >> /etc/issue
echo `ifconfig eth0 | grep inet | cut -d : -f 2 | cut -d \ -f 1` >> /etc/issue
Getting an ip part can be modified to check another adapter such as eth1, eth2, etc. Or you can get it another way if you want. That all there is too. Reboot, and you should see your changes.
[correction 4.24.08] you do not have to reboot to see your changes. Just press enter at the login prompt in console and it will re-read the issue file.
————————————-
DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.