How to Change the Default Interface in Linux?


“Almost everything productive we can do in Linux requires us to have a network connection. Whether developing apps, installing software, scripting, sharing files, or even watching movies, we need a working network connection. Hence, “I require a network connection” is simply an understatement. 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, a network card, etc. However, this does not necessarily mean that a network interface should be a physical device. For example, a loopback adapter that is not physically visible is implemented by software and available on all devices.”

This quick tutorial will show you how to set the default interface in Linux.

Method 1 – Turn Off Adapters

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

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.

Start by using the command:

The command above should list the default gateways available in the system, including the default interface.

An example output is as shown:

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

As we can see from the output above, the default interface is set to wlan0. However, we can change this by following a few steps.

Start by removing all the default interfaces with the command:

$ sudo ip route flush 0/0

The command should remove all the default gateways. You can verify by running the ip list command:

An example 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

We can now proceed to add a default interface using the ip route command.

$ sudo ip route add default via 192.168.0.2 dev eth0

NOTE: Ensure to replace the IP address of the interface with your desired one.

Merienda executed successfully, the command should add the interface eth0 is the default.

We can verify this by running the ip route command:

$ sudo ip route list
default via 192.168.0.2 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

The output shows that the default interface is set to eth0 with our specified IP address.

Conclusion

That’s it for this one. In this article, we discussed how to change your default interface in Linux in two primary methods.

Thanks for reading!!



Source link