3

I am novice in networking trying to figure how multiple network interfaces work. My doubt is when there are two or more NIC's on a machine, what is the meaning of default gateway present in the /etc/sysconfig/network file. Is the kernel supposed to load balance between different interfaces which have gateways defined in their respective /etc/sysconfig/network-scripts/ifcfg-eth* file?

3 Answers 3

9

The default gateway is where packets are sent when there is no more specific route - actually the default gateway has a route matching all packets - a /0 netmask route.

Try "netstat -rn" to see the routes on your system.

The default gateway is not an interface on your system - it is usually your local router. It may be reachable via more than one interface, though typically there is only one active interface.

I'm not sure about load-balancing, but it seems reasonable that if the default gateway is reachable from more than one interface that packets could be sent from all interfaces to it.

A simple example of setting up your networking from scratch:

ifconfig eth0 192.168.0.55 netmask 255.255.255.0
route add default gateway 192.168.0.1 eth0

The first command sets up your interface and adds a route to the local network (192.168.0/24). The second command adds a default route via 192.168.0.1 which is now reachable thanks to the first route.

If you have a second interface, you can set it up too:

ifconfig eth1 192.168.0.56 netmask 255.255.255.0

Now either interface can reach the default gateway. You can check if load balancing is happening by using "ifconfig" and looking at the RX/TX packets. If the counters increment it indicates that interface is being used.

Update:

For two interfaces on different networks, you can add more than one default gateway. I don't know if that situation is supported by etc/sysconfig. If not, you can add a "route add default gateway" statement to your startup script.

Some trivia on the subject: it used to be possible to send a packet through a gateway with a source IP from the other interface (asymetric routing). In this way, you could send all your packets from one gateway and receive them through the other. This is useful in the case where you have connections with asymetric up/down bandwidth or latancy (think satalite downlink and cellular uplink).

I say "used to" because most ISPs now filter out packets with a source IP that isn't assigned downstream.

More random dual-nic fun:

I have two nics on my laptop: wired and wireless. I assign them both the same IP in my DHCP server config based on their ethernet address. When the wired one is connected, I get high speed. But when I unplug it, everything keeps working. I don't even lose connections to remote hosts. The kernel doesn't care which interface a packet comes from as long as it's bound for the right IP address.

3
  • Thanks for the detailed response. What about the case where each interface(eth0 or eth1) are present in two different subnets( may be connected to different routers) Apr 10, 2013 at 6:34
  • See updated answer
    – Julian
    Apr 10, 2013 at 15:51
  • 1
    Good, detailed answer, Julian. A little note about using route add default gateway for multiple adapters; this command (and the work it does) is very much tied to the adapter used when issuing the command. I tend to use this for forcing all of my private VPN traffic through my otherwise unused wifi interface; but this is just one of many good use-cases. Apr 10, 2013 at 17:09
5

The default gateway should be reachable by only a single of your network interfaces. Having more than one NIC on the same subnet, and thus a potentially non deterministic output path might leads to unexpected and disappointing behavior.

See for example https://serverfault.com/questions/415304/multiple-physical-interfaces-with-ips-on-the-same-subnet

Should you really want to implement that, a reliable way would be to configure some form of network aggregation, which translates to bonding/teaming as far as Linux is concerned.

3
  • One can have many-to-one NICs to gateways configured without violating any networking standard. I currently have my Ethernet and my Wifi on the same network, with the same gateway. On OSX, and other operating systems, one route will be preferred over the other automatically, either by explicit ordering of interface priority, or by arbitrary means such as logical interface numbering. If a fixed source IP address is configured, so that regardless of which interface is sending traffic, the source IP is the same and reachable by the gateway, then each interface can take turns sending,no prob. Jan 24, 2015 at 16:22
  • @NevinWilliams Granted the standard allows such configurations and defines a couple of models to describe the expected behavior regarding incoming packets directed to the "wrong" physical interface. Answer updated to remove the standard violation point.
    – jlliagre
    Jan 24, 2015 at 21:16
  • Were you to specify 'active default gateway', I'd have no issue at all... but after the good chuckle I had after checking out the referred link, we're good! Jan 25, 2015 at 5:26
3

With two routes of equal metrics, a round-robin load-balancing scheme is used. This may be on a per-network basis, or it may be on a per-packet basis. Cisco (not linksys) routers can be configured to do either, but per-packet gives a better distribution equivalent links. Host-wise, I believe unless you're running a routing daemon, like routed or gated, the system kernel will select one interface as its preferred route, and only switch to the other interface if the first one goes down, or the gateway becomes unreachable over that interface.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .