How to Change the Default Gateway on Ubuntu 20

How to Change the Default Gateway on Ubuntu 20
how to change default gateway on ubuntu 20

Changing the default gateway on Ubuntu 20 can be vital for network configuration, especially if you're setting up a server, configuring a network, or need to change your internet connection settings. The default gateway is an essential component of a computer network; it serves as a routing device for data traveling outside an individual network by forwarding traffic to other networks.

Understanding Default Gateway

Before diving into the steps involved in changing the default gateway on Ubuntu 20, it's essential to grasp what a default gateway is. The default gateway acts as an intermediary that directs outbound traffic from your local network to the Internet or another network. Essentially, it's the path your data takes to reach other networks beyond your current one.

In a home or corporate setup, a router typically acts as the default gateway. You can verify its status by running the ip route command in the terminal, which displays the routing table and the current default gateway settings.

Why Change the Default Gateway?

There are several reasons why you may need to change the default gateway:

  • Changing ISPs: If you switch to a new Internet Service Provider (ISP), you might need to change your gateway settings to reflect your new router's IP address.
  • Setting up a new network: If you’re implementing a new local network configuration, the gateway IP might change to accommodate new devices or a different layout.
  • Troubleshooting: Sometimes, network misconfiguration or connectivity issues require updates to the default gateway to restore access to external networks.
  • Using VPNs: If you are connected to a Virtual Private Network (VPN), your default gateway may need to be adjusted for proper routing of network traffic.

Now that the groundwork has been laid down, let’s delve into how to change the default gateway on Ubuntu 20 step by step.

Method 1: Change Default Gateway via the Terminal

Using the terminal is one of the most effective ways to change the default gateway on Ubuntu 20 because it provides direct control and immediate application of changes.

Step 1: Open the Terminal

You can open the terminal by searching for "Terminal" in the Activities overview or pressing Ctrl + Alt + T.

Step 2: Check Current Network Configuration

Before making any changes, it’s prudent to inspect your current network configuration. You can do this by executing the following command:

ip route

This command will list your current routing table and display the default gateway.

Step 3: Deleting the Current Default Gateway

To change the default gateway, you first need to delete the existing one. You can do this by executing:

sudo ip route del default via [current_gateway_ip]

Replace [current_gateway_ip] with the actual IP address of the current gateway. For instance, if the current gateway IP is 192.168.1.1, the command will be:

sudo ip route del default via 192.168.1.1

Step 4: Adding the New Default Gateway

Now you can add the new default gateway. The command to accomplish this is as follows:

sudo ip route add default via [new_gateway_ip]

Replace [new_gateway_ip] with the new gateway's IP address. For instance, if your new gateway is 192.168.1.254, you would enter:

sudo ip route add default via 192.168.1.254

Step 5: Verify the Changes

After executing the previous commands, it's good practice to verify your changes. Run the ip route command again:

ip route

You should see the new default gateway reflected in the output.

APIPark is a high-performance AI gateway that allows you to securely access the most comprehensive LLM APIs globally on the APIPark platform, including OpenAI, Anthropic, Mistral, Llama2, Google Gemini, and more.Try APIPark now! 👇👇👇

Method 2: Change Default Gateway via Network Manager

If you're using a graphical user interface (GUI), you can also change the default gateway through Network Manager.

Step 1: Open Network Settings

Click on the network icon in the upper right corner of your screen. Then, select "Settings" or "Network Settings."

Step 2: Select the Network Interface

In the settings window, look for your active network connection (either wired or wireless). Click on the gear icon next to the active network connection.

Step 3: Go to IPv4 Settings

In the network settings dialog, navigate to the IPv4 tab. This is where you can define your default gateway along with other settings.

Step 4: Edit the Gateway

In the Additional Routing Options or Routes section, enter the new gateway IP address. You may also need to remove the old gateway entry.

Step 5: Apply Changes

Click on "Apply" or "Save" to make sure your changes are effective. The modifications will typically take effect immediately.

Step 6: Check New Settings

