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 have a question related to multiple network interfaces on Linux PC.

Suppose I have two connected network interfaces. Let us say that both network interfaces connect to LANs. Let us say one LAN (connected with eth0) has IP addresses 192.168.10.* and other LAN (connected with eth1) has IP addresses 192.168.20.*.

How can I configure Linux, so that all requests sent to any IP address starting with 192.168.10. will be sent over eth0 and all requests sent to any IP address starting with 192.168.20. will be sent over eth1?

share|improve this question

migrated from stackoverflow.com Feb 2 '13 at 8:08

This question came from our site for professional and enthusiast programmers.

2 Answers 2

There's nothing special you need to do. Interface routes are added by default and do exactly this. The system will send traffic out the interface "closest" to the packet's destination.

share|improve this answer
    
Thank you for the reply. I really appreciate it. If I connect to LAN on eth0 and WAN (Internet) on eth1, I cannot browse or use any Internet related software. If I disconnect from LAN on eth0 and restart eth1, I can browse and use software related to Internet. Why would this happen? –  geekowl Feb 2 '13 at 3:56
    
Do you have a default route (gateway) on the eth0 interface? You shouldn't. –  David Schwartz Feb 2 '13 at 4:35

@David Schwartz is correct. But you also need to make sure the subnet masks are set correctly. In your case above, you want to set the subnet masks of both interfaces to 255.255.255.0.

Your original question stated there was a LAN behind both interfaces (not the "Internet") so the above is correct for that situation.

If you want the machine to forward traffic between subnets (subnet = LAN for the purposes of this) you need to make sure you echo 1 to /proc/sys/net/ipv4/ip_forward - and also make sure your iptables is set to not filter anything. If you don't do this, machines behind both LANs can reach the Linux box but not the other LAN.

Now, you seem to want to have an interface reach both the Internet and a LAN. It can be done if the LAN in question has a router and you know that router's IP address. You would set the Linux box's default gateway to the IP and subnet of the router. (If there is no router to the Internet on any LAN, then you don't set a default gateway at all.)

What's happening when you "restart eth1" is likely that eth1 is getting an IP via DHCP from a router and your IP addresses and default route assignments are actually changing when you do that.

If your DHCP is set correctly on the LAN with the router, with an IP reservation or similar, you can probably just let DHCP take care of it.

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.