Thursday, November 29, 2007

Changing the default gateway using Network Manager

I have an oddball network configuration at home. I have a wireless D-Link router that connects to a Huawei router that in turn connects to the internet. So far so good.

The problem is that I want to use the D-Link router DHCP Server, but I want to use the Huawei router as default gateway... and there is no way to specify that in the D-Link router.

The solution I had so far implied setting the connection manually in Ubuntu, and that works fine... Apart from the fact that I have no fast way of setting up a VPN! So I decided to give it one more go with Network Manager, and turns out it is pretty easy to change the default gateway for a particular interface.

To do that, just create a file in /etc/network/if-up.d/ and call it gwconfig for instance.

sudo gvim /etc/network/if-up.d/gwconfig

In that file, check for the interface that you want (e.g. eth1), delete the default gateway that is messing up your system (e.g. and add the the one you really want (e.g.


if [ "$IFACE" = "eth1" ]; then
route delete default gw
route add default gw

Make sure you make the file executable and you're done.

sudo chmod a+x /etc/network/if-up.d/gwconfig

Set the network to Roaming Mode, and all should work fine. If it doesn't, try to disable and re-enable the network on Network Manager.

Btw, I still wasn't able to make the VPN work with this configuration... more on that later.

No comments: