Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The title question says it all. I've built a machine running Ubuntu 9.10 Desktop (AMD 64) and need it to email it's IP address to a list of email addresses whenever it starts up.

share|improve this question
Can you elaborate on why you need to do this? Have you considered alternatives like dynamic dns? – Zoredache Feb 24 '10 at 19:54
Other machines are part of a domain that the ubuntu machine cannot join. I'd assume that setting up a dynamic dns service would require configuring other machines to use the dynamic dns server as one of their DNS's. I can't modify settings on other machines that will be accessing the ubuntu machine, but I can tell people if/when the IP address has changed. I'd prefer to automate that process. – Michael Prescott Feb 24 '10 at 20:18
up vote 4 down vote accepted

When a network interface is started scripts in /etc/network/if-up.d are ran. When the scripts are executed lots of environment variables are provided that include the IP address and other network parameters. It should be very easy to write yourself a if-up script that sends out an email with the information you want.

I think that doing a dynamic dns update would probably be more useful then an email, but perhaps you have some reasons you haven't mentioned.

Here is a old script I had that did something close to what you want.


# interface definitions
MSG_OUT_UP='outside interface is up. Address is:'



[ ! -x /etc/default/if_notify ] || exit 0

. /etc/default/if_notify

NAME=`hostname -f`

if [ "$IFACE" = "$IF_OUT" -a "$MODE" = "start" ] ; then
    if [ "$IF_IN" -a "$MSG_OUT_UP" -a "$EMAIL_OUT" ] ; then

if [ "$IFACE" -a "$MSG" -a "$ADDR" ] ; then
    echo -e "From:root@$NAME\nTo:$ADDR\nSubject:[IFNOTIFY] Interface $IFACE up on $NAME\n$MSG" \
            | sendmail -f root "$ADDR"
share|improve this answer
Thanks for the tip and code! So, I could drop a bash script into that folder and it would run. I seem to recall seeing script naming convention or perhaps a command for registering scripts to control the order in which they run, I'd assume there is a way to make my script run after all of the other environment variables are created. – Michael Prescott Feb 24 '10 at 20:22
The see man run-parts to get a handle on the naming convention and order scripts are ran. See man interfaces for details about all the ways you can run things during the network configuration. In the script above I assume the system has a working locally installed mail server. It may be configured to use some other as a smart host, apt-get install exim4 exim4-daemon-light. It should be possible to use an external mail server with some other command line tool, but I'll leave that up to you to find, or ask about in a separate question. – Zoredache Feb 24 '10 at 20:37
extra points for recommending exim as the MTA :) – BuildTheRobots Feb 25 '10 at 1:20
@Michael: The registration command you might be looking for is called update-rc.d. – Dennis Williamson Feb 25 '10 at 2:02

Your Answer


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.