How to Add or Change the Default Gateway in Linux

Open the Terminal., View your current default gateway., Delete your current default gateway., Type .sudo route add default gw IP Address Adapter., Open the configuration file in an editor., Navigate to the correct section., Add .gateway IP Address...

9 Steps 2 min read Medium

Step-by-Step Guide

  1. Step 1: Open the Terminal.

    You can open the Terminal from the side bar, or by pressing Ctrl+Alt+T.
  2. Step 2: 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. , 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. , 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. , 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. , Find the section for the adapter you want to change the default gateway for.

    For a wired connection, this is usually eth0. , For example, type gateway
    192.168.1.254 to make the default gateway
    192.168.1.254. , Press Ctrl+X and then Y to save your changes and exit. , Restart your network by typing sudo /etc/init.d/networking restart.
  3. Step 3: Delete your current default gateway.

  4. Step 4: Type .sudo route add default gw IP Address Adapter.

  5. Step 5: Open the configuration file in an editor.

  6. Step 6: Navigate to the correct section.

  7. Step 7: Add .gateway IP Address to the section.

  8. Step 8: Save your changes and exit.

  9. Step 9: Restart your network.

Detailed Guide

You can open the Terminal from the side bar, or by pressing Ctrl+Alt+T.

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. , 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. , 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. , 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. , Find the section for the adapter you want to change the default gateway for.

For a wired connection, this is usually eth0. , For example, type gateway
192.168.1.254 to make the default gateway
192.168.1.254. , Press Ctrl+X and then Y to save your changes and exit. , Restart your network by typing sudo /etc/init.d/networking restart.

About the Author

M

Margaret Thomas

Writer and educator with a focus on practical creative arts knowledge.

38 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: