My home server has two interfaces named eth0 and eth1. eth0 is connected directly to an incoming WAN port, so the gateway of eth0 depends on the ISP's DHCP server. eth1 is connected to a router in my house, which is connected to another WAN port.

Below is the output of netstat -rn (with public addresses modified):

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         111.111.111.126 0.0.0.0         UG        0 0          0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1
111.111.111.126 0.0.0.0         255.255.255.128 U         0 0          0 eth0

What I need to do is being able to make outgoing connection with both interfaces to any public IP addresses, plus making one of the interfaces as a default one if there is no specified interface. For instance, curl www.google.com --interface eth1 fails in the current configuration. route add default gw 192.168.0.1 fixes that, but then curl www.google.com --interface eth0 breaks.

link|improve this question
2  
You can't normally have two default gateways; you can split network views and do all kinds of crazy stuff, but it's generally a really bad idea. This might sound simple, but normally IP does not keep track of where a packet came from, so sending it back out that direction isn't possible. IP was specifically designed this way to make it link agnostic and resilient. – Chris S Jan 4 at 14:35
feedback

migrated from serverfault.com Jan 4 at 15:37

This question came from our site for system administrators and desktop support professionals.

2 Answers

Not sure of your aims, but sounds like a load balancing question. This page gives some guidance on setting up multiple routing tables to take advantage of multiple connections to the internet: Guide to IP Layer Network Administration with Linux, Section 10.4

Notice that this approach uses the Source IP Address to select outbound connection. This can still work on a single server system if you bind your server's sockets to specific interfaces. For example, Apache to the IP of eth0 and bittorrent to the IP of eth1. Not all servers will provide the configuration hooks required to do this, but many will -- even Minecraft! ;)

link|improve this answer
feedback

This is going to be a little tricky. You need to ensure that any single TCP stream comes out only via a single interface. Otherwise the other end of connection will have seen packets from different sources and this would break the connection.

Read these two pages:

http://kindlund.wordpress.com/2007/11/19/configuring-multiple-default-routes-in-linux/

and

http://generationip.com/documentation/network-documentation/93-howto-setup-multiple-default-gateway-on-linux

They should help.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.