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
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.
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).
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.
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:
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.