Configuring IP aliases cleanly on Debian

I like using different IP addresses for different services on my internal network. Thanks to RFC1918 this is no problem at all, as there are several network ranges dedicated for private networks. Using a firewall with that supports NAT (something people didn’t think of yet when writing the RFC) gives a maximum amount of flexibility when moving services around between servers and keeping things simple.

Setting up network interfaces with multiple interfaces is not really supported by Debian’s ifupdown tools. Yes you can do this easily by adding the necessary calls to the ip utility to your network interface definitions, but this is ugly and error-prone. That’s why I came up with the attached script, which adds support for the keyword aliases to your /etc/network/interfaces configuration so you can define additional IP addresses like this:

{code}
iface eth0 inet static
address 192.168.0.2
netmask 255.255.255.0
broadcast 192.168.0.255
aliases 192.168.0.100 192.168.0.101 192.168.0.102
192.168.0.103
{code}

Bringing up or down the interface will automatically add or remove the aliases. Please note that aliases added this way should always be on the same network as the primary address of the interface. To have multiple addresses on the same physical interfaces you need to use vlan’s or alias devices.

To install the script on you Debian host, simply save the script attached to this post as a file called aliases in your current directory and execute the following commands as root:

{code}
chmod 755 aliases
chown root.root aliases
cp aliases /etc/network/if-up.d
ln -s ../if-up.d/aliases /etc/network/if-down.d
{code}

And add your aliases to your devices in /etc/network/interfaces

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.