Setting up IP Aliasing on A Linux Machine

 

 

Setting up IP Aliasing on A Linux Machine

 


Overview

IP Aliasing is built into the Linux 2.4.x kernel.

 


 

Configuration

  1. Log on as user "root".

  2. Configure the aliased network device/


    /sbin/ifconfig eth0:0 10.0.1.171 up
    /sbin/ifconfig eth0:1 10.0.1.172 up

  3. To re-establish the new IP address after a boot, put the above lines in /etc/rc.local

  4. Insert a line in /etc/hosts identifying new address. For example:

    10.0.1.171 machine1 machine1.mn.acme.com machine1.acme.com

  5. Setup the routes. First route the loopback, then the net, and finally, the various IP addresses starting with the default (originally allocated) one:

    /sbin/route add -net 127.0.0.0
    /sbin/route add -net 10.0.1.0 dev eth0
    /sbin/route add -host 10.0.1.170 dev eth0
    /sbin/route add -host 10.0.1.171 dev eth0:0
    /sbin/route add -host 10.0.1.172 dev eth0:1
    /sbin/route add default gw 10.0.1.1

  6. To verify results, run ifconfig

If you ever get locked out of the machine because of the aliased network device, you can run:

rm -f /etc/sysconfig/network-scripts/ifcfg-eth0:0
service network restart

 


 

Keeping settings through a reboot

To keep the IP alias settings through a reboot, config it in /etc/rc.d/rc.local.

#setting up IP alias interfaces
/sbin/ifconfig eth0:0 10.0.1.171
/sbin/ifconfig eth0:1 10.0.1.172
echo "Setting IP alias routes ..."
/sbin/route add -host 10.0.1.171 eth0:0
/sbin/route add -host 10.0.1.172 eth0:1