8

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?

1
  • You are supposed to configure a new alias for your second ip. The mandatory resources for ip management are the file /etc/network/interfaces and the ip tool from iproute package. Where are things breaking? what doesn't work?
    – scyldinga
    Sep 19, 2009 at 4:27

3 Answers 3

14

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.

4
  • Thanks for the answer. I tried following these instructions, but when I restart the network interfaces I receive this error: :/etc# /etc/init.d/networking restart Reconfiguring network interfaces...SIOCDELRT: No such process if-up.d/mountnfs[eth0]: waiting for interface eth0:0 before doing NFS mounts (warning). done. The subnet is the same for the ips, so from what I know and read this above solution should work. The virtual host that I setup are not working and I get network timeout on the domain.
    – David
    Sep 20, 2009 at 0:36
  • The warnings sound reasonable. The fact that it makes reference to waiting for eth0:0 is good news. What do your network interfaces look like after restarting networking? Specifically, what does the output of "ifconfig -a" look like?
    – Insyte
    Sep 20, 2009 at 2:46
  • wiki.debian.org/…
    – Hvisage
    Jul 28, 2020 at 12:20
  • Your debian.org link is broken. Also the eth0:0 method is apparently obsolete, see the Legacy method section.
    – x-yuri
    Nov 14, 2023 at 0:33
4

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
2

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)

2
  • 2
    I can't find the addresses line in the manpages interfaces or ifconfig, neither does it work on Debian Lenny.
    – Lekensteyn
    Jan 22, 2011 at 16:08
  • 3
    I have to down vote this, as it's not in Debian Buster's ifupdown either. wiki.debian.org/…
    – Hvisage
    Jul 28, 2020 at 12:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .