Table of Contents
This updated guide examines How to Add or Change the Default Gateway in Linux and organizes the essential facts, background, and practical takeaways in clear American English.
Part 1of 2:
Using the Terminal
Open the Terminal. You can open the Terminal from the side bar, or by pressingCtrl+Alt+T.
View your current default gateway. You can check what your default gateway is set to by typingrouteand 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.
- Typesudo route delete default gwIP AddressAdapter. For example, to delete the default gateway 10.0.2.2 on theeth0adapter, typesudo route delete default gw 10.0.2.2 eth0.
Type.sudo route add default gwIP AddressAdapter. For example, to change the default gateway of theeth0adapter to 192.168.1.254, you would typesudo route add default gw 192.168.1.254 eth0. You'll be prompted for your user password to complete the command.
Part 2of 2:
Editing Your Configuration File
Open the configuration file in an editor. Typesudo nano /etc/network/interfacesto 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 usuallyeth0.
Add.gatewayIP Addressto the section. For example, typegateway 192.168.1.254to make the default gateway 192.168.1.254.
Save your changes and exit. PressCtrl+Xand thenYto save your changes and exit.
Restart your network. Restart your network by typingsudo /etc/init.d/networking restart.[1]
FAQ
What is How to Add or Change the Default Gateway in Linux about?
It provides a structured overview of default, explains the main context, and highlights practical takeaways for readers.
Why does this topic matter?
Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.
How should readers use this information?
Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.
Reader Comments 0
Sign in with email or Google to join the discussion.