How to Change Default Gateway on Ubuntu 20: Easy Steps

How to Change Default Gateway on Ubuntu 20: Easy Steps
how to change default gateway on ubuntu 20

The digital arteries that carry the lifeblood of data across our global networks rely on a fundamental, yet often overlooked, component: the network gateway. For users and administrators of Ubuntu 20.04, understanding how to manage this crucial junction is not just a technical skill but a foundational aspect of network control and troubleshooting. Whether you're a seasoned system administrator responsible for a fleet of servers or a home user looking to fine-tune your local network, the ability to change your default gateway offers a powerful lever for directing traffic, resolving connectivity issues, and optimizing network performance. This comprehensive guide will take you on an in-depth journey into the heart of Ubuntu's networking, dissecting the concept of a gateway, exploring its pivotal role, and providing meticulous, step-by-step instructions for altering it, both temporarily and permanently, using various methods. Prepare to demystify the unseen architect of your network and master the art of directing its flow.

The Unseen Architect of Your Network: Demystifying the Default Gateway

In the intricate tapestry of interconnected devices that forms your network, every piece of data, every digital whisper, and every command needs a clear path to its destination. When that destination lies outside your immediate local network, it relies on a special device to act as its guide: the default gateway. Imagine your local network as a bustling city. All traffic within the city flows freely and directly. However, to send a letter to another city or to receive one from abroad, you wouldn't simply hand it to a random passerby; you'd take it to the post office, which acts as the central hub for all outgoing and incoming mail not destined for within the city limits. In the realm of computer networking, your default gateway is precisely that post office – the designated exit point for all data packets intended for destinations beyond your local subnet.

This gateway is typically a router, a specialized piece of hardware designed to forward packets between different networks. On a typical home network, your Wi-Fi router serves as both your local network access point and your default gateway to the internet. In a more complex corporate environment, it could be a dedicated router, a firewall, or even another server configured with routing capabilities. Its IP address is a critical piece of information that every device on your local network needs to know; without it, your computer would be isolated, unable to communicate with the vast expanse of the internet or any other remote network.

For users running Ubuntu 20.04, managing the network gateway is a task that might arise in several scenarios. Perhaps you are troubleshooting a connectivity issue where your device can communicate locally but fails to reach the internet. Or maybe you're reconfiguring your network after installing a new router, necessitating an update to the gateway address on all connected machines. In more advanced setups, you might be dealing with a multi-homed server connected to multiple networks, requiring specific routing rules to direct different types of traffic through different gateways. Network segmentation for security or performance, migrating infrastructure to a new subnet, or even dealing with changes from an Internet Service Provider (ISP) can all trigger the need to explicitly configure or change the default gateway.

Ubuntu 20.04, like its predecessors, offers robust and flexible tools for network configuration. While many desktop users rely on graphical interfaces for simplicity, the true power and precision lie in its command-line utilities. These tools allow for granular control, automation, and the ability to diagnose complex network issues. Before we dive into the practical steps, it's crucial to grasp the underlying network fundamentals. Changing the gateway is not an action to be taken lightly; an incorrect configuration can lead to complete loss of network connectivity, potentially locking you out of a remote server. Therefore, understanding the "why" and "how" with meticulous detail is paramount to ensuring a smooth and successful operation. This article will provide a comprehensive overview, ensuring that by the end, you will not only be able to change your default gateway but also possess a deeper understanding of its implications and the best practices for managing your network on Ubuntu 20.04.

Understanding the Fundamentals of Network Gateways

To truly master the act of changing a default gateway, one must first understand the fundamental building blocks of network communication. This foundational knowledge will not only empower you to execute the changes confidently but also to troubleshoot effectively when anomalies inevitably arise.

What is a Default Gateway? The Network's Exit Door

At its core, a default gateway is an IP address configured on a host (like your Ubuntu machine) that specifies the router on the local network segment responsible for forwarding packets to destinations outside that local segment. It's the "next hop" for any traffic that doesn't belong to the immediate subnet. Without a default gateway, your computer would only be able to communicate with other devices directly connected to the same local area network (LAN) segment, like other computers in your office or home. Any attempt to access a website on the internet, send an email, or connect to a server in a different part of the world would fail because your machine wouldn't know where to send those packets.

Consider the analogy of a small village (your local subnet) with a single road leading out to the rest of the world (the internet). The village elder (your computer) knows how to send messages to anyone within the village. But to send a message to someone in another village, they must take it to the designated messenger post (the default gateway) at the edge of their village. This messenger post then takes responsibility for forwarding the message further along the global road network. Without a designated messenger post, the message would simply pile up, unable to leave. Technically, when your computer needs to send a data packet, it first checks if the destination IP address is within its own local subnet. If it is, the packet is sent directly to the destination. If not, the packet is encapsulated and sent to the default gateway's MAC address (after an ARP request to resolve it), which then takes over the routing process.

IP Addressing and Subnetting: The Foundation of Locality

The concept of a default gateway is inextricably linked to IP addressing and subnetting. An IP address uniquely identifies a device on a network, much like a street address identifies a building. IPv4 addresses, the most common type, are 32-bit numbers usually represented as four decimal numbers separated by dots (e.g., 192.168.1.100). IPv6 addresses are 128-bit and offer a much larger address space.

Accompanying an IP address is a subnet mask (e.g., 255.255.255.0 or /24). The subnet mask defines which part of an IP address refers to the network and which part refers to the host. It essentially tells your computer how large your "local village" is. For instance, an IP address of 192.168.1.100 with a subnet mask of 255.255.255.0 (or 192.168.1.100/24 in CIDR notation) means that 192.168.1 is the network portion, and 100 is the host portion. Any device with an IP address starting with 192.168.1 is considered to be on the same local network. If your machine needs to send a packet to 192.168.1.50, it knows it's local. If the destination is 192.168.2.10, it knows it's not local and must send the packet to the default gateway.

The default gateway itself must always reside on the same local subnet as the device trying to use it. For example, if your computer has an IP address of 192.168.1.100/24, your default gateway must have an IP address like 192.168.1.1 or 192.168.1.254—any address within the 192.168.1.0/24 range that is assigned to your router.

Routing Tables: The GPS of Your System

