Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

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.

share|improve this answer
    
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) –  Sirish Kumar Apr 10 '13 at 6:34
    
See updated answer –  Julian Apr 10 '13 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. –  Jerry W Jackson Apr 10 '13 at 17:09

The default gateway should be reachable by only a single of your network interfaces. If you have more than one NIC on the same subnet, and thus have non deterministic output path, your system is considered to violate the standard and this usually leads to unexpected and disappointing behavior.

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

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

share|improve this answer

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.

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.