Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Add or Change the Default Gateway in Linux

Learn how to add or change the default gateway in linux with clear steps, practical context, and useful troubleshooting guidance.

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

  1. How to Add or Change the Default Gateway in Linux — contextual image 1 Open the Terminal. You can open the Terminal from the side bar, or by pressingCtrl+Alt+T.
  2. How to Add or Change the Default Gateway in Linux — contextual image 2 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.
  3. How to Add or Change the Default Gateway in Linux — contextual image 3 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.
  4. How to Add or Change the Default Gateway in Linux — contextual image 4 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

  1. How to Add or Change the Default Gateway in Linux — contextual image 5 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.
  2. How to Add or Change the Default Gateway in Linux — contextual image 6 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.
  3. How to Add or Change the Default Gateway in Linux — contextual image 7 Add.gatewayIP Addressto the section. For example, typegateway 192.168.1.254to make the default gateway 192.168.1.254.
  4. How to Add or Change the Default Gateway in Linux — contextual image 8 Save your changes and exit. PressCtrl+Xand thenYto save your changes and exit.
  5. How to Add or Change the Default Gateway in Linux — contextual image 9 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.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.