Based on http://pachome1.pacific.net.sg/~harish/linuxipalias.html
Please realize that IP aliases and NAT do not play well together, as can be read in this FAQ
GNU Copyleft 1996/1997 Harish Pillay (h.pillay@ieee.org)
This is a cook book recipe on how to set up and run IP aliasing on a FREESCO box.
ifconfig eth0:0 172.16.3.10 ifconfig eth0:1 172.16.3.100
172.16.3.10 and .100 are the aliases. The magic is the eth0:x where x=0,1,2,…n for the different IP #s. The main IP # does not need to be aliased.
route add -host 172.16.3.10 dev eth0:0 route add -host 172.16.3.100 dev eth0:1
That's it.
In the example IP # above, I am using the Private IP #s (RFC 1918) for illustrative purposes. Substitute them with your own official or private IP #s.
The example shows only 2 IP #s. The max is defined to be 256 in /usr/include/linux/net_alias.h.
256 IP #s on ONE card is a lot !
Here's what my /sbin/ifconfig looks like:
lo Link encap:Local Loopback
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
RX packets:5088 errors:0 dropped:0 overruns:0
TX packets:5088 errors:0 dropped:0 overruns:0
eth0 Link encap:10Mbps Ethernet HWaddr 00:8E:B8:83:19:20
inet addr:172.16.3.1 Bcast:172.16.3.255 Mask:255.255.255.0
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:334036 errors:0 dropped:0 overruns:0
TX packets:11605 errors:0 dropped:0 overruns:0
Interrupt:7 Base address:0x378
eth0:0 Link encap:10Mbps Ethernet HWaddr 00:8E:B8:83:19:20
inet addr:172.16.3.10 Bcast:172.16.3.255 Mask:255.255.255.0
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0
TX packets:0 errors:0 dropped:0 overruns:0
eth0:1 Link encap:10Mbps Ethernet HWaddr 00:8E:B8:83:19:20
inet addr:172.16.3.100 Bcast:172.16.3.255 Mask:255.255.255.0
UP BROADCAST RUNNING MTU:1500 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0
TX packets:0 errors:0 dropped:0 overruns:0
And /proc/net/aliases:
device family address
eth0:0 2 172.16.3.10
eth0:1 2 172.16.3.100
And /proc/net/alias_types:
type name n_attach 2 ip 2
Of course, the stuff in /proc/net was created by the ifconfig command and not by hand!
Question: How can I keep the settings through a reboot?
Answer: Place the commands in your /rc/rc_user script:
start) #setting up IP alias interfaces echo "Setting 172.16.3.10, 172.16.3.100 IP Aliases ..." ifconfig eth0:0 172.16.3.10 ifconfig eth0:1 172.16.3.100 #setting up the routes echo "Setting IP routes ..." route add -host 172.16.3.10 eth0:0 route add -host 172.16.3.100 eth0:1 ;;