How to Add or Change the Default Gateway in Linux

How to Add or Change the Default Gateway in Linux
How to Add or Change the Default Gateway in Linux

In Linux, you can add or modify the default gateway – You’re in luck since finding or changing your router’s default gateway’s IP address on Linux is quite simple. This wikiHow article will teach you how to change the default gateway in your /etc/network/interfaces configuration file as well as how to use the route command to retrieve the default gateway IP address on Linux.

Part 1 of 2: Opening the Terminal

1. Start up the terminal. The Terminal can be accessed via the sidebar or by entering Ctrl+Alt+T.

2 Check out your default gateway right now.
Enter route and hit Enter to see what your default gateway is currently set to. Your default gateway is indicated by the IP next to the word “default,” and the interface it is associated with is shown on the right side of the table.

3 Remove the default gateway you now use.
Conflicting connections occur if you set up multiple default gateways. If you want to change your default gateway, remove the current one.
To delete the default GW IP Address Adapter route, use sudo. Type sudo route delete default gw eth0, for instance, to remove the default gateway from the eth0 device.

4 Type
To add the default GW IP Address Adapter, type.sudo route. For instance, you might write sudo route add default gw eth0 to make the default gateway for the eth0 adapter. To finish the command, you will need to enter your user password.

Part 2 of 2 Editing Your Configuration File

1 Open an editor and the configuration file.
Open an editor and the configuration file. To launch the nano editor and open the file, type sudo nano /etc/network/interfaces. Every time the machine restarts, editing your configuration file will maintain your modifications.

2 Go to the right section by navigating.
Locate the section for the adapter whose default gateway you want to alter. The default value for a wired connection is eth0.

3 Add gateway IP Address should be included to the area. To set as the default gateway, type gateway as an example.

4 Enable saving and then leave.To save your changes and leave, use Ctrl+X and Y.

5. Start your network again. Switch off your network. By entering sudo /etc/init.d/networking restart, you can restart your network.