Tuesday 5 December 2017

linux - Multiple default gateways


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 (111.111.111.126 is a mock public address):


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

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 192.168.0.1 fixes that, but then curl www.google.com --interface eth0 breaks.



Answer



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


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...