HOWTO IP Aliasing
From Gentoo Linux Wiki
| Installation • Kernel & Hardware • Networks • Portage • Software • System • X Server • Gaming • Non-x86 • Emulators • Misc |
Contents |
[edit] Introduction
Need to load multiple IP addresses to a single ethernet interface? These steps will help you do just that.
[edit] Use Your Variables
ethN - N = The number of the ethernet interface you are working with, such as eth0 or eth1 so in the examples below you will substitute the N variable for the correct eth interface you are working with.
Also the IP adresses listed here are obviously private IPs. If you are needing IP Aliasing it is very likely that you will be using public IP address so again substitute your own IP's
[edit] Setting it up
[edit] Prepare correct modules
modules=( "ifconfig" )
[edit] IP aliasing with ifconfig
You can use the 'ifconfig' command to add the aliased IPs to the ethN interface, like this;
# ifconfig eth0 192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0 # ifconfig eth0:1 192.168.0.3 broadcast 192.168.0.255 netmask 255.255.255.0 # ifconfig eth0:2 192.168.0.4 broadcast 192.168.0.255 netmask 255.255.255.0 # ifconfig eth0:3 192.168.0.5 broadcast 192.168.0.255 netmask 255.255.255.0 # ifconfig eth0:4 192.168.0.6 broadcast 192.168.0.255 netmask 255.255.255.0
But this is not permanent and will need to be done every time you want start net.ethN with multiple aliases. To make it stick between reboots, it needs to be put into a configuration file.
[edit] Making it a permanent addition
The preferred method is to edit your /etc/conf.d/net file, and define a iface_ethN and gateway for your ethN IP/Netmask/Broadcast, as well as three arrays containing aliases, broadcasts and netmasks for each additional IP configuration:
| File: /etc/conf.d/net |
iface_ethN="192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255"
gateway="ethN/192.168.0.1"
alias_ethN=("192.168.0.2", "192.168.0.3", "192.168.0.4")
broadcast_ethN=("192.168.0.255", "192.168.0.255", "192.168.0.255")
netmask_ethN=("255.255.255.0", "255.255.255.0", "255.255.255.0")
|
An alternative to the above (because this did not work for me on 2.6.15-gentoo-r5), and seems to be much simpler, is described in /etc/conf.d/net.example (which is a good resource anyhow, DO use it) - something more like this,
| File: /etc/conf.d/net |
config_ethN=(
"192.168.0.1 netmask 255.255.255.0 brd 192.168.0.255"
"192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255"
"192.168.0.3 netmask 255.255.255.0 brd 192.168.0.255"
"192.168.0.4 netmask 255.255.255.0 brd 192.168.0.255"
# ... ad infinitum ... (though i'm sure there IS a finite limit, what i know not) (ifconfig limits to 256 addresses)
)
routes_ethN=( "default gw 192.168.0.1" )
|
that should glom your eth0 interface onto 192.168.0.1, .2, .3 and .4 - at eth0, eth0:0, eth0:1 and eth0:2 respectively.
Then save your changes and exit. Now to restart your Nth service; (remember that if you're doing this over ssh and you screwed up, you might not be able to be on ssh anymore... ensure you have physical access to the machine in case you blow it)
# /etc/init.d/net.ethN restart
Now you can check your interfaces with the ifconfig command, which should result something like this;
| Code: ifconfig |
ethN Link encap:Ethernet HWaddr 00:01:02:1A:10:9F
inet addr:192.168.0.1 Bcast:192.168.255.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2175669 errors:13218 dropped:0 overruns:32 frame:15176
TX packets:434249 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:305729858 (291.5 Mb) TX bytes:84745134 (80.8 Mb)
Interrupt:16 Base address:0x1000
ethN:0 Link encap:Ethernet HWaddr 00:01:02:1A:10:9F
inet addr:192.168.0.2 Bcast:192.168.255.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1022 errors:0 dropped:0 overruns:0 frame:0
TX packets:1022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70546 (68.8 Kb) TX bytes:70546 (68.8 Kb)
Interrupt:16 Base address:0x1000
ethN:1 Link encap:Ethernet HWaddr 00:01:02:1A:10:9F
inet addr:192.168.0.3 Bcast:192.168.255.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1022 errors:0 dropped:0 overruns:0 frame:0
TX packets:1022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70546 (68.8 Kb) TX bytes:70546 (68.8 Kb)
Interrupt:16 Base address:0x1000
ethN:2 Link encap:Ethernet HWaddr 00:01:02:1A:10:9F
inet addr:192.168.0.4 Bcast:192.168.255.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1022 errors:0 dropped:0 overruns:0 frame:0
TX packets:1022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70546 (68.8 Kb) TX bytes:70546 (68.8 Kb)
Interrupt:16 Base address:0x1000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1022 errors:0 dropped:0 overruns:0 frame:0
TX packets:1022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:70546 (68.8 Kb) TX bytes:70546 (68.8 Kb)
|
There you are. Remember if you copy the format of this file to replace the N in the ethN command with the appropriate interface.
[edit] ADSL Static IP Addresses
One other useful way to use aliasing is when you have been allocated a block of static IP addresses from your ISP. Normally these days that also means you are using PPPoE, however this case is also easily handled as long as you put the adsl entry last.
| Code: net config for ADSL with multiple static IPs |
config_ethN=( "192.168.0.100 netmask 255.255.255.0 mtu 1500"
"170.8.123.157 netmask 255.255.255.248 mtu 1480",
"adsl")
|
So what this does is bring up the main ethernet interface so it can talk to your modem directly, which is useful for diagnostics; it also brings up the alias 170.8.123.157 which is part of a range of 8 IP addresses, and finishes by starting the PPPoE daemon. This configuration has many uses, including static Destination NAT entries for individual hosts inside your network.
