Netplan is Ubuntu’s default network configuration tool, using simple YAML files to manage network interfaces on modern releases (17.10 and later). This guide walks you through configuring static IPs, DHCP, and other common settings, then applying them safely. You’ll need a terminal with sudo access and a basic understanding of your network’s IP scheme.
What You’ll Need
- A system running Ubuntu 17.10 or newer (20.04, 22.04, 24.04, etc.)
- Sudo or root access to edit files and run commands
- Knowledge of your network: desired static IP, subnet mask, gateway, and DNS servers
- The name of your network interface (e.g., eth0, ens33, wlp2s0) – find it with
ip linkorls /sys/class/net
Step-by-Step
- Identify your network interface. Run
ip linkorls /sys/class/netto list interfaces. Note the one you want to configure (often named likeens33,eth0, orwlp2s0). - Back up the current Netplan configuration. Netplan configs live in
/etc/netplan/. Copy the existing YAML file (e.g.,sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak). If the directory is empty, you’ll create a new file. - Open the config file with a text editor. Use
sudo nano /etc/netplan/01-netcfg.yaml(or the actual filename). If no file exists, create one with that name. - Write the YAML configuration. Start with the required header and specify the renderer (networkd is standard for servers, NetworkManager for desktop). For a static IP, use a structure like this:
network: version: 2 renderer: networkd ethernets: ens33: dhcp4: no addresses: - 192.168.1.100/24 routes: - to: default via: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4]For DHCP, simply set
dhcp4: yesand omit addresses/routes/nameservers. - Check the indentation carefully. YAML is strict: use spaces, not tabs. The example above uses two-space indentation. A single misaligned line will cause an error.
- Test the configuration before applying. Run
sudo netplan try. This applies the config temporarily and waits for your confirmation (default 120 seconds). If you lose connectivity, it automatically reverts. Press Enter to accept or wait for rollback. - Apply the configuration permanently. If
netplan trysucceeded, runsudo netplan applyto make it active immediately. - Verify the settings. Check with
ip addr show ens33(replace interface name) andip routeto confirm IP and gateway. Test DNS withping -c 4 google.com.
Common Mistakes
- Incorrect YAML indentation: Using tabs or inconsistent spaces triggers a parse error. Always use spaces and align lists properly.
- Wrong interface name: Using
eth0when your system usesens33will result in no changes. Double-check withip link. - Missing gateway or DNS: Without a default route, you can’t reach the internet. Without DNS, hostnames won’t resolve.
- Forgetting to set
dhcp4: no: If you leave DHCP enabled while also specifying a static IP, the system may still get a DHCP address. - Editing the wrong file: There may be multiple YAML files in
/etc/netplan/. Netplan merges them; editing the wrong one can cause conflicts. Check which files exist and edit the one that defines your interface.
Tips
- Use
sudo netplan generateto check for syntax errors without applying changes. It will report any issues. - For wireless connections, use
wifis:instead ofethernets:and include anaccess-points:block with the SSID and password. - If you’re on a desktop with NetworkManager, set
renderer: NetworkManagerto avoid conflicts. - To add multiple IP addresses, list them under
addresses:with each on a new line. - Use
optional: truefor interfaces that might not be present at boot (like USB adapters) to prevent boot delays.
Troubleshooting
- “Invalid YAML” error: Re-check indentation and colons. Run
sudo netplan generateto get a more specific error message. - No network after apply: If you’re connected via SSH, you’ll be disconnected. Use the console (physical or virtual) to run
sudo netplan tryagain and let it time out to roll back. Then fix the config. - Interface not found: The name in the config doesn’t match any real interface. Run
ip linkand correct the name. - Can ping IP but not hostname: DNS is misconfigured. Check
nameserversin the YAML and test withdig google.comornslookup. - Gateway unreachable: Verify the gateway IP is correct and on the same subnet as your static IP. Check with
ip routeand try pinging the gateway. - Changes not persisting after reboot: Ensure you ran
sudo netplan apply(not justtry). Also confirm the YAML file is in/etc/netplan/and has correct permissions (usually 600).
Frequently Asked Questions
Can I use Netplan on older Ubuntu versions?
Netplan is default only from 17.10 onward. On older versions, use /etc/network/interfaces or install netplan manually (not recommended).
How do I switch from DHCP to a static IP?
Edit the YAML file, set dhcp4: no, add your addresses, routes, and nameservers, then run sudo netplan apply.
What is the difference between netplan try and netplan apply?
try applies temporarily and rolls back after 120 seconds if you don’t confirm. apply makes changes permanent immediately. Always use try first when working remotely.
Why does my config file have a different name?
Netplan filenames are arbitrary; they just need to end in .yaml. Common names include 01-netcfg.yaml, 50-cloud-init.yaml, or 99-config.yaml. Use whatever exists.
How do I configure a VLAN or bond?
Netplan supports these via vlans: and bonds: sections. For example, a VLAN 10 on eth0: vlans: { vlan10: { id: 10, link: eth0 } }. Refer to the official Netplan documentation for full syntax.
Can I use Netplan with NetworkManager?
Yes, set renderer: NetworkManager at the top level. This is common on desktop installations where NetworkManager manages Wi-Fi and other connections.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Alexa App Stuck on Setup
- Android Camera for 7 Office Tasks: Step-by-Step
- Pair Phone to Pioneer Stereo After Bluetooth Reset
- Fix Windows Not Saving Remote Desktop Credentials
- Fix Error 0x8007025d in Windows 10
- Essential Tips for macOS Users Switching to Windows