Multiple IP - different gateways - one interface - Debian Squeezy
6,572
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 videos on Youtube
Author by
Arsen K
Updated on September 18, 2022Comments
-
Arsen K over 1 year
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.
-
Arsen K almost 11 yearsI cannot choose them. They have been given to me in this configuration. It is because I need some IP's with different C sections
-
David Schwartz almost 11 yearsI'm talking about how you're routing outbound traffic, not about your IP address assignments. Do you really want to route outbound traffic through three default gateways? Are there really three routers you have access to that can handle traffic from any source you are using to any destination you don't have a direct route to?
-
Arsen K almost 11 yearsNo, you might be right. I do not really need that. I actually just need to run my webserver with a few different IPs, I need to run my postfix with 1 IP (and only from localhost, no relay server), mysql with 1 IP. What config would you recommend? Thank you
-
David Schwartz almost 11 yearsIt really depends how the rest of your network is set up. Ask the person who assigned you these IPs how you're supposed to be routing outbound traffic. It may be that all three default gateway IPs are just different interfaces on the same routing switch, in which case this set up is fine. But don't assume anything. The first step to getting it working is knowing how it's supposed to work.
-
the-wabbit almost 11 yearsMay I direct your attention to an obvious mistake in your
interfaces
- all four configuration sections do configure IPv4 foreth0
- you should change the latter three to use the respective interface alias you need to configure, e.g.iface eth0:0 inet static
-
Arsen K almost 11 yearsThank you, syneticon, it was really a mistake. I corrected all the records, but it still does not work. At the moment I am waiting for an answer from my provider regarding outbound routing - David's suggestion.
-