-1

I've got two WAN interfaces coming into a Debian 8 VM.

WAN 1 - All Internet and local traffic. (0.0.0.0/0) Has a a static IP, thus IP, netmask and gateway are fixed values.

WAN 2 - Specific private subnet traffic only (10.100.0.0/16). IP obtained via DHCP, can be anywhere in the 10.0.0.0/8 range.

I don't have control over WAN2 (The link is supplied by the ISP) so I am faced with a dual gateway situation.

Right now, here is how I have it set up.

iface eth0 inet static
address 172.16.100.100
netmask 255.255.255.0
gateway 172.16.100.1

iface eth1 inet dhcp

I then manually bring up eth1, obtain the DHCP gateway IP, then set a static route for 10.100.0.0/16 manually. This works fine, of course, until the DHCP lease renews, which is about every 4 days. At which point I have to bring down eth1, bring it back up, note the new gateway and set the new static route.

I've tried setting a static route to 10.100.0.0/16 via eth1, but without any knowledge of the next-hop gateway IP.. of course that doesn't work.

I've also tried several iproute2 setups but it still boils down to knowing the next-hop address it would seem.

What i'm trying to solve - How can I set a static route for eth1 given that I have no knowledge of the next-hop address as it constantly changes via DHCP?

Indecided
  • 3
  • 2

2 Answers2

0

Have you tried this ?

ip route add 10.100.0.0/16 dev eth1

if this still not work, good chances that there is a conflict of routes, try adding metric or check route -n

5thphase
  • 1
  • 1
  • 1
    Have *you* tried that? Routes to a (non-PtP) device don't work because the routes are specified by next-hop IP. – womble Oct 05 '17 at 00:22
0

Assuming you're running dhclient (the ISC DHCP client), you can add a script in /etc/dhcp/dhclient-enter-hooks.d which gets the DHCP gateway address (it's in some env var or another) and updates the routing table. Exact implementation left as an exercise for the reader.

(Obligatory "your ISP sucks" addendum: your ISP really sucks)

womble
  • 95,029
  • 29
  • 173
  • 228
  • Yep - it would certainly seem that this is the only sensible way to go, save putting a small router in front of both WAN connections. I am halfway writing a hook on bind/unbind/renew/etc that discards default gateway information from the ip add command on the WAN2 interface and then using the gateway information to add static routes appropriately. – Indecided Oct 06 '17 at 01:50
  • Another thing to note is that you can *modify* the environment in your hook scripts, for example unsetting the variable that contains the DHCP-server-provided default route, which means that the default dhclient action script then won't setup the default route at all. – womble Oct 06 '17 at 02:22