Skip to content

Instantly share code, notes, and snippets.

@TomCan
Created June 5, 2018 12:25
Show Gist options
  • Select an option

  • Save TomCan/5af6e3623572bc88d245f4c9eebe51c6 to your computer and use it in GitHub Desktop.

Select an option

Save TomCan/5af6e3623572bc88d245f4c9eebe51c6 to your computer and use it in GitHub Desktop.
Routing traffic out over the interface the connection was received on in a setup where multiple NICs are present.
# If you're using multiple NICs/IPs on AWS, traffic might be sent out over one of the 2 NICs only.
# And the other IP will not be usable.
#
# /etc/network/interfaces
iface eth0 inet dhcp
post-up ip route add default via <ip-of-default-gateway-of-eth0> dev eth0 tab 1
post-up ip rule add from <ip-of-eth0> tab 1
pre-down ip rule del from <ip-of-eth0> tab 1
pre-down ip route del default via <ip-of-default-gateway-of-eth0> dev eth0 tab 1
iface eth1 inet dhcp
post-up ip route add default via <ip-of-default-gateway-of-eth1> dev eth1 tab 2
post-up ip rule add from <ip-of-eth1> tab 2
pre-down ip rule del from <ip-of-eth1> tab 2
pre-down ip route del default via <ip-of-default-gateway-of-eth1> dev eth1 tab 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment