Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a couple of linux virtual machines with bridged interfaces, and I'd like the IP address of the machine to show up after the machine boot (in the login, where it usually shows the release and kernel).

From what I can tell the message is picked up from /etc/issues, but I'm not sure how and when to write to it.

share|improve this question

3 Answers 3

up vote 8 down vote accepted

It's just a text file...you write to it the same way you'd send text to a file with any other shell script. Something like this would replace /etc/issue with just your ip address:

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

Obviously you can make this arbitrarily more complex, depending on what information you want in your /etc/issue file.

You can write to this file in your local equivalent of /etc/rc.d/rc.local (which typically executes after all the other startup scripts).

share|improve this answer
3  
Slightly more Linuxy to say ip address show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 –  Sorpigal Dec 6 '10 at 18:01
    
I'm not sure how that's more linuxy, but yes, that works too. –  larsks Dec 7 '10 at 16:33
1  
@larks: It's more linuxy because on linux ip is the tool you're supposed to use for this sort of thing. ifconfig is technically just for compatibility. –  Sorpigal Dec 17 '10 at 18:03

you can write it once. unfortunately there's no getty escape sequence to show the ip address of eth0 but there's an escape sequence you can use in /etc/issue to show the hostname: \n

you can always statically set the ip of the machine in /etc/issue by writing it directly into the file. beware that the file /etc/issue.net is used for remote logins so you may want to edit that as well.

anyway, after working in the terminal window you will loose the initial screen and the ip/host address information with it. best way is to set the hostname in the prompt (most linux distros do) using \h or \H or again, statically setting the ip address you know is set on the host in the PS1 variable you can set PS1 variable in /etc/profile on most linux distros.

share|improve this answer
    
This is just to know what IP to connect to after booting the vm, so setting it up as larsks says is enough :) –  Bruno Lopes Dec 6 '10 at 15:56

This script will add/remove IP addresses to/from the /etc/issue file as needed:

#!/bin/sh
PREFIX="Local IP addresses:"
IPADDRS=$(hostname -I | tr " " "\n" | grep -v "^$" | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tr "\n" " ")

perl -i -p -0777 -e "s/^$PREFIX[^\n]*\n\n//m; s/$/\n$PREFIX $IPADDRS\n/ if length('$IPADDRS')>6" /etc/issue

If you're using a Debian-based distro, it's best to place the script at these locations:

/etc/network/if-up.d/update-issue
/etc/network/if-post-down.d/update-issue

This way the scripts are executed everytime an interface comes up or goes down. Placing it in /etc/rc.d/rc.local has the disadvantage of beeing executed only one time during bootup.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.