Linux

How to Change the Default Network Interface in Linux

This quick tutorial will show you how to set the default interface in Linux.
Captain Salem 2 min read
How to Change the Default Network Interface in Linux

The only way to enable network connection on a machine is through a network interface.

A network interface is a device or a point of connection between a device and a private or public network. In most cases, a network interface is a physical card such as a wireless adapter or network card.

However, this does not necessarily mean that a network interface should be a physical device. For example, the software implements a loopback adapter that is not physically visible and available on all devices.

Method 1 – Turn Off Adapters

The simplest way to set your default network interface is by disabling all other interfaces. For example, you can use the GUI network manager or the terminal in Linux.

Suppose you have a wireless adapter and you wish to use the Ethernet adapter; in that case, you can bring down the wifi adapter using the command:

sudo ifconfig wlan0 down
sudo ifconfig eth0 up

The above commands will shut down the wireless adapter and bring up the ethernet adapter.

That will force the system to switch to the available network.

NOTE: The above command requires sudo or root privileges with the net-tools package installed.

Method 2 – Use IP ROUTES

An unconventional method is to edit your routes and specify which devices to use as the default.

Start by using the command:

sudo ip route list

This command will show you the default gateway and the default interface. For example, below:

default via 192.168.0.1 dev wlan0 proto dhcp metric 100 
169.254.0.0/16 dev wlan0 scope link metric 1000 
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.10 metric 100

In the above example, the default value is wlan0. To change this, we start by removing all the routes as

sudo ip route list

This removes the default interface. Here’s an output:

169.254.0.0/16 dev wlan0 scope link metric 1000 
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.10 metric 100

To set the default interface, add the route using the command:

sudo ip route add default via 192.168.0.1 dev eth0

Once executed successfully, you can list the default interface as:

sudo ip route list

Output:

default via 192.168.0.1 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1000 
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.10 metric 100

Conclusion

That’s it for this one. This is a quick tutorial shows you how to modify the IP routes to specify your default interfaces.

If you enjoy our content, please consider buying us a coffee to support our work:

Share
Comments
More from GeekBits

Join us at GeekBits

Join our members and get a currated list of awesome articles each month.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to GeekBits.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.