wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 14 people, some anonymous, worked to edit and improve it over time.
This article has been viewed 973,867 times.
Learn more...
If you need to find or change the IP address of your default gateway or router on Linux, you're in luck—it's super easy to do. This wikiHow article will show you how to use the route command to find the default gateway IP address on Linux, and how to set a new default gateway in your /etc/network/interfaces configuration file.
Steps
Using the Terminal
-
1Open the Terminal. You can open the Terminal from the side bar, or by pressing Ctrl+Alt+T.[1]
-
2View 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.Advertisement
-
3Delete 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.[2]
- 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.
-
4
Editing Your Configuration File
-
1Open 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.[4]
-
2Navigate 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.
-
3Add .gateway IP Address to the section. For example, type gateway 192.168.1.254 to make the default gateway 192.168.1.254.[5]
-
4Save your changes and exit. Press Ctrl+X and then Y to save your changes and exit.
-
5Restart your network. Restart your network by typing sudo /etc/init.d/networking restart.[6]
Community Q&A
-
QuestionWill the admins know if I change my IP?Community AnswerYes, if they chose to check.
References
- ↑ https://linuxhint.com/how-to-open-ubuntu-terminal-keyboard-shortcuts/
- ↑ https://howto.lintel.in/add-delete-routes-linux/
- ↑ https://www.cyberciti.biz/faq/linux-setup-default-gateway-with-route-command/
- ↑ https://help.ubuntu.com/community/NetworkConfigurationCommandLine
- ↑ https://help.ubuntu.com/community/NetworkConfigurationCommandLine
- ↑ https://help.ubuntu.com/community/NetworkConfigurationCommandLine
About This Article
1. Open a terminal window.
2. Type "sudo route delete default gw (IP) (Adapter)" and press Enter.
3. Type "sudo route add default gw (IP) (Adapter)" and press Enter.
4. Open /etc/network/interfaces in a text editor.
5. Update the gateway IP address for the adapter.
6. Save your changes and exit the editor.
7. Type "sudo /etc/init.d/networking restart" and press Enter.