Just to be thorough, you can still check the new settings using the terminal's ip route command.

Configuration File Changes

Another method to set a default gateway is by modifying the network interface configuration files. Ubuntu uses netplan for network configuration.

Step 1: Locate Netplan Configuration File

You'll need to find the netplan configuration file located in /etc/netplan/. You can list the contents using:

ls /etc/netplan/

Step 2: Open Configuration File in a Text Editor

Choose the appropriate YAML file and edit it:

sudo nano /etc/netplan/[configuration_filename].yaml

Step 3: Modify Gateway Setting

Locate the section that corresponds to your network interface. You can add or update the gateway entry as follows:

network:
  version: 2
  ethernets:
    [your_network_interface]:
      dhcp4: no
      addresses: [your_ip_address]
      gateway4: [new_gateway_ip]
      nameservers:
        addresses: [nameserver_ip]

Step 4: Apply the Changes

After making the necessary changes, apply them with the netplan command:

sudo netplan apply

Step 5: Validate Configuration

It is once again crucial to check that the changes have taken effect using the command:

ip route

Setting Up APIPark with Your New Gateway

If you are using various web services, such as APIPark, changing the default gateway may also impact how your APIs communicate with the outside world. For developers utilizing the APIPark - Open Source AI Gateway & API Management Platform, ensure that the routing settings complement your API configurations.

The flexibility of the API calls made through APIPark ensures that your applications maintain efficiency, especially if client requests leverage AI components that require reliable communications with other network resources.

Troubleshooting Gateway Changes

When changing the default gateway, you may encounter issues if the settings aren't correctly configured. Some common troubleshooting steps you can follow include:

  1. Try Ping: Test your connection by attempting to ping an external site such as Google. Use:bash ping 8.8.8.8
  2. Check Network Connectivity: Ensure that the physical connection (if wired) is intact and functioning correctly. Also, confirm wireless connectivity if using Wi-Fi.
  3. Recheck Configuration: Go through your changes once more, ensuring that the entered IP addresses are correct and not conflicting with other devices on the network.
  4. Consult System Logs: Use dmesg and syslog for any pertinent error messages related to network changes.
  5. Reboot: Sometimes, a simple reboot could resolve lingering issues post-configuration.

Conclusion

Changing the default gateway on Ubuntu 20 is not a daunting task but is a vital skill for system administrators and users alike. Knowing how to do it through various methods enables flexibility in managing network configurations, whether through command line, GUI, or configuration files. As you've learned, the default gateway plays a critical role in enabling seamless communication between your local devices and external networks, including vital services like APIPark.

FAQ

1. What is a default gateway? The default gateway is a networking device that routes traffic from your local network to the internet or other networks.

2. Why would I need to change my default gateway? You might need to change your default gateway due to a change in ISP, new networking hardware, or troubleshooting connectivity issues.

3. How can I check my current default gateway in Ubuntu? You can check the current default gateway by running ip route in the terminal.

4. Can I change the default gateway through GUI in Ubuntu? Yes, you can change the default gateway via the Network Manager GUI by modifying the settings of your active network connection.

5. What happens if I set the wrong default gateway? Setting the wrong default gateway can lead to connectivity issues, preventing your device from accessing external networks like the internet.

🚀You can securely and efficiently call the OpenAI API on APIPark in just two steps:

Step 1: Deploy the APIPark AI gateway in 5 minutes.

APIPark is developed based on Golang, offering strong product performance and low development and maintenance costs. You can deploy APIPark with a single command line.

curl -sSO https://download.apipark.com/install/quick-start.sh; bash quick-start.sh
APIPark Command Installation Process

In my experience, you can see the successful deployment interface within 5 to 10 minutes. Then, you can log in to APIPark using your account.

APIPark System Interface 01

Step 2: Call the OpenAI API.

APIPark System Interface 02

Learn more

Configuring networks - Ubuntu

A Step-by-Step Guide on How to Change Default Gateway on Ubuntu 20

How to Set the Default Gateway in Linux - How-To Geek