Linux: Three default gateways?

Posted by Daniel on Server Fault See other posts from Server Fault or by Daniel
Published on 2012-12-05T12:18:45Z Indexed on 2014/06/10 9:27 UTC
Read the original article Hit count: 172

Filed under:
|

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

© Server Fault or respective owner

Related posts about linux

Related posts about routing