I manage several OpenWrt (embedded linux) routers for which I've written bash scripts to run an Openconnect VPN client. The client uses "vpnc-script" to set up routing, which replaces the initial DHCP-provided default route.

My problem is that when the tunnel collapses, or the process is killed, the default route does not get reset, leaving the router with no default route for reconnection.

I have been solving this so far by manually setting a variable with the gateway's IP address. However, I don't think this should be necessary; and furthermore, when the router is moved (to provide a VPN connection behind another gateway), the gateway variable has to be manually changed in the script.

Since the default route is set up correctly (automatically) when the router boots, I'm sure there must be an easy way to trigger it later, but for the life of me I can't find it!

Is there an easy way to tell a linux system to reset the default route?

2 Answers 2


The default route is just another route. If you remove it, the kernel has no way of retaining it. It's just runtime configuration that can change.

If you have configured your interface somewhere, you can try restarting the interface (as you mention in your own answer). If you haven't done that, however, you'll need another solution.

I can see two options:

  • When you configure the interface in your vpn configuration script, first read the old default route and store it somewhere else. Then, when the tunnel goes down, you can fire up another script that reads what you stored and applies it again.
  • Have the vpn configuration script work with a separate routing table, which you make the default. Then, when the interface goes down, all you need to do is to switch routing tables again.

Duh. Not sure why in all my scripting I never thought of this before, but one easy way to do it is to reset the interface:

ip link set eth0 down
ip link set eth0 up

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.