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
- Duo laptop entertainment Gatewaythe difference is that the gateway mc7803u has a strong graphics card, a black cover and the mc7801u is equipped with an integrated chip, the red back surface, both are powerful entertainment laptops.
- Gateway 'ultraportable' laptop pairboth gateway id49c and ec 19c were present in vietnam with a respectable weight, thinness, sleekness and high configuration that cost less than vnd15 million.
- How to change Google DNS on Linuxin the previous article, tipsmake.com showed you how to change google dns on a mac. today, let's find out how to change dns on linux and its distributions.
- Gateway to add two Core laptops ithe new id line of gateway with two screen sizes (14 and 15.6 inches) is equipped with core i3 and core i5 chips along with 4gb of ram
- How to change the default browser on Androidbrowsers on smartphones in general and on android in particular are usually quite simple and do not have many useful features like google chrome, firefox or dolphin, ... instead of using the default browser available in your computer completely can change as you like to enhance your experience when using.
- 3 ways to change the default browser in Windows 10in windows 10, the default web browser will be microsoft edge, the latest browser developed by microsoft. however, even if edge has many new and improved features compared to the previous browser, internet explorer, you may still want to change your favorite default browser. so how to change the default browser here? please follow the tutorial below of network administrator.
- How to change desktop theme on Linux Mintlinux mint is a great linux distribution for anyone getting started with linux. it comes in 3 different versions: cinnamon, mate and xfce, each catering to a different audience.
- Instructions for fixing 502 Bad Gateway error502 bad gateway error is an http status code error (http status code), which means that a server (server) receives an invalid response from another server (server).
- How to change the default shell in Windows Terminalnormally, when you open windows terminal, powershell will launch as the default shell. however, if you want, you can optionally change this default shell to something of your liking, such as command prompt or ubuntu (linux).
- How to set and change a user password in Linuxboth linux and unix operating systems use the passwd command to change the user password. the password used to update the user's authentication token (password) is stored in the / etc / shadow file.