blog

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

Changing the default gateway in Ubuntu 20 is a fundamental aspect of network configuration. Whether you are managing a server or a local workstation, understanding how to modify the default gateway is essential for maintaining a seamless network connection. This guide will walk you through the steps to change the default gateway on Ubuntu 20, while also highlighting the importance of API calls, the use of Kong as an API gateway, the concept of Open Platform, and Routing Rewrite.

Why Change the Default Gateway?

Before we delve into the steps involved in changing the default gateway, it’s important to understand the significance of the default gateway. The default gateway serves as the main access point for your machine to communicate with devices outside of your local network. If you do not correctly configure the default gateway, your machine will be unable to connect to the internet or other external networks.

The default gateway is typically a router on the network, and it directs packets that are destined for outside the local subnet. Here are some reasons why you might want to change the default gateway:

  • Network Reconfiguration: If you are moving to a new network or have changed your network configuration, you may need to update the default gateway to reflect this change.
  • Performance Improvements: Changing the gateway can help optimize performance by connecting to a more efficient route for your data packets.
  • Issue Troubleshooting: Sometimes, a default gateway can become unresponsive, necessitating a change to restore connection reliability.

Pre-requisites for the Gateway Change

Ensure you have the following before proceeding with the changes:

  • Administrative access to the Ubuntu machine.
  • Basic familiarity with using the terminal.
  • Relevant IP address information of your new network gateway.

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

Step 1: Open the Terminal

To change the default gateway, you will need to access the terminal. You can do this by pressing Ctrl + Alt + T on your keyboard or searching for “Terminal” in the application menu.

Step 2: View Current Network Configuration

Before making any changes, it’s good practice to check your existing network configuration. You can do this by executing the following command:

ip route show

This command will display the current routing table, including the default gateway. Look for a line that starts with default via, which indicates the current default gateway.

Step 3: Change the Default Gateway

To change the default gateway, you can use the ip command. The syntax to set a new default gateway is as follows:

sudo ip route add default via [NEW_GATEWAY_IP]

Replace [NEW_GATEWAY_IP] with the IP address of your new gateway. For example, if your new gateway IP is 192.168.1.1, you would run:

sudo ip route add default via 192.168.1.1

Step 4: Verify the Change

After making the change, it is crucial to verify that it was successful. Run the ip route show command again to confirm that the default gateway has been updated. You should now see the new gateway listed.

Step 5: Make the Changes Permanent

The above changes will not persist after a reboot. To make them permanent, you can edit the Netplan configuration file. Open the file in a text editor with the following command:

sudo nano /etc/netplan/01-netcfg.yaml

In this file, locate the configuration section for your network interface (usually named eth0, ens33, etc.) and add or modify the gateway4 entry to reflect your new gateway. The format should look like this:

network:
  version: 2
  ethernets:
    eth0:  # (or your interface name)
      addresses:
        - 192.168.1.10/24
      gateway4: 192.168.1.1  # new default gateway

Make sure to replace the IP addresses with your actual network interface’s IP address and the new gateway IP.

Step 6: Apply the Changes

After editing the configuration file, apply the changes using the following command:

sudo netplan apply

This will apply the new network configuration, including your updated default gateway.

Troubleshooting Common Issues

In case you encounter connectivity issues after changing the default gateway:

  • Check Network Cables: Ensure that physical connections are intact.
  • Firewall Settings: Adjust firewall settings if they are blocking traffic.
  • DNS Configuration: Verify that your DNS settings are correct for external access.

Incorporating APIs into Your Routing

As we move deeper into networking, it’s important to consider the role of APIs and tools like Kong in modern infrastructures. API calls allow applications to communicate with each other and can be instrumental in managing data flow. Below is an overview of how you can utilize APIs, specifically focusing on Kong as an API gateway.

What is Kong?

Kong is an open-source API gateway that can help you manage, secure, and orchestrate your APIs effectively. By utilizing Kong, you can handle everything from authentication to rate-limiting, making it easier to maintain a robust API ecosystem.

How API Calls Work with Kong

Using Kong, you can set up API calls that redirect traffic to your applications based on defined routes. API routing can optimize the user experience and ensure that requests are handled efficiently. Here’s an example of an API call set up in Kong:

curl -i -X POST http://localhost:8001/services/ \
--data '{
  "name": "my-service",
  "url": "http://httpbin.org:80"
}'

This command registers a service called my-service that Kong will route requests to.

Open Platform and Routing Rewrite

An open platform approach, particularly using Kong, can facilitate a diverse range of services and enhance flexibility in managing network calls. It allows various teams and departments to seamlessly integrate their services while controlling the flow of data.

With Routing Rewrite features in Kong, you can modify requests and responses dynamically, improving the performance of your service strategies. Whether you’re redirecting users to different endpoints or transforming requests on the fly, these capabilities ensure that your APIs remain efficient and user-friendly.

Example of Routing Rewrite in Kong

To demonstrate Routing Rewrite, consider the following example configuration:

plugins:
  - name: request-transformer
    service: my-service
    config:
      add:
        - "X-API-Request-Id:123"
      remove:
        - "X-Request-ID"

This configuration will add a new header X-API-Request-Id while removing X-Request-ID from incoming requests to my-service. This transformation can streamline how data is processed across different services.

Conclusion

Changing the default gateway in Ubuntu 20 is essential for a reliable network connection. Through the steps outlined in this guide, you can efficiently manage your network configurations. At the same time, incorporating API gateways such as Kong into your networking strategy can significantly enhance your application’s performance and flexibility. Utilizing API calls and understanding routing, whether it’s for traditional networking or developing an open platform, will provide a competitive edge in managing your services.

As you apply these concepts, always evaluate ongoing performance and connectivity to ensure that your network infrastructure sustains the necessary growth and responsiveness required in today’s digital landscape.

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! 👇👇👇

Through this comprehensive understanding, you can confidently manage your network settings while leveraging modern API technologies to streamline your operations. Happy networking!

Summary Table of Steps to Change Default Gateway

Step Command / Action
Open terminal Ctrl + Alt + T
View current network configuration ip route show
Change the default gateway sudo ip route add default via [NEW_GATEWAY_IP]
Verify the change ip route show
Make changes permanent Edit /etc/netplan/01-netcfg.yaml
Apply the changes sudo netplan apply

With the detailed walkthrough above, you now have a solid foundation to adapt your network settings appropriately and utilize API management tools to enhance interoperability and service execution across your systems.

🚀You can securely and efficiently call the Wenxin Yiyan 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 Wenxin Yiyan API.

APIPark System Interface 02