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

Below is the output of netstat -rn ( is a mock public address):

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface         UG        0 0          0 eth0   U         0 0          0 eth1 U         0 0          0 eth0

I want to be able to choose an interface for the outgoing connections freely, but don't know how. curl www.google.com --interface eth1 should connect to www.google.com via eth1, it fails in the current configuration. route add default gw fixes that, but then curl www.google.com --interface eth0 breaks.

  • 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, 2012 at 14:35
  • @ChrisS: If you have two IP addresses, then there is no problem. Anything that talks to eth0's IP must come from eth0, be answered using eth0's IP and through eth0, and the same is true for eth1. That's done easily with policy routing, and the RFC clearly recognize source-based routing. You can't simply dismiss this as 'crazy stuff', especially when compared to things like NAT.
    – BatchyX
    Aug 21, 2012 at 7:14
  • @BatchyX Um, no. Locally attached routes have a higher priority in routing than unknown networks accessed by default gateways. If you're going to claim "the RFC" supports you, you'd better include the RFC number at a minimum. I do consider split network views to be "crazy stuff".
    – Chris S
    Aug 21, 2012 at 12:42
  • @ChrisS: I don't see the problem with locally attached routes. If you receive a packet from 192.168.x.y coming from eth0, reverse path filtering will trash them anyway. And a machine from eth0's lan cannot send you a packet to eth1's IP unless you configured it to have routes to you. And for locally generated packets, your properly configured policy routing will only select eth0's gateway for packets coming from eth0's IP or may optionnal reject packets from eth0's IP to eth1's lan. Also i should have said "the RFCs" instead of "the RFC", but see ye old 1812's "Vendor Policy" for starters.
    – BatchyX
    Aug 21, 2012 at 18:36
  • @BatchyX We're talking about completely different things.
    – Chris S
    Aug 21, 2012 at 18:53

2 Answers 2


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! ;)


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:




They should help.


You must log in to answer this question.

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