Adding a second IP to Debian Server

I was given a second IP by my server provider. I am running Debian 5.0. I thought I knew how to add the IP to the system and configure with apache, but I have not yet been able to.

The primary IP works fine and I have a few sites already running on that one.

What steps would I take to add this second IP so that I use it in apache?


Assuming the new IP address is on the same subnet as the first, add a second virtual interface (sometimes called an "alias") to the primary network interface. This is configured, like all network interface settings, in /etc/network/interfaces. The Debian Reference manual has a section on the topic:

http://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_virtual_interface

A simple example, assuming your primary network interface is eth0 and has an ip of 192.168.1.1 and the new ip is 192.168.1.2:

auto eth0
iface eth0 inet static
  address 192.168.1.1
  netmask 255.255.255.0
  gateway 192.168.1.254

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

Once the appropriate settings have been added to /etc/network/interfaces, run ifup eth0:0 to activate the new interface.

If, however, the new ip is on a different subnet, you need to either provision the ip on a physically distinct network interface or create a VLAN interface, depending on how your ISP is prepared to hand it off to you. That's a whole new topic.


If you use the iproute package, you can put this in /etc/network/interfaces:

auto eth0
iface eth0 inet static
    address 10.0.0.17
    netmask 255.0.0.0
    gateway 10.0.0.1
    up   ip addr add 10.0.0.18 dev eth0
    down ip addr del 10.0.0.18 dev eth0

Even Simpler:

Use an "addresses" line in /etc/network/interfaces

iface eth1 inet static
        address 10.10.0.66
        netmask 255.255.255.240
        network 10.10.0.64
        broadcast 10.10.0.79
        gateway 10.10.0.65
        addresses 10.10.0.67/28 10.10.0.67/28 10.10.0.68/28

You can use a space seperated list of IPs/CIDR netmasks.

This is a crippled version of my interface definition (IPs changed and only relevant part)