How to Add or Change the Default Gateway in Linux
Part 1 of 2:
Using the Terminal
- Open the Terminal. You can open the Terminal from the side bar, or by pressing Ctrl+Alt+T.
- 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.
- 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.
- 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.
- 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
- 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.
- 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.
- Add .gateway IP Address to the section. For example, type gateway 192.168.1.254 to make the default gateway 192.168.1.254.
- Save your changes and exit. Press Ctrl+X and then Y to save your changes and exit.
- Restart your network. Restart your network by typing sudo /etc/init.d/networking restart.[1]
4.5 ★ | 4 Vote
You should read it
- How to use sudo without password in Linux
- How to Add or Change the Default Port on Linux
- The sudo command is coming to Windows 11
- Linux Error SUDO allows you to run commands as root
- How to fix 'The 504 Gateway Timeout' error
- How to reset the password for sudo in Debian
- Correct the 'The default gateway is not available' error on Windows 10
- SpaceX signs on to ship cargo to NASA's future lunar Gateway in orbit around the moon
May be interested
- How to Install Linuxlinux 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 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 Linuxyou 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 KUserkuser 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 Linuxin 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.3this 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...