Routing Traffic: Static IP vs. DHCP on Ubuntu 22.04

Abstract: Resolve Ubuntu 22.04 network configuration by assigning static IPs or enabling DHCP via Netplan YAML files for wired and wireless interfaces.

Created: 2026-09-16 by

Ubuntu 22.04 uses Netplan to configure network interfaces, allowing you to assign static IP addresses or obtain them via DHCP for both wired and wireless connections. This guide explains how to set up these configurations using the netplan YAML files and apply changes without disrupting active sessions.

Understanding Ubuntu Network Configuration

Modern Ubuntu versions have moved away from the traditional /etc/network/interfaces file in favor of Netplan, a configuration utility that generates backend configurations for either systemd-networkd or NetworkManager. When you edit your network settings, you are primarily modifying YAML files located in the /etc/netplan/ directory. These files define the state of your network interfaces, such as eno1 for Ethernet and wls4 for Wi-Fi. It is crucial to understand that while the title mentions "routing," this process is fundamentally about assigning IP addresses (Layer 3) rather than configuring dynamic routing protocols like OSPF or BGP. For users migrating from older Ubuntu releases or other Linux distributions, understanding this shift is vital to avoid confusion with deprecated tools. If you are managing multiple virtual machines, you might also find it helpful to review How to Configure a Traffic Route from VM1 through Host to VM2 to understand broader traffic flow concepts beyond simple interface assignment.

Configuring a Static IP on Wired Interface

To assign a static IP address to your wired connection, typically identified as eno1, you need to edit the appropriate Netplan configuration file. Open a terminal and use a text editor like nano or vim to modify the file in /etc/netplan/. The filename often ends with .yaml or .yml. You must ensure the indentation is correct, as YAML is sensitive to whitespace. Use two spaces for each level of nesting; do not use tabs. Below is an example configuration for a static setup:
network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: no
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 1.1.1.1
In this snippet, dhcp4: no disables automatic IP assignment. The addresses field specifies the IP and subnet mask. The routes section defines the default gateway, which is essential for internet access. Finally, nameservers ensures DNS resolution works correctly. After saving the file, you can apply the changes immediately by running sudo netplan apply. If there are syntax errors, this command will report them, allowing you to fix the file before breaking connectivity.

Setting Up DHCP for Wireless Interface

Wireless interfaces, such as wls4, often benefit from Dynamic Host Configuration Protocol (DHCP) because they may connect to various networks with different IP schemes. Configuring DHCP simplifies mobility and reduces manual intervention. To enable DHCP for your wireless adapter, you can modify the same Netplan configuration file or create a separate one if your system structure supports it. Here is how the configuration block should look for wls4:
  wifis:
    wls4:
      dhcp4: yes
      dhcp6: no
      access-points:
        "Your_SSID_Name":
          password: "your_wifi_password"
This configuration tells the system to automatically request an IP address from the connected router. The access-points section handles the authentication details for your Wi-Fi network. Note that dhcp6: no is included to disable IPv6 if it is not required, which can prevent potential connectivity issues in some environments. Once saved, run sudo netplan apply again. The system will disconnect and reconnect to the wireless network, obtaining a new IP address from the DHCP server.

Distinguishing Between IP Assignment and Routing

It is important to clarify a common misconception: configuring a static IP or enabling DHCP is not the same as setting up dynamic routing. Dynamic routing involves protocols that automatically update routing tables based on network topology changes. In contrast, the configurations above are static. They define how your machine connects to its local network and the internet. If you need to add specific static routes for non-default paths, you can include additional entries in the routes section of your Netplan file, similar to the default route shown earlier. For more complex scenarios involving internal network segmentation, refer to Troubleshooting WireGuard Client-to-Client Communication Issues to see how tunneling affects routing decisions.

Troubleshooting Common Issues

After applying Netplan configurations, you may encounter connectivity problems. First, verify that the YAML syntax is valid. A single misplaced space can cause the entire configuration to fail. You can check for syntax errors by running sudo netplan try, which applies the configuration but reverts it after 120 seconds if you do not confirm it works. This safety feature prevents lockouts. If the wired interface fails to connect, check the physical link status with ip link show eno1. Ensure the interface is in the UP state. For wireless issues, confirm that the SSID and password are correct and that the radio is enabled. You can also check the system logs using journalctl -u systemd-networkd to see detailed error messages related to network initialization. If you suspect a deeper issue with your virtual machine's networking, especially in KVM environments, consulting resources on Ubuntu 22.04 VM on KVM/virt-manager Not Connecting to Internet might provide insights into hypervisor-level restrictions.

Verifying Your Configuration

Once your settings are applied, verify that they are active. Use the ip addr show command to list all IP addresses assigned to your interfaces. Confirm that eno1 has the static IP you defined and that wls4 has received a DHCP lease. Additionally, test connectivity by pinging an external host, such as ping 8.8.8.8. If ping fails, check your firewall rules and ensure that the default route is present using ip route show. This final step ensures that your network stack is correctly configured to handle traffic.

Frequently Asked Questions

Can I mix static and DHCP configurations in the same Netplan file?

Yes, you can define both wired and wireless interfaces with different methods in a single YAML file. Each interface is defined under its own key (e.g., ethernets vs wifis), allowing independent configuration. This approach keeps all network settings centralized and easier to manage.

What happens if I make a typo in the Netplan YAML file?

If there is a syntax error, netplan apply will fail and display an error message indicating the line number and nature of the problem. The previous configuration remains active until a successful apply occurs, preventing accidental loss of connectivity. Always use netplan try to safely test changes.

Does Netplan support IPv6 out of the box?

Yes, Netplan supports IPv6 configuration. You can enable it by setting dhcp6: yes or assigning static IPv6 addresses in the addresses list. However, many users disable it (dhcp6: no) if their network infrastructure does not fully support IPv6 to avoid potential conflicts or delays in connection establishment.

How do I revert to the default network configuration?

To revert to defaults, you can delete or comment out the custom settings in the Netplan YAML files and run sudo netplan generate followed by sudo netplan apply. This regenerates the backend configuration based on the remaining active settings. Be cautious, as this may remove specific static routes or DNS settings you intentionally added.

Is it safe to edit Netplan files while connected remotely?

It is risky to edit Netplan files via SSH because a misconfiguration can lock you out of the server. It is recommended to use netplan try, which provides a rollback window. Alternatively, configure a console access method or have physical access available before making significant network changes to ensure you can recover the system if needed.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More