A chronological documentation test project, nothing serious, really!

21 Jan 2009 IP address change notifier script

This is a simple bash script that is run by crontab every 5 minutes on a linux box.
It e-mails me the new address when a change of IP address is detected.

The script (


# Check if IP-address has changed. If a change has occured, mail me the new address
# Add the following line to crontab if you would like it to be run every 5 minutes:
# */5 * * * * ./

# The network interface I want to monitor

# File to keep the latest IP address

# Mail to this address when a change occur

# Read the previous IP address from file
source $IP_FILE

CURRENT_IP=`/sbin/ifconfig $NET_INTERFACE | sed -n "/inet addr:.*255.255.25[0-5].[0-9]/{s/.*inet addr://; s/ .*//; p}"`

if [ "$CURRENT_IP" != "$OLD_IP" ]
        # Send email about address change
        `echo "New IP address detected: $CURRENT_IP" | mail -s "New IP address" $MAILTO`

        # Write new address to file
        `echo "OLD_IP=$CURRENT_IP" > $IP_FILE`

The script can be downloaded here.

Tags: , , ,

Posted by

30 Nov 2007 Create virtual / alias IP address

This is the code to make an alias IP address on network interface ethX where X is a number to indicate the device we are attaching the IP.
ifconfig eth0:1 netmask up
Your machine will now answer on ping requests

You can see the result by running the command

ifconfig eth0:1


eth0:1    Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx
          inet addr:  Bcast:  Mask:
          Interrupt:17 Base address:0x1080

To take down this alias use

ifup eth0:1 down

You might experience that the new device/address won’t answer network requests to the IP address after moving it. This happens because the arp cache on the router most likely haven’t discovered that the IP address is on a new MAC address. A solution to this problem is to clear the arp info on the router using the arprelease command

arprelease eth0:1

This command can be downloaded from if it isn’t available on your linux distribution.

Tags: , , ,

Posted by

20 May 2007 Get your IP address

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

Tags: , ,

Posted by