How to Change the Default Gateway on Ubuntu 20

Open-Source AI Gateway & Developer Portal
Changing the default gateway in Ubuntu 20 is an essential task for network configuration. Whether you are managing a server or just setting up a new machine for home or office use, understanding how to change and verify your default gateway will allow proper communication within networks and between different networks. This article serves as a comprehensive guide to help you successfully change the default gateway on Ubuntu 20.
Understanding the Default Gateway
What is a Default Gateway?
A default gateway is a critical component in network configurations—it acts as an access point or IP router that networked devices use to communicate with devices on other networks. By default, when a device wants to communicate with another device, it sends the data to the default gateway, which decides where to send that data next.
Why Change the Default Gateway?
There are several reasons why you might need to change the default gateway: - Network Changes: If you change your network setup, you may need to update the gateway to match the new router or network configuration. - Multiple Networks: In environments with multiple networks, managing traffic systematically may necessitate changing gateway settings. - Troubleshooting: If you're experiencing connectivity issues, changing the gateway may help resolve routing problems.
Steps to Change the Default Gateway
1. Checking Current Default Gateway
Before making any changes, it’s important to check the current default gateway settings. This can be easily achieved with the terminal.
Open the Terminal and run the following command:
ip route show
This command will output something like this:
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
In this example, 192.168.1.1
is the current default gateway.
2. Changing the Default Gateway Temporarily
To change the default gateway temporarily (until the next reboot), execute the following command in the terminal:
sudo ip route add default via NEW_GATEWAY_IP
Replace NEW_GATEWAY_IP
with the IP address of your desired gateway.
To remove the old default gateway (if needed), use:
sudo ip route del default via OLD_GATEWAY_IP
3. Making the Change Permanent
If you want to make the gateway change permanent, you will need to modify the network configuration files.
For Ubuntu 20, the following steps should be taken:
Edit Netplan Configuration
- Identify the Netplan Configuration File: The configuration files are typically located in the
/etc/netplan/
directory. You may find files named01-netcfg.yaml
or50-cloud-init.yaml
. You can list the files using:
bash ls /etc/netplan/
- Edit the Configuration File: Open the relevant configuration file in a text editor (for example,
nano
):
bash sudo nano /etc/netplan/01-netcfg.yaml
- Modify the Gateway: Look for the
gateway4
line under your network configuration and update it to the new gateway IP address. Here is an example configuration:
yaml network: version: 2 renderer: networkd ethernets: eth0: dhcp4: true gateway4: NEW_GATEWAY_IP
Replace NEW_GATEWAY_IP
with your desired gateway.
- Apply the Changes: After saving the file, apply the configuration changes with the command:
bash sudo netplan apply
4. Verifying the Changes
After changing the default gateway, it’s crucial to verify that the change has been applied successfully.
Run the following command:
ip route show
Ensure that the output now reflects your new default gateway.
Troubleshooting Common Issues
No Internet Connection
If you've changed the default gateway and lost internet connection, verify the following: - Check if the new gateway IP is reachable using the ping
command. For instance:
bash ping NEW_GATEWAY_IP
- Ensure that the gateway IP is valid and configured correctly.
Incorrect Configuration
If you are facing issues after editing the Netplan configuration, it’s advisable to revert changes to the previous configuration file and reapply it using the netplan apply
command.
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! 👇👇👇
Network Configuration Example
Here is an example configuration for a static IP address and a default gateway in the YAML format:
Example Config | Description |
---|---|
network: | Top-level key for the configuration |
version: 2 | Specifies the version of Netplan |
renderer: networkd | Indicates the renderer for the config |
ethernets: | Defines Ethernet devices/settings |
eth0: | Specific Ethernet interface |
dhcp4: false | Disabled DHCP |
addresses: | List of static IP addresses |
- 192.168.1.10/24 | Assigned static IP |
gateway4: 192.168.1.1 | The new default gateway |
nameservers: | DNS server settings |
addresses: | List of DNS server addresses |
- 8.8.8.8 | Example: Google DNS |
- 8.8.4.4 | Example: Google DNS |
Using the above format, you can easily set up your networking needs.
Benefits of Proper Gateway Configuration
Understanding how to manage gateways can significantly enhance your network performance, security, and management. A well-configured gateway facilitates: - Efficient Data Transfer: Ensures reliable communication between devices and external networks. - Improved Security: With the ability to set up rules and restrictions on gateway traffic. - Easier Troubleshooting: Problems can be diagnosed and resolved faster with a clear view of gateway operations.
Conclusion
Changing the default gateway on Ubuntu 20 is a straightforward procedure and depends largely on whether you prefer to make a temporary or permanent change. It is essential to keep your network configurations in check for efficient operations.
Additionally, if you are venturing into API management and require an effective gateway solution, you might find APIPark to offer robust capabilities in API governance. It simplifies the management of AI services and REST APIs, facilitating smoother networking operations tailored to your needs.
FAQ
- What is the default gateway?
- The default gateway is a router that serves as an access point to send data from one network to another.
- How do I check my current default gateway?
- You can check the current default gateway by executing the command
ip route show
in the terminal. - Can I configure multiple gateways?
- Yes, you can configure multiple gateways; however, only one will be the default at any given time.
- What to do if changing the gateway doesn't work?
- Verify the IP address, check ping connectivity to the new gateway, and confirm that the configuration syntax is correct.
- Can APIPark help with my gateway management?
- Yes, APIPark offers advanced features for API management and can help optimize traffic through effective gateway management.
🚀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

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.

Step 2: Call the OpenAI API.

Learn more
How to Set the Default Gateway in Linux - How-To Geek
A Step-by-Step Guide on How to Change Default Gateway on Ubuntu 20
A Step-by-Step Guide on How to Change Default Gateway on Ubuntu 20