How to Add or Change the Default Gateway in Linux
Your default gateway is the IP address of your router. Typically this is automatically detected by your operating system during installation, but you may need to change it. This is especially true if you have multiple network adapters or...
Part 1 of 2:
Using the Terminal
- Open the Terminal. You can open the Terminal from the side bar, or by pressing Ctrl+Alt+T.
- View your current default gateway. You can check what your default gateway is set to by typing route and pressing ↵ Enter. The address next to "default" shows your default gateway, and the interface it is assigned to is displayed on the right side of the table.
- Delete your current default gateway. If you have more than one default gateway set, you'll run into connection conflicts. Delete your existing default gateway if you intend to change it.
- Type sudo route delete default gw IP Address Adapter. For example, to delete the default gateway 10.0.2.2 on the eth0 adapter, type sudo route delete default gw 10.0.2.2 eth0.
- Type .sudo route add default gw IP Address Adapter. For example, to change the default gateway of the eth0 adapter to 192.168.1.254, you would type sudo route add default gw 192.168.1.254 eth0. You'll be prompted for your user password in order to complete the command.
Part 2 of 2:
Editing Your Configuration File
- Open the configuration file in an editor. Type sudo nano /etc/network/interfaces to open the file in the nano editor. Editing your configuration file will keep your changes every time the system restarts.
- Navigate to the correct section. Find the section for the adapter you want to change the default gateway for. For a wired connection, this is usually eth0.
- Add .gateway IP Address to the section. For example, type gateway 192.168.1.254 to make the default gateway 192.168.1.254.
- Save your changes and exit. Press Ctrl+X and then Y to save your changes and exit.
- Restart your network. Restart your network by typing sudo /etc/init.d/networking restart.[1]
4.5 ★ | 4 Vote
You should read it
- How to find the default gateway IP address
- What is the Default Gateway? How to view and configure the Default Gateway on Windows
- How to use sudo without password in Linux
- How to Add or Change the Default Port on Linux
- The sudo command is coming to Windows 11
- Linux Error SUDO allows you to run commands as root
- How to fix 'The 504 Gateway Timeout' error
- How to reset the password for sudo in Debian
- Correct the 'The default gateway is not available' error on Windows 10
- SpaceX signs on to ship cargo to NASA's future lunar Gateway in orbit around the moon
- Gateway to ultra-thin NV-series
- Duo laptop entertainment Gateway
Maybe you are interested
How to change the default font in Google Docs - Use the font of choice
Instructions to remove DirectX 11, restore default DirectX
How to remove Bing from Chrome and reset default search engine
How to set default applications on Android
Instructions for changing the default PDF reader on Windows 10
The printer cannot display default settings and what you need to do