Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My server has three default gateways, how can that be? Shouldn't there be one default gw?

I have three NICs, each attached to a separate subnet:

server1:~#  route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.5.0.0        *               255.255.255.224 U     0      0        0 eth3
localnet        *               255.255.255.224 U     0      0        0 eth0
192.168.8.0     *               255.255.255.192 U     0      0        0 eth1
default         10.5.0.1        0.0.0.0         UG    0      0        0 eth3
default         192.168.8.1     0.0.0.0         UG    0      0        0 eth1
default         10.1.0.1        0.0.0.0         UG    0      0        0 eth0

Sometimes, I can't ping a host on the Internet, sometimes I can. What I want is traffic to the Internet (0.0.0.0) routed through a specific NIC. Can I just add a route for 0.0.0.0 and default gw to one of the eth0-3 interfaces? Will it break my connection?

I'm using Debian, here is my /etc/network/interfaces:

# 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
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
    address 10.1.0.4
    netmask 255.255.255.224
    network 10.1.0.0
    broadcast 10.1.0.31
    gateway 10.1.0.1

allow-hotplug eth1
iface eth1 inet static
        address 192.168.8.4
        netmask 255.255.255.192
        network 192.168.8.0
        broadcast 192.168.8.63
        gateway 192.168.8.1

allow-hotplug eth3
iface eth3 inet static
        address 10.5.0.4
        netmask 255.255.255.224
        network 10.5.0.0
        broadcast 10.5.0.31
        gateway 10.5.0.1
share|improve this question
3  
I don't do Linux, but you're basically right. If you only need to get to the individual subnets you're connecting too with eth0 & eth1 then simply remove the gateway from their config. Otherwise you'll need to configure some routing rules. –  Dan Dec 5 '12 at 12:24

3 Answers 3

up vote 4 down vote accepted

Technically, you may have as many default gateways as you want, but by default it doesn't make much sense, because the way your traffic goes will be somewhat unpredictable. Having multiple gateways makes sense if you use policy routing; for example, if you're connected to 2 different providers and you want your server to reply to each remote host on the same interface that was used by that host to reach you, you can accomplish that with iproute2 package in a multiple-default-gateway environment.

If you want to have a single default gateway, just remove 'gateway' statement from all interfaces in /etc/network/interfaces except one interface where your default gateway will be. And reboot, of course.

share|improve this answer
    
Any chance of accomplish that without a reboot? –  Daniel Dec 5 '12 at 14:53
2  
Yes, if you manually delete unneeded default gateways with "route delete default gw <address>". But change /etc/network/interfaces anyway so that it works after next reboot. –  Eugene Dec 5 '12 at 15:00

You configured all gateways on your interfaces file. Leave only the gateway what you really need.

Linux is supporting multiple gateways ... but depends on what do you want to do.

  1. You can choose to configure different metrics on each gw and it will work like a failover
  2. You can use source routing based on iproute2 and kernel policiy routing
  3. You can use BGP to balance your traffic.

This are your options, but if you need only 1 gw then delete the other 2 from your interfaces file (delete the lines what are starting with gateway xxx.yyy.zzzz.wwww and leave only the gateway what you need).

share|improve this answer

depending on how many of those gateways are actually connected to the internet you might want 2 or even more "default" gateways.

The key to choose the priority is the "metric" parameter.

Eli Rosencruft on unix.SE describes this process and how to include that in the interfaces file.

important part:

iface eth0 inet static
...    
post-up route add default gw 192.168.1.1 metric 1
pre-down route del default gw 192.168.1.1


iface eth1 inet static
...
post-up route add default gw 192.168.2.1 metric 2
pre-down route del default gw 192.168.2.1

so once your connection to the gateway drops (for whatever reason) it will switch over to the other.

Obviously you can alter at least some of your traffic to route via the interface of your choice even without setting a metric , you should check the man pages of the programms for how you do this exactly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.