Question Locked

IP aliasing through /etc/network/interfaces ?

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm spending today learning about network IP aliases.

The concept is simple; one network card listening for multiple IP addresses.

The manual setup is also simple:
ifconfig eth0 up
ifconfig eth0 192.168.1.1
ifconfig eth0:0 192.168.1.2
ifconfig eth0:1 192.168.1.3

Everything I've found for this so far suggests dropping the ifconfig commands into the rc.local startup file to be rerun at each system boot.

Is there a way to do the aliases through /etc/network/interfaces instead of in a seporate file? I'd prefer my full network config be contained in a single file so I don't have to deal with one running before the other and such.

6 replies

by jdclyde

http://www.faqs.org/docs/Linux-mini/IP-Alias.html

http://home.pacific.net.sg/~harish/linuxipalias.html

And yes, these and a few others I looked at all pointed at using rc.local.

To my shock, as I walk through this, I find that MINT linux does not HAVE an /etc/rc.d directory? GRRRRR. and of course my laptop running SuSE is down stairs.... ~sigh~

On SCO Unix, this used to be handled via the web manager, (GUI) and I don't recall where it put the data. Been a few years. Actually, thinking back, I think they just changed the port number for each web page. Never mind, just thinking to myself.... ;\

by neon samurai

The why needed; IP based vhosting on a single NIC server.

They why not in the network config directly; that's the bit I'm working on understanding.

I think it's going to end up being two ifconfig lines in my rc.local but I wanted to see if there was a way to just include it in the network config directly instead of as an add-on command after. If rc.local runs after the network interfaces are established during boot then it's less of an issue; just messy.

For me, it means another config file I have to include into my build pack and scripts. The elegant solution would be to echo it into an existing config file (will duplicate rows when script is rerun) or place the config lines in the interfaces config file which is already included into the build pack.

by jaqui

as in virtual apache hosts?
you don't need to alias the interface for that.

the httpd.conf will let apache handle it for you.

leave the ip address section of the conf at 0.0.0.0 and in the vhosts, put the ip address for each one needed.
one vhost container for each ip address.

by neon samurai

http://cr.yp.to/djbdns/ifconfig.html

Debian GNU/Linux details: first address
A typical use of ifconfig and route is

ifconfig eth0 1.8.7.200 netmask 255.255.255.0
route add default gw 1.8.7.1

which means three things:

* The computer should respond to IP address 1.8.7.200.
* To reach other 1.8.7.* IP addresses, the computer should send packets through its eth0 network card. You can run ifconfig without arguments to see a list of network cards.
* To reach the rest of the Internet, the computer should send packets through the router with IP address 1.8.7.1.

To tell the computer to do all this after each boot, add

auto eth0
iface eth0 inet static
address 1.8.7.200
netmask 255.255.255.0
gateway 1.8.7.1

to /etc/network/interfaces.
Debian GNU/Linux details: IP aliases
To set up a second IP address, say 1.8.7.246, type

ifconfig eth0:0 1.8.7.246 netmask 255.255.255.0

and add

auto eth0:0
iface eth0:0 inet static
address 1.8.7.246
netmask 255.255.255.0

to /etc/network/interfaces. Use :1 for the third address, :2 for the fourth address, etc.

Seems I may have been closer than expected during my first attempt this morning. Will confirm back if it works.

by neon samurai

For testing, one can quickly do

ifconfig eth0:0 192.168.1.2
ifconfig eth0:1 192.168.1.3

This manually stacks IP addresses on top of an existing inteface; eth0 on 192.168.1.1

That can be automated by dropping the commands into the rc.local file.

The more elegant method in my opinion is the interfaces config file (for Debian and derivatives anyhow).

auto eth0
iface eth0 inet static
address 1.8.7.200
netmask 255.255.255.0
gateway 1.8.7.1

auto eth0:0
iface eth0:0 inet static
address 1.8.7.246
netmask 255.255.255.0

The first block, configures the interface device on the standard IP. The second block layers on a second IP with eth0:0. A third could be added as eth0:1 and so on up to a maximum of 256'ish IP addresses.

If your using bonded NIC, this works as well.

bond0 on 192.168.1.1
bond0:0 on 192.168.1.2
bond0:1 on 192.168.1.3

The bonding config for bond0 takes care of managing the bonded NICs eth0/eth1 while the other IP simply layer on top through bond0:0, bond0:1 and so on.

I figure if it two two of us more than two searches to find the information, it may as well be posted again.

This discussion is closed to new replies.