Every operating system maintains a routing table, which is essentially a set of rules that tells the kernel how to forward IP packets. When your Ubuntu machine wants to send a packet, it consults this routing table to determine the best path to the destination. The routing table contains entries for various networks and hosts, specifying which network interface to use and, if the destination is remote, which next-hop IP address (i.e., the gateway) to send the packet to.

The most crucial entry in the routing table, from our perspective, is the "default route." This is the entry that corresponds to the default gateway. It's typically represented by a destination network of 0.0.0.0/0 (for IPv4) or ::/0 (for IPv6), meaning "any destination not explicitly covered by a more specific route." All traffic destined for outside the local network is directed through this default route to the specified default gateway.

You can view your system's routing table on Ubuntu using commands like ip route show or the older netstat -rn. The output will clearly show the "default" entry pointing to your current gateway.

# Example output from 'ip route show'
default via 192.168.1.1 dev enp0s3 proto dhcp src 192.168.1.100 metric 100
192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.100 metric 100

In this example, 192.168.1.1 is the default gateway, and enp0s3 is the network interface used to reach it.

Network Interfaces: Your System's Connection Points

Your Ubuntu machine connects to the network via one or more network interfaces. These can be physical interfaces like an Ethernet card (often named enpXsY or eth0 on older systems) or a Wi-Fi adapter (wlpXsY or wlan0), or virtual interfaces created for specific purposes. Each interface can have its own IP address, subnet mask, and potentially its own routing rules. When configuring a default gateway, you'll often need to specify which interface it should be associated with, especially in systems with multiple network connections. Understanding the naming conventions and status of your network interfaces is a prerequisite to making any network configuration changes.

Tools for Network Configuration on Linux

Ubuntu 20.04, like modern Linux distributions, primarily relies on specific tools for network management:

  • ip command: This is the modern, powerful, and preferred command-line utility for configuring network interfaces, IP addresses, and routing tables. It supersedes older tools like ifconfig and route. We will heavily utilize ip route for temporary gateway changes.
  • Netplan: Since Ubuntu 17.10, Netplan has been the default declarative network configuration system. You define your network setup in YAML files, and Netplan generates the necessary configuration for either NetworkManager (for desktops) or systemd-networkd (for servers). This is the primary method for making permanent gateway changes on Ubuntu servers.
  • NetworkManager: Predominantly used in desktop environments, NetworkManager provides a dynamic way to manage network connections. It offers both a graphical user interface (GUI) and a command-line interface (nmcli). It's suitable for persistent changes on desktop systems.
  • ifconfig and route: These are legacy commands. While still present for backward compatibility and sometimes used in older scripts or for quick diagnostic checks, they are generally deprecated in favor of the ip command. We will focus on the modern ip command for command-line route manipulation.

By understanding these core concepts—what a gateway is, how IP addresses and subnetting define locality, the role of routing tables, the function of network interfaces, and the tools available—you equip yourself with the knowledge necessary to confidently and competently manage your network configurations on Ubuntu 20.04.

Prerequisites and Precautions: Before You Begin

Before you embark on the journey of altering your Ubuntu system's default gateway, it is absolutely critical to prepare meticulously and take necessary precautions. Network configuration changes, especially to the default gateway, can have immediate and far-reaching consequences, potentially disrupting connectivity and isolating your machine. A moment of foresight can save you hours of troubleshooting later.

Root Privileges: The Key to Network Control

Modifying network settings on a Linux system requires administrative privileges. This means you will need to execute commands with sudo, which allows you to run programs with the security privileges of the superuser (root). Always ensure you are operating from an account with sudo capabilities. If you attempt to run network modification commands without sudo, you will likely encounter "permission denied" errors.

Network Information Gathering: Know Thy Network

The first and most crucial step is to gather detailed information about your current network configuration. You need to know what you have before you can effectively change it.

  1. Identify Current IP Address, Subnet Mask, and Default Gateway:
    • For IP Address and Subnet Mask: Use the ip a command (short for ip address show). Look for your active network interface (e.g., enp0s3, eth0, wlpXsY). bash ip a In the output, you'll see lines like inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic enp0s3. Here, 192.168.1.100 is your IP address, and /24 denotes the subnet mask (equivalent to 255.255.255.0).
    • For Current Default Gateway: Use ip route show or ip route show default. This command will display your kernel's routing table. bash ip route show default You're looking for a line starting with default via, such as default via 192.168.1.1 dev enp0s3. The IP address following via is your current default gateway.
    • For NetworkManager (Desktop/Server): If you're on a system using NetworkManager, nmcli device show <interface> can also provide comprehensive details for a specific interface. bash nmcli device show enp0s3 Look for IP4.ADDRESS[1], IP4.GATEWAY, and IP4.DNS.
  2. Identify Network Interface Name: From the outputs above, note down the exact name of the network interface you intend to configure (e.g., enp0s3, wlp2s0). This is crucial for specifying the correct interface in your commands and configuration files.
  3. Know the New Default Gateway IP Address: Before making any changes, you must have the correct IP address of the new router or device that will serve as your default gateway. This information typically comes from your network administrator, your new router's documentation, or by inspecting another device on the same desired network. An incorrect gateway IP will lead to network isolation. Ensure the new gateway IP is within the same subnet as your desired IP configuration for the interface.
  4. Understand Your Network Topology: It's helpful to have a basic mental (or physical) map of your network. Where is your router? What's its IP address? Are there any firewalls or other routing devices involved? This context will help in troubleshooting if things go awry.

Backup Existing Configuration: A Safety Net

