How to Add or Change the Default Gateway in Linux

Part 1 of 2:

Using the Terminal

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

  1. How to Add or Change the Default Gateway in Linux Picture 5
    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.
  2. How to Add or Change the Default Gateway in Linux Picture 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 usually eth0.
  3. How to Add or Change the Default Gateway in Linux Picture 7
    Add .gateway IP Address to the section. For example, type gateway 192.168.1.254 to make the default gateway 192.168.1.254.
  4. How to Add or Change the Default Gateway in Linux Picture 8
    Save your changes and exit. Press Ctrl+X and then Y to save your changes and exit.
  5. How to Add or Change the Default Gateway in Linux Picture 9
    Restart your network. Restart your network by typing sudo /etc/init.d/networking restart.[1]
4.5 ★ | 4 Vote

May be interested

  • How to Install LinuxPhoto of How to Install Linux
    linux is the foundation of thousands of open source operating systems designed to replace windows and mac os. it is free to download and install on any computer. because it is open source, there are a variety of different versions, or...
  • How to Deploy .Net Applications to the Linux Platform With Confidence Using Mono With Delphi PrismPhoto of How to Deploy .Net Applications to the Linux Platform With Confidence Using Mono With Delphi Prism
    .net since inception has captivated developers across the world, with its simplicity in terms of development, and flexibility of deployment of enterprise class applications. today, windows applications are reaching new frontiers in the...
  • How to Encrypt Files in LinuxPhoto of How to Encrypt Files in Linux
    you may not want people to see important files on your computer, particularly if it has multiple users. there are several different ways to restrict access to a particular file in the system, but unfortunately, most of them consume a lot...
  • How to Use KUserPhoto of How to Use KUser
    kuser is an application used in many linux distros to create, delete, or manage user accounts. these instructions assume you are using the kde 4 version (the more recent version). click the 'add' button on the top toolbar.
  • How to Change the Position of the Wbar Dock in AV LinuxPhoto of How to Change the Position of the Wbar Dock in AV Linux
    in the latest av linux version, the wbar dock is located at the top of the screen. this can be quite annoying to those who are use to using it from the bottom. this small problem can be quickly solved by following the steps below. open...
  • How to Set up Php on Apache 2.2.3 on CentOS 5.3Photo of How to Set up Php on Apache 2.2.3 on CentOS 5.3
    this article is aimed at people who have centos 5.3 and apache 2.2.3. it may also work on rhel (but you have to pay for rhel). connect to your vps using ssh to get a command line (unless its being installed on your local machine). your...