Debian – Multiple IP – different gateways – one interface – Debian Squeezy

debiangatewayinterfaceip

i was reading many answers here and everywhere, but I cannot find the right one. I tried several solutions, but nothing works. I have a server with ONE Interface eth0. I have multiple IP's, but I cannot get them to work. Maybe you can help me.

etc/network/interfaces (I found this solution online as many others):

    # This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo eth0
iface lo inet loopback

# The primary network interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 31.133.CCC.47
    netmask 255.255.255.0
    broadcast 31.133.CCC.255
    network 31.133.CCC.0
  post-up route add default gw 31.133.CCC.1 metric 1
  pre-down route del default gw 31.133.CCC.1

auto eth0:0
allow-hotplug eth0
iface eth0 inet static
    address 31.133.XXX.254
    netmask 255.255.255.128
  post-up route add default gw 31.133.XXX.129 metric 2
  pre-down route del default gw 31.133.XXX.129

auto eth0:1
allow-hotplug eth0
iface eth0 inet static
    address 31.133.YYY.254
    netmask 255.255.255.128
  post-up route add default gw 31.133.YYY.129 metric 3
  pre-down route del default gw 31.133.YYY.129

auto eth0:2
allow-hotplug eth0
iface eth0 inet static
    address 31.133.ZZZ.229
    netmask 255.255.255.0
  post-up route add default gw 31.133.ZZZ.1 metric 4
  pre-down route del default gw 31.133.ZZZ.1

This config does not work. Without post-up and pre-down, but with gateway – does not work too. What should I do? While booting, bind and other services won't start, because they cannot find a working interface. With a single IP config (the first one) server is working.

Thank you very much for your suggestions.

Best Answer

I solved this.

/etc/init.d/interfaces:

auto lo eth0
iface lo inet loopback

auto eth0:0 eth0:1 eth0:2

allow-hotplug eth0
iface eth0 inet static
    address 31.133.MMM.47
    netmask 255.255.255.0
    broadcast 31.133.MMM.255
    network 31.133.MMM.0
    post-up route add default gw 31.133.MMM.1 metric 1
    pre-down route del default gw 31.133.MMM.1


iface eth0:0 inet static
    address 31.133.NNN.254
    netmask 255.255.255.128
    broadcast 31.133.NNN.255
    network 31.133.NNN.0
    post-up route add default gw 31.133.NNN.129 metric 2
    pre-down route del default gw 31.133.NNN.129


iface eth0:1 inet static
    address 31.133.KKK.254
    netmask 255.255.255.128
    broadcast 31.133.KKK.255
    network 31.133.KKK.0
    post-up route add default gw 31.133.KKK.129 metric 3
    pre-down route del default gw 31.133.KKK.129


iface eth0:2 inet static
    address 31.133.LLL.229
    netmask 255.255.255.0
    broadcast 31.133.LLL.255
    network 31.133.LLL.0
    post-up route add default gw 31.133.LLL.1 metric 4
    pre-down route del default gw 31.133.LLL.1

And it works!

Thank you all for your help!

Related Topic