Multiple Domain Names on Linux

Multiple IP Addresses - Linux 2.0.30

Jun 1997
Reference How do I set up my Linux box (and possibly other UNIX systems) to answer to multiple IP addresses? - like 209.0.42.2 and 207.90.132.170

If you have the IP aliasing module installed in your Linux kernel (it can be installed as a module, which means it will turn itself on when required and otherwise leave your kernel alone, or it can be installed as a standard part of your kernel. See My notes on Linux Modules) it is really easy. If you don't have this module installed, it can still be done, I think. (see below)

If you have the IP aliasing module, you want to add an alias networking device called "eth0:1". In the following example, my IP address was 207.90.132.170 and I was changing my IP address to 209.0.42.2. For a period of a couple weeks during the transition, I wanted my machine to answer to both IP addresses. So I set my machine to be the new IP address (209.0.42.2) and I did the following to keep it answering the old one.


ifconfig eth0:1 207.90.132.170
route add -net 207.90.132.0 eth0:1

The 207.90.132.0 is my "network" address, not my machine IP. I don't quite understand the difference, but typically you have a router IP and a network IP and typically these are 1 and 0 respectively. YYMMV. You can check to see if it worked with "netstat -nr" which should give something like this.

Kernel routing table
Destination     Gateway         Genmask         Flags Metric Ref Use    Iface
209.0.42.0      0.0.0.0         255.255.255.128 U     0      0      137 eth0
207.90.132.0    0.0.0.0         255.255.255.0   U     0      0      112 eth0:1
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0       44 lo
0.0.0.0         209.0.42.1      0.0.0.0         UG    1      0     2040 eth0

You can add this information into your boot up scripts so that it gets done automatically when you reboot. I did that via. more /etc/rc.d/rc.inet1

#! /bin/sh
#
# rc.inet1      This shell script boots up the base INET system.
#
# Version:      @(#)/etc/rc.d/rc.inet1  1.01    05/27/93
#

HOSTNAME=`cat /etc/HOSTNAME`

# Attach the loopback device.
/sbin/ifconfig lo 127.0.0.1
/sbin/route add -net 127.0.0.0

# IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
# eth0 interface. If you're only using loopback or SLIP, don't include the
# rest of the lines in this file.

# Edit for your setup.
IPADDR="209.0.42.2"             # REPLACE with YOUR IP address!
NETMASK="255.255.255.128"       # REPLACE with YOUR netmask!
NETWORK="209.0.42.0"            # REPLACE with YOUR network address!
BROADCAST="209.0.42.127"        # REPLACE with YOUR broadcast address, if you
			# have one. If not, leave blank and edit below.
GATEWAY="209.0.42.1"            # REPLACE with YOUR gateway address!

# Uncomment the line below to configure your ethernet card.
/sbin/ifconfig eth0 ${IPADDR} broadcast ${BROADCAST} netmask ${NETMASK}

# If the line above is uncommented, the code below can also be uncommented.
# It sees if the ethernet was properly initialized, and gives the admin some
# hints about what to do if it wasn't.
if [ ! $? = 0 ]; then
cat << END
Your ethernet card was not initialized properly.  Here are some reasons why this
may have happened, and the solutions:
1. Your kernel does not contain support for your card.  Including all the 
network drivers in a Linux kernel can make it too large to even boot, and
sometimes including extra drivers can cause system hangs.  To support your
ethernet, either edit /etc/rc.d/rc.modules to load the support at boottime,
or compile and install a kernel that contains support.
2. You don't have an ethernet card, in which case you should comment out this
section of /etc/rc.d/rc.inet1.  (Unless you don't mind seeing this error...)
END
fi

# Uncomment these to set up your IP routing table.
/sbin/route add -net ${NETWORK} netmask ${NETMASK}
/sbin/route add default gw ${GATEWAY} metric 1

# temporary to answer to both old and new addresses
echo "adding temporary routing info"
echo "/sbin/ifconfig eth0:1 207.90.132.170"
/sbin/ifconfig eth0:1 207.90.132.170
echo "/sbin/route add -net 207.90.132.0 eth0:1"
/sbin/route add -net 207.90.132.0 eth0:1

The cool thing is that you can repeat this, of course, using eth0:2, eth0:3, etc.

If you do NOT have the IP aliasing module, you may have support for a "dummy" network alias. Try the same directions above substituting dummy for eth0:1. The downside to this method is you can only do it once. You can't set up more than two IP addresses unless you have the IP alias.

Return to Gene's Home Page
Return to Gene's Random Unix Crap