This is just a short article that shows how to change the default network route in Linux. Before I show how to do it, hoping that it helps somebody, let me tell you how I found myself in a situation where I was forced to change it.

If all you care about is how to change the route and not what led to the decision to change it, you may scroll to the end of the article.

Changing the default route in Linux is something I’ve never had to do on any desktop distribution in ages, but since yesterday afternoon, crazy stuff has been happening in my local network. My ISP is Verizon and I subscribe to their FiOS Internet service. I’ve never had a problem with it until yesterday afternoon when it just stopped working. I couldn’t connect to the Internet.

I spent the better part of an hour trying to figure out what the heck was going on, but nothing I tried worked. I could ping the router from any computer and connect to its web management interface, but that was about it. From the router itself I could ping and run a traceroute to any IP on the Internet, but I could not surf the Web. I gave up after an hour and called tech support. I succeeded in scheduling an appointment with a Verizon technician for Sunday afternoon and resigned to not having Internet access for two days. Not good, but what else can I do?

About six hours later, Internet access started working on its own. I didn’t even touch anything. Afterwards, I noticed that every computer on the network was getting an IP address in the 192.168.1.100 and higher range, something that has never happened in more than the six years I’ve been using Verizon FiOS. I figured that I have to investigate what’s going on, but there are other important matters that I have to attend to. So I shelved it for a later time.

Aside from my VoIP service, Internet access has been working just fine until a few hours ago when I installed Ubuntu 14.04 server in VMPlayer. apt-get update was failing because the system couldn’t connect to the Internet. My main computer running Fedora 20 KDE is working fine, but the Ubuntu server running as a guest OS on it was not. I booted up another computer running Ubuntu 14.10 desktop, but it too could not connect to the Internet.

What in the name of Tux is going on!

Just then I decided to check something I should have checked all along – the routing table. Perhaps it could tell me something. And it did. The default route was not what it’s supposed to be (see Figure 1). IP address 192.168.1.5 does not even belong to any device on the network. Something doesn’t smell right. But the best I can do now is change the default route to point to the correct IP.

So here’s how you change the default route in Linux: <strong>sudo ip route change default via IP-address dev eth0 proto static</strong> (replace IP-address with the IP of your router).

add IP route Linux

Figure 1: Changing the default route in Ubuntu or any other Linux distribution

That solved an immediate problem, but I think there’s something not quite right in my network. I’ve gotta find out what. More on this later, if I find something that’s worth writing about.