2

OS: Debian

Currently I have only 1 network connection setup (br0).

I'd like to connect a second network connection (eth3) to a separate network/gateway.

Everything should continue to be sent through eth0, except if I specifically choose to send a request out via eth1 (such as CURL request specifying eth1)

Note that eth2 is used as br0 bridge for a number of KVM virtual machines.

UPDATED: I added some routes and updates to the interfaces file: Here is my current interfaces file.

auto lo
iface lo inet loopback

auto br0
iface br0 inet static
  address 192.168.1.121
  network 192.168.1.0
  netmask 255.255.255.0
  broadcast 192.168.1.255
  gateway 192.168.1.1
  bridge_ports eth2
  bridge_stp on
  bridge_fd 0
  bridge_maxwait 0
  post-up ip route add 192.168.1.0/24 dev br0 metric 1
  post-up route add default gw 192.168.1.1 metric 1
  pre-down route del default gw 192.168.1.1

auto eth3
iface eth3 inet static
  address 192.168.0.121
  netmask 255.255.255.0
  broadcast 192.168.0.255
  gateway 191.168.0.1
  post-up ip route add 192.168.0.0/24 dev eth3 metric 2
  post-up route add default gw 192.168.0.1 metric 2
  pre-down route del default gw 192.168.0.1

However when I try to restart networking service is gives this error (also gives this error when trying to use ifup eth3

RTNETLINK answers: File exists

Failed to bring up eth3

1

If you know which IP addresses you will be connecting to via eth1 then you should set up routing.

Your default gateway will remain eth0 so all traffic will go there by default, however, any traffic sent to specific networks or IP addresses will go through eth1.

Check your current routing tables using the iproute2 package:

$ ip route list
default via gateway 192.168.1.1 dev eth0
gateway 192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.121

Set a static route using the gateway from eth1 to get to unix.stackexchange.com:

ip route add (remote_network) via (remote_connecting_gatway) dev (local_outgoing_interface)

$ ip route add 198.252.206.16/32 via 192.168.0.1  dev eth1

Check the new routing table:

$ ip route list
default via gateway 192.168.1.1 dev eth0
gateway 192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.121
198.252.206.16 via 192.168.0.1 dev eth1

Test the new route:

$ ip route get 198.252.206.16
198.252.206.16 via 192.168.0.1 dev eth1  src 192.168.0.121
cache

Delete the route:

$  ip route del 198.252.206.16/32 via 192.168.0.1  dev eth1

Make this static route persistant through a reboot:

Add the following entries to the /etc/network/interfaces file:

auto eth1
iface eth1 inet static
address 192.168.0.121
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
post-up ip route add 198.252.206.16/32 via 192.168.0.1  dev eth1
pre-down ip route del 198.252.206.16/32 via 192.168.0.1  dev eth1

Notice the post-up and pre-down entries.

Restart networking:

$ /etc/init.d/networking restart

Note:

If you do NOT know the IP addresses you will go to, then you need to add an additional routing table to contain the second default routes.

This is covered in detail on Two Default Gateways on One System.

References

man ip
man interfaces
Configure static routing on Debian
Two Default Gateways on One System

  • Note that I don't know the specific remote destination for all eth1 requests. For eth1 requests I would use CURLOPT_TIMEOUT 'eth1'. I have updated to interfaces config to include routes, but getting "Failed to bring up eth1" – David Barnes Nov 7 '14 at 10:13
  • That was a rather large caveat! You will need to remove the gateway entry from eth1 if you are using the routing method. – geedoubleya Nov 7 '14 at 10:15
  • So the 192.168.0.1 gateway does not need to specified as gateway in the interfaces file? – David Barnes Nov 7 '14 at 10:21
  • Yes - added the additional details – geedoubleya Nov 7 '14 at 10:22
0

When you have two default gw you could add a higher metric value on eth1 to avoid other than specified traffic over that interface. I think that this post have your answer. Adding two default gateways in Debian interfaces file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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