-   Linux - Networking (
-   -   Bringing routes up only when link state is active (

mudtoe 12-04-2012 01:02 PM

Bringing routes up only when link state is active
Hi folks:

I've got a Ubuntu 11.04 VM that I'm trying to setup a backup LAN route on. It's a migration of a physical machine onto a VMWare ESXi white box. I've got a backup LAN setup on the ESXi white box using wireless and I wanted to be able to allow this VM to use that backup network if the regular hardwired LAN is down for some reason.

The problem I'm having is that I can't seem to prevent the hardwired primary LAN default route from being active as long as eth0 is up, even if the link is down (i.e. no cable connected). When that happens if I try to connect to the system via the backup wireless lan subnet, the routing table sends the packets back over the primary default gateway route, which of course is down. I can fix this by doing "ifdown eth0" which clears the routing table of the primary lan default route, leaving the backup default route (which has a higher metric #) active, but I'd like that functionality to work simply by virtue of whether or not the link state is up versus having to do that manually. Is there any way to do that? I've tried using the post-up configuration settings in the interfaces file, but it looks like those only pay attention to whether eth0 is enabled or not, and based on the link state.

Suggestions welcome.


mmheera 12-04-2012 04:20 PM

Are you looking for something like policy based routing in Linux? Then you may have a look at this:


mudtoe 12-05-2012 02:00 PM

I'm already using that with a Vyatta router VM in this same box. I've got an internal subnet setup within the ESXi box. The internal subnet is 172.24.99.xx, the external hardwired subnet is 172.24.222.xx, and the external wireless subnet is 172.24.221.xx. The Vyatta router VM controls the internal subnet and can route traffic from that subnet to the wireless external subnet. The other VMs in the box have access to the internal subnet and the hardwired external subnet.

What I wanted to be able to do, for testing purposes, is access the VMs in the box from a computer on the external hardwired subnet via the internal subnet. This works with a windows VM as long as the external hardwired subnet is disconnected (i.e. nic cable disconnected) and you don't actually have to mark the nic as disabled. However, with Linux it looks like you have to actually disable the eth0 interface (ifdown), rather than just use VMWare to simulate disconnecting the cable, in order to get the routing table to remove the default routes for that interface.

What that basically means is that if the external hardwired network fails I will have to use VMWare to login to the Ubuntu VM via the local console and manually disable eth0 with ifdown in order to get the backup connection to fully work. While I will be able to do that because the Vyatta VM will allow me to access the VMWare interface using the backup wireless network, it won't work without manual intervention, which is what I'm trying to avoid.


mmheera 12-05-2012 04:20 PM

Sorry to say but, your scenario is not fully clear to me, guess with a network diagram it would be better understandable.
Anyway, maybe you need dynamic routing, something like OSPF. Then routing tables can be dynamically updated automatically. You can implement OSPF using zebra in linux, but all the connected router/machine need to support that. It's not only putting the interface down for the defaults route to go, but again you will need to bring the interface up again automatically when your primary link is up.

mudtoe 12-05-2012 07:29 PM

Well, I guess what it boils down to is the question of whether or not there is a way to have a script triggered when the link state of an ethernet connection changes. All the stuff I've found (e.g. pre-up, post-down, etc.) which are in /etc/network/interface only seems to be triggered when the interface itself, from a software perspective, is enabled or disabled (e.g. ifup, ifdown), and they don't appear to be triggered when just the link state changes, which seems a bit strange to me. If there is a way to trigger a script when just the link state changes then I can put the route commands I need in that script.


unSpawn 12-05-2012 07:33 PM


Originally Posted by mudtoe (Post 4843400)
What that basically means is that if the external hardwired network fails I will have to (..) manually disable eth0 (..) it won't work without manual intervention, which is what I'm trying to avoid.

There are daemons that check link state and respond by running scripts.

mudtoe 12-12-2012 11:55 PM

Thanks for the tip. I found something called netplug that looks like it might do what I need. I'll play with it a bit and report back.


All times are GMT -5. The time now is 03:55 PM.