Always, always back up your current configuration files before making permanent changes. This provides a clear path to revert to a known working state if something goes wrong.

  • Netplan: The primary configuration files for Netplan are located in /etc/netplan/. Identify the .yaml file(s) that configure your active interface (e.g., 01-network-manager-all.yaml, 50-cloud-init.yaml, or a custom file). Copy it to a safe location or rename it with a .bak extension. bash sudo cp /etc/netplan/01-network-manager-all.yaml /etc/netplan/01-network-manager-all.yaml.bak
  • NetworkManager: Configuration files for NetworkManager are usually in /etc/NetworkManager/system-connections/. While less common to manually edit these for gateway changes, a backup isn't a bad idea if you're making extensive changes.
  • Note Down Current Settings: Even for temporary changes, having your current IP, subnet, and gateway written down or copied somewhere accessible (not on the machine you're about to modify, in case you lose connectivity) is invaluable.

Access Methods: Don't Lock Yourself Out

If you are changing the gateway on a remote server accessible only via SSH, extreme caution is warranted. An incorrect change can immediately sever your SSH connection.

  • Console Access: Whenever possible, perform critical network changes from a directly connected keyboard and monitor (or through a hypervisor console for virtual machines). This guarantees you retain access even if network connectivity is lost.
  • Backup SSH Session (Advanced): If direct console access is not possible, consider opening a second SSH session before making changes. If the first session drops, the second might remain active long enough for you to attempt a fix or revert. This is not foolproof but can sometimes buy you a few crucial seconds.
  • netplan try: As we'll see, Netplan offers a netplan try command, which provides a timeout mechanism to automatically revert changes if network connectivity is lost, significantly reducing the risk of lockout.

Impact of Changing Gateway: Expect Disruption

Understand that changing your default gateway will, for a brief moment, disrupt all network traffic that relies on that route. If you're on a remote server, your SSH session will likely freeze or disconnect during the change. If it's a critical server, plan for a maintenance window to minimize impact on users or services.

Test Connectivity: Verify Your Work

After making any changes, immediately verify your connectivity.

  • Ping: Use ping to test reachability to the new default gateway IP, an IP address on your local network, and finally, an external IP address (e.g., 8.8.8.8 for Google's DNS). bash ping 192.168.1.1 # Ping the new gateway ping 8.8.8.8 # Ping an external IP
  • Traceroute: Use traceroute (or tracepath) to see the path your packets are taking to an external destination. This will confirm that your packets are indeed exiting through the correct default gateway. bash traceroute google.com The first hop in the output should be your new default gateway.
  • DNS Resolution: If you can ping external IPs but not hostnames (like google.com), your DNS configuration might be incorrect, which is a separate but often related issue.

By diligently following these prerequisites and precautions, you significantly mitigate the risks associated with altering your network configuration and set yourself up for a successful change of your default gateway on Ubuntu 20.04.

Method 1: Temporarily Changing the Default Gateway (Using ip route)

There are scenarios where you need to change your default gateway for a short period without making permanent alterations to your system's configuration files. This could be for diagnostic purposes, testing a new network configuration, or simply routing traffic through a different path for a specific task. For these situations, the ip route command-line utility is your best friend. Changes made with ip route are applied immediately but are not persistent; they will be lost upon a system reboot or if the network service is restarted.

When to Use This Method

  • Troubleshooting Network Issues: If you suspect your current gateway is faulty or misconfigured, you can temporarily switch to an alternative gateway to see if connectivity is restored.
  • Testing New Configurations: Before committing to a permanent change via Netplan or NetworkManager, you can use ip route to test if the new gateway IP and associated routing work as expected.
  • Temporary Network Rerouting: In specific cases, you might need to route all traffic through a different device for a brief period, perhaps for a security scan, data transfer, or to bypass a temporary network bottleneck.
  • No Reboot Required: This method allows you to change the gateway without restarting your system, which is crucial for servers where uptime is paramount.

Understanding the ip route Command

The ip route command is part of the iproute2 utility suite, the modern standard for network configuration on Linux. It provides comprehensive control over the kernel's routing table.

To change the default gateway temporarily, you'll primarily use two sub-commands:

  1. ip route delete default: This command removes the existing default route from the kernel's routing table. It essentially tells your system, "Forget the current messenger post for outgoing mail."
  2. ip route add default via <new_gateway_ip> dev <interface>: This command adds a new default route.
    • default: Specifies that this is the default route (for 0.0.0.0/0).
    • via <new_gateway_ip>: Specifies the IP address of the new default gateway. This IP must be reachable on your local network.
    • dev <interface>: (Optional but recommended) Specifies the network interface through which the gateway is reachable (e.g., enp0s3, wlp2s0). This is particularly important on systems with multiple network interfaces to ensure traffic exits the correct port.

Step-by-Step Guide with Examples

Let's walk through the process with a practical example. Assume your current default gateway is 192.168.1.1 and you want to temporarily change it to 192.168.1.254 using the enp0s3 interface.

Step 1: Identify Current Default Gateway

Before making any changes, confirm your current gateway. This also gives you the interface name.

ip route show default

Expected output might look like:

default via 192.168.1.1 dev enp0s3 proto dhcp src 192.168.1.100 metric 100

This confirms 192.168.1.1 is the current gateway and enp0s3 is the interface.

Step 2: Delete Existing Default Route

You cannot have two default routes simultaneously (at least, not without advanced policy routing, which is beyond a simple default gateway change). Therefore, you must first remove the old one.

sudo ip route delete default

Upon executing this command, your system might temporarily lose internet connectivity if it was relying solely on this route. If you're connected via SSH, your session might freeze momentarily or disconnect. This is expected.

Step 3: Add New Default Route

Now, add the new default route specifying the new gateway IP and the network interface.

sudo ip route add default via 192.168.1.254 dev enp0s3

Replace 192.168.1.254 with your desired new gateway IP address and enp0s3 with your actual network interface name.

Step 4: Verify Changes

Immediately after adding the new route, verify that it has been successfully applied to the kernel's routing table.

ip route show default

The output should now reflect your new gateway:

default via 192.168.1.254 dev enp0s3

You can also use ip route show to see the complete routing table and confirm the default route entry.

Step 5: Test Connectivity

The most critical step is to test if your system can now reach external networks through the new gateway.

  • Ping the new gateway: Ensure your system can reach the new gateway itself. bash ping 192.168.1.254 You should receive successful replies. If not, the gateway IP might be incorrect, the gateway device might be down, or there's a problem with your local network segment.
  • Ping an external IP address: Test connectivity to a reliable external IP, like Google's public DNS server. bash ping 8.8.8.8 If successful, it means your system can now reach the internet.
  • Traceroute to an external domain: Use traceroute to confirm the path your packets are taking. The first hop should be your new default gateway. bash traceroute google.com The output should show 192.168.1.254 as the first hop.

Example Scenario: Multi-homed Server

Imagine a server with two network interfaces, enp0s3 and enp0s4, each connected to a different network or VLAN. You want to temporarily send all outbound internet traffic through a gateway accessible via enp0s4 (e.g., 10.0.0.1) instead of the default 192.168.1.1 on enp0s3.

  1. Check current default route: ip route show default (let's assume it's via 192.168.1.1 dev enp0s3).
  2. Delete existing default route: sudo ip route delete default
  3. Add new default route: sudo ip route add default via 10.0.0.1 dev enp0s4
  4. Verify and test connectivity.

Limitations

  • Non-Persistent: As mentioned, changes made with ip route are temporary. They will be lost if your system reboots, if the network service (like systemd-networkd or NetworkManager) is restarted, or if the interface goes down and comes back up (depending on the renderer and configuration).
  • No Configuration File Changes: This method doesn't modify any configuration files on your system. It only manipulates the kernel's active routing table in memory.
  • No DNS Update: This command only affects routing. If your DNS servers are configured via DHCP and you change your gateway (which might imply changing networks), your DNS resolution might still be pointing to old, unreachable DNS servers. You might need to manually update /etc/resolv.conf for temporary DNS changes, though this file is often managed by Netplan or NetworkManager.

This method is invaluable for quick diagnostics and transient routing needs, offering immediate feedback and easy reversibility simply by rebooting the system or applying a saved persistent configuration. However, for permanent, production-ready changes, you'll need to use Netplan or NetworkManager.

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: Permanently Changing the Default Gateway (Using Netplan)

For servers and systems where network configurations need to be persistent across reboots and network service restarts, Netplan is the officially recommended and most robust method on Ubuntu 20.04 and later. Netplan is a declarative network configuration abstraction that works by reading YAML files and generating appropriate configuration files for either systemd-networkd (typically for servers) or NetworkManager (typically for desktops). This approach simplifies complex network setups and provides a consistent way to manage your network.

When to Use This Method

  • Server Configuration: Essential for headless servers where reliability and persistence are paramount.
  • Production Environments: Ensures that your network configuration, including the default gateway, is consistently applied after every boot.
  • Static IP Configurations: When you're assigning a static IP address to your Ubuntu machine, manually specifying the default gateway is a common practice.
  • Infrastructure as Code: For automated deployments and consistent network setups across multiple machines.

Introduction to Netplan

Netplan configuration files are stored in the /etc/netplan/ directory and typically have a .yaml extension. Ubuntu 20.04 usually comes with a default file, such as 01-network-manager-all.yaml (if NetworkManager is used) or 50-cloud-init.yaml (on cloud instances, often managed by cloud-init). You might also create your own custom files, like 00-installer-config.yaml. The system processes these files in lexical order.

A basic Netplan YAML file structure looks something like this:

network:
  version: 2
  renderer: networkd # or NetworkManager
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1 # This is where the default gateway is set
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Crucially, YAML is whitespace-sensitive. Incorrect indentation will lead to syntax errors. Always use spaces, not tabs, for indentation, and maintain consistent levels.

Identifying the Correct Netplan Configuration File

Before editing, determine which .yaml file is responsible for configuring the network interface whose default gateway you wish to change. 1. List files in /etc/netplan/: bash ls /etc/netplan/ You might see files like 01-network-manager-all.yaml, 50-cloud-init.yaml, or 00-installer-config.yaml. 2. Inspect the contents of each file using cat or nano to identify which one contains the configuration for your target network interface (e.g., enp0s3). 3. It's generally recommended to have only one active configuration file per interface to avoid conflicts. If multiple files configure the same interface, Netplan might merge them or use the last one processed, leading to unexpected behavior.

Editing the Netplan YAML File

Let's assume you've identified 00-installer-config.yaml as the file to modify, and your interface is enp0s3. You want to change the default gateway from 192.168.1.1 to 192.168.1.254 for a static IP configuration.

Step 1: Backup Existing Netplan File

This is an essential safety measure. If your changes break network connectivity, you can easily revert.

sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak

Step 2: Open the Netplan File for Editing

Use your preferred text editor, such as nano or vim.

sudo nano /etc/netplan/00-installer-config.yaml

Step 3: Modify the gateway4 Entry

Locate the section for your network interface (e.g., enp0s3) and update the gateway4 entry. If you are using IPv6, you would update gateway6.

Scenario A: Static IP Configuration (Most Common for Explicit Gateway Changes)

If your interface is configured with a static IP address (dhcp4: no), you'll likely have addresses and gateway4 already defined.

Original (Example):

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1 # Old gateway
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Modified (Example - changing gateway to 192.168.1.254):

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.254 # New gateway
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

Ensure that gateway4 is indented correctly, aligning with addresses and nameservers. The gateway4 IP address must be on the same subnet as the interface's IP address.

Scenario B: DHCP Configuration (Nuanced)

If your interface is configured to use DHCP (dhcp4: yes), the default gateway is typically provided automatically by the DHCP server. In such cases, explicitly setting gateway4 within the Netplan file is generally not recommended and can lead to conflicts or unexpected behavior. If your DHCP server is providing an incorrect gateway, the proper solution is to fix the DHCP server's configuration.

However, if you must override a DHCP-provided gateway or if your network setup is unusual, you might consider converting to a static IP configuration to gain full control over the gateway. Alternatively, some advanced users add a custom route using the routes section, but this is more complex than simply changing the gateway4 parameter. For a simple default gateway change with DHCP, it's usually indicative of a problem with the DHCP server itself.

For IPv6 Gateway: If you're configuring an IPv6 gateway, you would use gateway6 instead of gateway4.

    enp0s3:
      dhcp6: no
      addresses: [2001:db8::100/64]
      gateway6: 2001:db8::1 # IPv6 gateway
      nameservers:
        addresses: [2001:4860:4860::8888, 2001:4860:4860::8844]

Step 4: Save and Close the File

In nano, press Ctrl+O to save and Ctrl+X to exit.

Applying Netplan Changes

After modifying the YAML file, you need to apply the changes. Netplan provides a safe mechanism for this:

  1. Generate Configuration (Optional but Recommended for Debugging): This command checks for syntax errors in your YAML file and generates the backend configuration files (for systemd-networkd or NetworkManager) without applying them. bash sudo netplan generate If there are any syntax errors (e.g., incorrect indentation, missing colons), netplan generate will report them, allowing you to fix them before attempting to apply.
  2. Test Changes Safely (netplan try): This is a highly recommended step, especially on remote servers. netplan try applies the changes but starts a 120-second (default) timer. If you don't confirm the changes within that time (by pressing Enter), or if you lose network connectivity and the timer expires, Netplan automatically reverts to the previous working configuration. This prevents you from locking yourself out of a remote server. bash sudo netplan try If successful, you'll see a prompt like: Do you want to keep these changes? Press ENTER before the timeout to accept the new configuration.. At this point, test your network connectivity (ping, SSH, etc.). If all looks good, press ENTER to confirm the changes and make them permanent. If connectivity is broken, simply do nothing, and the changes will revert.
  3. Apply Changes Permanently (netplan apply): If you're confident in your changes (e.g., after successful netplan try or if you have console access), you can directly apply them. bash sudo netplan apply This command applies the generated configuration to the network interfaces. Unlike netplan try, netplan apply does not have an automatic rollback mechanism; the changes are permanent immediately.

Verifying Changes

After applying the Netplan configuration, always verify that your new default gateway is active.

  1. Check Routing Table: bash ip route show default Confirm that the default via entry now shows your new gateway IP address.
  2. Test Connectivity:
    • Ping your new default gateway (ping 192.168.1.254).
    • Ping an external IP address (ping 8.8.8.8).
    • Traceroute to an external domain (traceroute google.com) to ensure the first hop is your new gateway.
  3. Check Interface Status (Optional): bash ip a show enp0s3 Ensure your interface is up and has the correct IP address.

Troubleshooting Netplan Issues

  • Syntax Errors: The most common issue. netplan generate will usually catch these. Pay close attention to indentation and colons. YAML is very strict.
  • No Connectivity After apply: If you didn't use netplan try and lost connectivity, you'll need console access to revert the changes. Edit the Netplan file, correct the error, or restore your .bak file, and sudo netplan apply again.
  • Checking Logs: For deeper issues, check the logs of the Netplan backend:
    • For renderer: networkd: journalctl -u systemd-networkd
    • For renderer: NetworkManager: journalctl -u NetworkManager
    • You can also check general Netplan logs: journalctl -u netplan-networkd-wait-online.service (for networkd) or journalctl -u netplan-wpa@.service (for Wi-Fi).
  • Incorrect Gateway IP: Double-check that the gateway4 address is correct and belongs to the same subnet as your interface's IP address.
  • Firewall: Ensure no firewall rules (e.g., UFW) are blocking traffic to or from your new gateway.

By carefully following these steps and understanding the nuances of Netplan, you can confidently and permanently change your default gateway on Ubuntu 20.04, maintaining robust and reliable network connectivity for your servers and systems. This declarative approach makes network management predictable and scalable, which is invaluable in complex environments.

Method 3: Using NetworkManager (GUI and nmcli)

NetworkManager is a popular and powerful system network service primarily used on desktop Ubuntu installations, though it can also be found on some server setups. It simplifies network configuration by automatically detecting network devices, managing connections, and switching between them. NetworkManager offers both a user-friendly Graphical User Interface (GUI) and a versatile Command-Line Interface (nmcli), providing options for different user preferences and environments.

When to Use This Method

  • Ubuntu Desktop Environments: This is the default and most intuitive method for changing network settings on a graphical Ubuntu desktop.
  • Dynamic Network Environments: NetworkManager is excellent at managing connections that change frequently (e.g., laptops switching between Wi-Fi networks and wired connections).
  • Server with NetworkManager: If your server specifically uses NetworkManager (as indicated by Netplan's renderer: NetworkManager), then nmcli is the appropriate command-line tool.
  • Users Comfortable with GUI or nmcli: Provides flexibility for those who prefer visual configuration or a powerful command-line tool.

Understanding NetworkManager

NetworkManager acts as a centralized control point for network devices and connections. It stores connection profiles (configurations) and applies them dynamically. While Netplan can act as a frontend to NetworkManager, if NetworkManager is directly managing your connections (i.e., you're not solely relying on systemd-networkd through Netplan), then the GUI or nmcli commands are the direct way to configure it.

GUI Method (Ubuntu Desktop)

This is the easiest approach for desktop users.

Step 1: Access Network Settings

Click on the network icon in the top right corner of your screen (usually two arrows for wired or a Wi-Fi symbol for wireless), then select "Wired Connected" or "Wi-Fi Connected" -> "Wired Settings" or "Wi-Fi Settings." Alternatively, go to "Activities" -> search for "Settings" -> select "Network."

Step 2: Select Your Connection

In the "Network" settings panel, find your active network connection (e.g., "Wired" or your Wi-Fi network name). Click the gear icon (⚙️) next to your connection to open its configuration.

Step 3: Navigate to IPv4 or IPv6 Tab

Within the connection settings window, switch to the "IPv4" tab (for IPv4 gateway changes) or "IPv6" tab (for IPv6 gateway changes).

Step 4: Change Connection Method to Manual (if using Static IP)

If your network is currently set to "Automatic (DHCP)," it means the gateway is being assigned by your DHCP server. To manually specify a default gateway, you'll typically need to switch the "IPv4 Method" (or "IPv6 Method") from "Automatic (DHCP)" to "Manual."

  • If switching to Manual:
    1. Select "Manual" from the "IPv4 Method" dropdown.
    2. In the "Addresses" section, click "+ Add" to add your static IP address, netmask, and the new Gateway.
      • Address: Your desired static IP (e.g., 192.168.1.100)
      • Netmask: Your subnet mask in CIDR notation (e.g., 24 for 255.255.255.0)
      • Gateway: Your new default gateway IP address (e.g., 192.168.1.254)
    3. Enter your DNS servers in the "DNS" field (e.g., 8.8.8.8, 8.8.4.4), ensure "Automatic" toggle is off for DNS if you want to use custom ones.

Step 5: Apply Changes

Click the "Apply" button in the top right corner of the connection settings window. You might be prompted for your password. The network connection will likely briefly disconnect and then reconnect with the new settings.

Step 6: Verify Changes

Open a terminal and run ip route show default to confirm the default gateway. Test connectivity by pinging an external IP address (e.g., 8.8.8.8) and browsing a website.

nmcli Command-Line Interface

For server environments where a GUI is absent, or for users who prefer the command line, nmcli offers granular control over NetworkManager.

Step 1: List Network Devices and Connections

First, identify your network devices and the names of your active connections.

nmcli device status
nmcli connection show

The nmcli connection show command will list connection names (e.g., "Wired connection 1," "My Wi-Fi"). You'll use this connection name for modifications.

Step 2: Modify the Connection to Set a Static IP with New Gateway

If you want to permanently set a specific default gateway, it's usually done in conjunction with setting a static IP address.

Assume your connection name is "Wired connection 1" and you want to set IP 192.168.1.100/24, new gateway 192.168.1.254, and DNS 8.8.8.8.

sudo nmcli connection modify "Wired connection 1" \
    ipv4.method manual \
    ipv4.addresses "192.168.1.100/24" \
    ipv4.gateway "192.168.1.254" \
    ipv4.dns "8.8.8.8,8.8.4.4"
  • ipv4.method manual: Changes the IP configuration method to static.
  • ipv4.addresses: Sets the static IP address and subnet mask.
  • ipv4.gateway: Specifies the new default gateway.
  • ipv4.dns: Sets custom DNS servers.

For IPv6 Gateway:

sudo nmcli connection modify "Wired connection 1" \
    ipv6.method manual \
    ipv6.addresses "2001:db8::100/64" \
    ipv6.gateway "2001:db8::1" \
    ipv6.dns "2001:4860:4860::8888,2001:4860:4860::8844"

Step 3: Activate the Modified Connection

After modifying the connection profile, you need to bring it down and then up again (or simply activate it) for the changes to take effect.

sudo nmcli connection up "Wired connection 1"

If you're connected via SSH, this command will likely cause your session to drop. Ensure you have console access or are prepared to reconnect.

Step 4: Verify Changes

  • Check nmcli: bash nmcli connection show "Wired connection 1" | grep ipv4.gateway This will show the configured gateway.
  • Check Routing Table: bash ip route show default Confirm that the default via entry now shows your new gateway IP address.
  • Test Connectivity: Ping your new gateway IP, an external IP, and an external domain name.

Overriding DHCP Gateway (Advanced/Specific Scenarios)

Generally, if you're using ipv4.method auto (DHCP), NetworkManager will get the gateway from the DHCP server. If the DHCP server provides an incorrect gateway, the best solution is to fix the DHCP server.

However, if you need to add a specific route or override a part of the routing table while still largely relying on DHCP for the IP address, you can use nmcli to add routes. For instance, to replace the default route received via DHCP with a manually specified one, you would first need to disable the DHCP-provided default route (if NetworkManager allows, which it might not directly for the default gateway) and then add your own. This is complex and usually requires switching to a manual method for the gateway. The ipv4.gateway setting in manual mode is the most straightforward way to define a persistent default gateway via nmcli.

Troubleshooting NetworkManager

  • No Connectivity: Check ip route show default. Ensure the IP address is correct.
  • Connection Not Activating: Check journalctl -u NetworkManager for errors.
  • Conflicting Configurations: If you also have Netplan .yaml files in /etc/netplan/ configured with renderer: NetworkManager, ensure they don't conflict with direct nmcli or GUI changes. Netplan acts as a higher-level configuration for NetworkManager. If Netplan specifies settings, they will often override manual NetworkManager changes. For ultimate clarity, pick one method for persistent configuration.
  • Firewall: Always check ufw status or other firewall configurations that might be blocking traffic.

NetworkManager, whether through its intuitive GUI or the powerful nmcli command, provides a flexible and efficient way to manage your network gateway on Ubuntu systems, particularly where user interaction or dynamic network changes are common.

Advanced Considerations and Troubleshooting

Changing your default gateway can be a straightforward task, but in complex network environments or when unexpected issues arise, a deeper understanding of advanced concepts and systematic troubleshooting becomes invaluable. This section delves into these more intricate scenarios, ensuring you're well-equipped to handle them.

Multiple Network Interfaces and Gateways

Many servers and specialized workstations are equipped with multiple network interfaces. These "multi-homed" systems might connect to different physical networks, different VLANs, or even different internet service providers. In such scenarios, the concept of a single default gateway becomes more nuanced.

  • Scenarios for Multiple Interfaces:
    • Multi-homed Servers: A server acting as a router, firewall, or gateway between two internal networks, or connecting to both a private and a public network.
    • Dual-WAN Routers: A router that connects to two different ISPs for load balancing or failover, implying two potential default gateways for outbound internet traffic.
    • Network Segmentation: Different applications or services on a single server might need to use different network paths (and thus different gateways) for security or performance reasons.
  • Policy-Based Routing (ip rule, ip route table): When you have multiple default gateways available through different interfaces, the kernel needs rules to decide which gateway to use for specific traffic. This is where policy-based routing comes into play, a powerful feature of Linux's iproute2 suite. Instead of a single global routing table, you can define multiple routing tables. ip rule commands then specify which table to use based on criteria like source IP, destination IP, protocol, or even user ID. For example, you might want all traffic originating from a specific IP address on your server to exit via gateway A on interface X, while all other traffic exits via gateway B on interface Y. This is significantly more complex than a simple default gateway change and involves:
    1. Creating new routing tables (ip route add table <table_id>).
    2. Adding specific default routes (or other routes) to these tables.
    3. Creating ip rule entries to direct traffic to the appropriate table. This level of routing goes beyond simply changing the system's default gateway but illustrates how gateways are managed in advanced contexts.
  • Kernel's Gateway Selection: If you mistakenly configure multiple default routes with the same metric (cost/preference) without policy routing, the kernel will typically pick one based on internal heuristics (e.g., the order in which they were added, or the interface associated with a specific route). This is usually not desirable as it leads to unpredictable routing. Therefore, it's crucial to ensure that if you need to manage multiple gateways, you do so with a clear understanding of policy routing or by assigning different metrics to routes to establish preference. The metric parameter in ip route add or Netplan configurations (e.g., routes: - to: default via: 192.168.1.1 metric: 100) allows you to prioritize gateways; a lower metric means higher preference.

IPv6 Gateway

As IPv6 adoption grows, understanding how to configure its gateway is becoming increasingly important. While the principles are similar to IPv4, the syntax and mechanisms differ slightly.

  • Netplan (gateway6): In Netplan, you use the gateway6 parameter within your interface configuration for IPv6, just as you use gateway4 for IPv4.
  • nmcli (ipv6.gateway): With nmcli, the parameter is ipv6.gateway when modifying a connection.
  • ip -6 route: For temporary changes, you use ip -6 route instead of ip route. bash sudo ip -6 route delete default sudo ip -6 route add default via 2001:db8::1 dev enp0s3
  • Router Advertisements (RA): In many IPv6 networks, devices automatically discover their default gateway and obtain IPv6 addresses through a mechanism called Router Advertisements (RA), which is part of Stateless Address Autoconfiguration (SLAAC). In such cases, explicitly setting a gateway6 might not be necessary or could even conflict with the RA process, unless you intend to override it.

Security Implications

The default gateway is a critical security control point.

  • Untrusted Networks: Routing your traffic through an incorrect or untrusted default gateway can expose your system to eavesdropping, man-in-the-middle attacks, or redirect your traffic to malicious destinations. Always verify the authenticity and trustworthiness of your gateway IP address.
  • Firewall Considerations (UFW): After changing your default gateway, always review your firewall rules (e.g., UFW - Uncomplicated Firewall on Ubuntu). Some firewall rules might be tied to specific interfaces or IP ranges. Ensure that your new network configuration still allows necessary traffic and that unwanted traffic is still blocked. For instance, if you changed networks, your ufw rules might need to be updated to allow SSH from the new management subnet.

Common Troubleshooting Steps

Even with the best preparation, issues can arise. Here's a systematic approach to troubleshooting:

  1. Is the new gateway IP reachable?
    • ping <new_gateway_ip>: This is the first and most fundamental test. If you can't ping your gateway, it's either the wrong IP, the gateway device is down, or there's a problem with your local link (e.g., cable unplugged, interface down).
  2. Check Routing Table:
    • ip route show default: Confirm that the default route correctly points to your new gateway. Look for default via <new_gateway_ip> dev <interface>.
    • ip route show: View the full routing table. Ensure there are no conflicting default routes or other routes inadvertently directing traffic away from your intended gateway.
  3. Check Interface Status:
    • ip a show <interface_name>: Verify that your network interface is UP, has the correct IP address and subnet mask.
    • sudo ethtool <interface_name> (if applicable): Check physical link status for wired connections.
  4. Check DNS Resolution:
    • ping 8.8.8.8: If this works but ping google.com fails, your problem is DNS, not routing to the gateway. Check /etc/resolv.conf to ensure it contains valid and reachable DNS servers. Netplan and NetworkManager typically manage this file.
    • systemd-resolve --status: For systems using systemd-resolved, this provides DNS server information.
  5. Review Configuration Logs:
    • Netplan: journalctl -u systemd-networkd (for networkd renderer) or journalctl -u NetworkManager (for NetworkManager renderer). Look for errors or warnings related to your network interface or Netplan application.
    • NetworkManager: journalctl -u NetworkManager.
  6. Revert to Previous Configuration: If you encounter persistent issues, the fastest way to restore connectivity is often to revert to your last known good configuration.
    • Netplan: Restore your .bak file: sudo mv /etc/netplan/00-installer-config.yaml.bak /etc/netplan/00-installer-config.yaml then sudo netplan apply.
    • ip route (Temporary): A simple reboot will clear any ip route changes.
  7. Physical Connection: A simple check, but often overlooked: is the Ethernet cable plugged in properly? Are there any lights on the network card or router indicating a link?

Naturally Integrating APIPark

In environments where network architectures become complex, especially for servers managing many services or APIs, ensuring proper traffic routing is paramount. While setting the correct system-level default gateway handles fundamental outbound internet traffic, modern applications, particularly those leveraging AI and microservices, require a more specialized kind of gateway for internal and external API traffic management.

When discussing the intricacies of network routing and the management of various services, it becomes clear that foundational network configuration, such as correctly setting the default gateway, is just the beginning. For businesses and developers dealing with an ever-growing ecosystem of application programming interfaces, particularly those incorporating AI models, an advanced API management solution is essential. This is precisely where APIPark fits into the discussion.

While changing a system's default gateway ensures basic network connectivity for your Ubuntu server, an AI gateway like ApiPark operates at a higher, application-specific level. APIPark, an open-source AI gateway and API Management Platform, is designed to help developers and enterprises manage, integrate, and deploy AI and REST services with ease. It stands as a sophisticated layer that sits in front of your diverse API services, acting as a single entry point for all API traffic. Regardless of your underlying network infrastructure's default gateway configuration, APIPark intelligently manages the flow, security, and integration of API requests. It standardizes API invocation formats across over 100 AI models, handles authentication, rate limiting, and ensures efficient routing of API requests to the correct backend service. This robust platform complements the foundational network setup you've just configured by providing a unified and secure way to expose, consume, and monitor your APIs, abstracting away the complexities of individual service deployments. Thus, while your server's default gateway directs its general network traffic, APIPark specifically architects the intricate flow of your digital services, enhancing efficiency, security, and observability across your API landscape.

By systematically approaching troubleshooting and understanding these advanced considerations, you can maintain a robust and resilient network infrastructure on your Ubuntu 20.04 systems.

Table: Comparison of Default Gateway Configuration Methods

To provide a clear overview and help you choose the most appropriate method for your specific needs, here's a comparison table summarizing the key characteristics of each approach discussed for changing the default gateway on Ubuntu 20.04.

Feature/Method Temporary (ip route) Permanent (Netplan) Permanent (NetworkManager GUI/nmcli)
Persistence No (resets on reboot, network service restart, or interface down/up) Yes (persists across reboots and service restarts) Yes (persists across reboots and service restarts)
Use Case Quick testing, debugging, temporary rerouting, immediate diagnostic checks without commitment. Server configuration, cloud instances, automated deployments, static IP assignments, production environments requiring reliability. Desktop environments, laptops, dynamic network changes, user-friendly setup, servers where NetworkManager is explicitly used.
Complexity Low (simple command-line syntax) Medium (YAML syntax sensitivity, understanding Netplan flow) Low (GUI), Medium (nmcli command-line syntax can be verbose)
Configuration File None (runtime kernel change) /etc/netplan/*.yaml (YAML format) /etc/NetworkManager/system-connections/* (key-value pair config files)
Primary Command(s) ip route add/delete netplan generate, netplan try, netplan apply GUI settings panel, nmcli connection modify, nmcli connection up
Risk of Lockout Low (easy to revert by reboot or re-adding old route; temporary impact) Medium (syntax errors can break network; netplan try mitigates risk) Low to Medium (GUI is generally safer; nmcli requires care, especially on remote systems)
DHCP Compatibility Can be used post-DHCP to override or add specific routes, but not for persistent default gateway changes. Best with static IP; DHCP usually provides the gateway automatically. Explicitly overriding DHCP gateway is generally discouraged. Can be used with static IP; DHCP usually provides the gateway automatically. Explicitly overriding DHCP gateway is generally discouraged, fix DHCP server instead.
Default Ubuntu Install Available on all Ubuntu installations (CLI utility) Default declarative network configuration system for Ubuntu 20.04+ (CLI utility) Default network manager for Ubuntu Desktop installations (GUI and CLI nmcli)
Notes Ideal for quick, non-disruptive tests and diagnostics. Essential for understanding basic routing. Declarative approach, powerful for complex and consistent network setups. Requires careful YAML syntax. User-friendly for desktops, offers good balance of control and ease of use. Can coexist with Netplan if renderer: NetworkManager is used.

This table serves as a quick reference to guide your decision-making process, ensuring you select the most appropriate method for your specific requirements when changing the default gateway on your Ubuntu 20.04 system.

Conclusion: Mastering Your Network's Front Door

The default gateway is far more than just an IP address; it is the crucial pivot point where your local network connects to the vast global internet. It is the unseen architect that ensures your data packets find their way out to remote destinations and that external information can flow back to your Ubuntu machine. Understanding its function and, more importantly, mastering the techniques to configure it, is a foundational skill for anyone managing an Ubuntu 20.04 system, whether it's a personal workstation or a critical production server.

Throughout this comprehensive guide, we've dissected the anatomy of network communication, from the fundamental concepts of IP addressing and routing tables to the specific tools Ubuntu provides for network management. We explored the temporary yet invaluable ip route command, ideal for quick diagnostics and transient routing adjustments. We then delved into Netplan, Ubuntu's declarative and robust system for making permanent, production-grade network configurations, emphasizing its power and the critical need for precise YAML syntax. Finally, we covered NetworkManager, the versatile solution for desktop users and environments demanding dynamic network handling, accessible via both its intuitive GUI and the powerful nmcli command.

We've stressed the paramount importance of prerequisites and precautions: always gather current network information, back up existing configurations, and ensure you have secure access methods to prevent being locked out of your system. We also touched upon advanced considerations like multiple network interfaces, IPv6 gateway configuration, and the significant security implications of routing decisions. Crucially, we highlighted the broader context of network management by naturally integrating APIPark, demonstrating how specialized solutions complement foundational network configurations to manage complex API traffic efficiently and securely.

Changing your default gateway is a powerful act of network control. It empowers you to troubleshoot connectivity issues, reconfigure your network infrastructure, optimize traffic flow, and ensure your system is always pointing to the correct "front door" to the wider digital world. Approach this task with diligence, verify every step, and embrace the learning process. By doing so, you not only solve an immediate problem but also deepen your understanding of the intricate dance of data across your network, transforming you from a mere user into a confident and capable network administrator. With the knowledge gained from this guide, you are now well-equipped to confidently navigate and command the very arteries of your Ubuntu 20.04 system's connectivity.

Frequently Asked Questions (FAQs)

Here are five frequently asked questions related to changing the default gateway on Ubuntu 20.04, along with their answers:

1. Why would I need to change my default gateway on Ubuntu 20.04? There are several common reasons for changing your default gateway. You might need to troubleshoot network connectivity issues where your current gateway is unresponsive or misconfigured. It's often necessary after installing a new router, modifying your network's subnet, or integrating your Ubuntu machine into a different network segment. For servers, you might change it to route specific traffic through a different path for security, performance, or to utilize a new network device. In advanced setups, testing alternative network paths or recovering from a faulty gateway can also necessitate a temporary change.

2. What is the difference between temporarily and permanently changing the default gateway? Temporarily changing the default gateway using the ip route command (e.g., sudo ip route add default via <new_gateway_ip> dev <interface>) only modifies the kernel's active routing table in memory. These changes are immediate but are lost upon a system reboot, network service restart, or when the associated network interface goes down. This method is ideal for quick tests or diagnostics. Permanently changing the default gateway, typically done via Netplan (by editing /etc/netplan/*.yaml files) or NetworkManager (through GUI or nmcli), involves modifying configuration files on your system. These changes persist across reboots and service restarts, ensuring your network setup is consistent and reliable for long-term use, especially on servers.

3. What critical information should I gather before attempting to change my default gateway? Before making any changes, you must gather essential network information to ensure a smooth transition and prevent network lockout. This includes: * Your current IP address and subnet mask (ip a). * Your current default gateway IP address (ip route show default). * The exact name of the network interface you're configuring (e.g., enp0s3, wlp2s0). * The new default gateway IP address you intend to use. Crucially, this new gateway must be reachable on your local network segment and typically belongs to the same subnet as your machine's IP address. It's also highly recommended to back up your current Netplan configuration files (e.g., sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak).

4. How can I verify that my default gateway change was successful? After applying the new gateway configuration, verification is crucial. 1. Check the routing table: Run ip route show default to confirm the default route now points to your new gateway IP. 2. Ping the new gateway: Execute ping <new_gateway_ip> to ensure your machine can communicate with the gateway itself. 3. Ping an external IP address: Try ping 8.8.8.8 (Google's DNS) to confirm outbound internet connectivity. 4. Traceroute to an external domain: Use traceroute google.com (or any other external domain). The first hop in the traceroute output should be your new default gateway, confirming traffic is flowing through it. If you can ping external IPs but not domain names, your DNS servers might need to be updated.

5. I changed my default gateway, and now I've lost all network connectivity. What should I do? If you lose connectivity, especially on a remote server, immediate action is needed. 1. If using netplan try: Do nothing. The 120-second timer will expire, and Netplan will automatically revert to your previous working configuration, restoring connectivity. This is why netplan try is strongly recommended. 2. If you used netplan apply or ip route directly (without console access): You'll need console access (physical keyboard/monitor, or hypervisor console for VMs) to regain control. Once you have console access, review your Netplan .yaml file for syntax errors or incorrect IP addresses. You can restore your backup file (sudo mv /etc/netplan/00-installer-config.yaml.bak /etc/netplan/00-installer-config.yaml) and then run sudo netplan apply to revert. For temporary ip route changes, a simple reboot often clears the custom routes, or you can manually delete the incorrect route and add the correct one. Always double-check IP addresses, subnet masks, and YAML indentation before applying changes.

🚀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