Resolving Multiple Default Routes in Linux

In this tutorial, we will guide you through the steps to identify and resolve issues related to multiple default routes on a Linux system. Having multiple default routes can cause network issues and unexpected behavior, so it's important to manage them properly.

Step 1: Check Existing Default Routes

First, check the current default routes configured on your system. Open your terminal and run the following command:

ip route | grep '^default'

This command will list all default routes. For example, you might see an output like this:

default via 104.36.27.92 dev eth0
default via 169.254.0.1 dev eth0 proto static metric 100

In this example, there are two default routes configured for the `eth0` interface.

Step 2: Understand the Output

The output shows two default routes:

1. `default via 104.36.27.92 dev eth0`
2. `default via 169.254.0.1 dev eth0 proto static metric 100`

Each line indicates a route with the default gateway address, the network interface (`dev eth0`), and additional information like protocol (`proto static`) and metric.

Step 3: Decide Which Route to Keep

Decide which default route you want to keep based on your network configuration. Typically, you should keep the route that points to your main gateway. In this example, we will keep `default via 104.36.27.92 dev eth0` and remove the other route.

Step 4: Remove the Unwanted Route

To remove the unwanted default route, use the `ip route del` command followed by the route you want to delete. In our example, we want to delete `default via 169.254.0.1`:

ip route del default via 169.254.0.1

Step 5: Verify the Changes

After removing the unwanted route, verify that only one default route remains by running the following command again:

ip route | grep '^default'

The output should now display only one default route:

default via 104.36.27.92 dev eth0

Step 6: Make the Changes Persistent (Optional)

If you want the changes to persist after a reboot, you will need to modify your network configuration files. The exact method depends on your Linux distribution. Here are examples for Red Hat-based and Debian-based systems:

Red Hat-based systems (CentOS, Fedora):

Edit the network configuration file for the interface (e.g., `/etc/sysconfig/network-scripts/ifcfg-eth0`) and ensure it contains the correct gateway:

GATEWAY=104.36.27.92

Debian-based systems (Ubuntu, Debian):

Edit the network interfaces file (e.g., `/etc/network/interfaces`) and ensure it contains the correct gateway:

auto eth0
iface eth0 inet static
address [your_ip_address]
netmask [your_netmask]
gateway 104.36.27.92

After making the changes, restart the network service to apply the new configuration:

systemctl restart networking

Conclusion

By following these steps, you can effectively manage multiple default routes on your Linux system, ensuring that only the intended default route is active. This helps to avoid potential network issues and maintain a stable network configuration.

  • 4 Users Found This Useful
Was this answer helpful?

Related Articles

How to restrict direct root access in Linux

We can do it just in two steps. Step One: At first we will create new root user as follows (for...

How to extract .tar.gz files in Linux/UNIX OS

A tarball is a group of files that are bundled together using the tar command. Use the...

How to add welcome message when SSH start?

You need to change the contents of /etc/motd. Unfortunately, by default, /etc/motd is a link to...

How to change root password when SSH logged in

Run the following command: passwd Now type your new passwordOnce done, retype new passwordDone!...

How to install Pinguzo on any Linux/UNIX OS

Login to Pinguzo panel using Softaculous account or create an account of Pinguzo To add new...