
September 11, 2026
12 min read
By Kokil Thapa | Last reviewed: September 2026
A misconfigured network interface is one of the fastest ways to lock yourself out of a remote Ubuntu server. This Ubuntu network configuration guide walks you through the tools that actually matter on modern LTS releases: Netplan as the front door, NetworkManager or systemd-networkd as the renderer, and the diagnostic commands you reach for when DNS or routing breaks after a deploy. If you run production web stacks on Ubuntu, the steps here mirror what I use before pointing Apache or Nginx at a new VPS. Start with the Ubuntu server setup guide if the machine is still fresh from the installer.
/etc/netplan/. Edit the file, run sudo netplan try, then sudo netplan apply. Netplan passes configuration to NetworkManager or systemd-networkd depending on your renderer choice.How does Ubuntu handle network configuration in 2026?
Ubuntu Server switched to Netplan as the default network abstraction layer starting with 18.04. The pattern still holds on Ubuntu 22.04 and 24.04 LTS in 2026. You rarely touch /etc/network/interfaces on new installs anymore.
Netplan reads YAML from /etc/netplan/*.yaml. It generates backend configuration for one of two renderers:
- NetworkManager — common on desktop and some cloud images; good when you want
nmclior a GUI. - systemd-networkd — the default on many Ubuntu Server images; lean, predictable, and what I prefer on headless VPS boxes running Laravel or WordPress.
Before changing anything, identify your renderer:
ls /etc/netplan/
networkctl status
nmcli general status 2>/dev/null || echo "NetworkManager not active" Cloud-init may own the first Netplan file on AWS, DigitalOcean, or Hetzner droplets. Look for a header comment mentioning cloud-init. Manual edits can be overwritten on reboot unless you disable cloud-init networking or edit the correct persistent file. That surprise has burned more than one Linux server administration engagement.
How do you set a static IP address with Netplan on Ubuntu?
Static addressing is standard on production web servers. DHCP works for labs. Production boxes need fixed IPs for firewall rules, DNS A records, and SSL certificate validation.
Step 1: Find the interface name
ip -br link show
ip -br addr show Common names are eth0, ens3, or enp0s3. Use the name tied to your primary NIC, not lo.
Step 2: Write the Netplan file
Create or edit /etc/netplan/01-netcfg.yaml. YAML is whitespace-sensitive. Use spaces, not tabs. A broken indent takes the whole interface offline.
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
search:
- lan.local Replace ens3, the address, gateway, and DNS values with your provider's details. VPS panels usually list gateway and netmask in the control UI.
Step 3: Validate and apply safely
Never run netplan apply blindly over SSH. Use the built-in rollback timer first:
- Run
sudo netplan generateto catch syntax errors. - Run
sudo netplan try— you have 120 seconds to confirm or the old config restores. - Press Enter when connectivity holds, or wait for automatic rollback.
- Run
sudo netplan applyonce you are confident.
Verify with ip addr show ens3 and ip route show default. Ping the gateway, then an external host like 1.1.1.1.
On sister sites I deploy with Deployer 7, a bad Netplan edit during off-hours maintenance is worse than a failed code release. Always keep provider console access open. That out-of-band path has saved me more than once.
What is the difference between Netplan, NetworkManager, and systemd-networkd?
You do not pick all three independently. Netplan is the configuration layer. The renderer does the heavy lifting. Knowing which is active prevents editing the wrong files.
| Tool | Role | Best for | Config location |
|---|---|---|---|
| Netplan | YAML abstraction; generates backend configs | All modern Ubuntu Server and Desktop | /etc/netplan/*.yaml |
| systemd-networkd | Lightweight network daemon | Headless servers, containers, VPS | /run/systemd/network/ (generated) |
| NetworkManager | Full-featured connection manager | Desktops, laptops, Wi-Fi, VPN | /etc/NetworkManager/ |
Switching renderers requires changing the renderer: key in Netplan and re-applying. Do not hand-edit generated files under /run/ — they disappear on reboot.
For quick one-off changes on a NetworkManager host, nmcli still works:
nmcli connection show
nmcli connection modify "Wired connection 1" ipv4.addresses 192.168.1.60/24
nmcli connection modify "Wired connection 1" ipv4.gateway 192.168.1.1
nmcli connection modify "Wired connection 1" ipv4.method manual
nmcli connection up "Wired connection 1" On servers where I install Nginx on Ubuntu or stack PHP-FPM behind Apache, I stick with Netplan plus networkd. Fewer moving parts means fewer midnight pages.
How do you configure DNS and hostnames on Ubuntu?
DNS misconfiguration looks like a dead website when the web server is fine. Browsers fail, but curl -I http://127.0.0.1 still returns 200. Separate name resolution from application issues early.
Netplan DNS settings
The nameservers block in Netplan feeds systemd-resolved on most Ubuntu Server installs. After applying Netplan, check the effective resolver:
resolvectl status
resolvectl query kokil.com.np For split DNS on internal LANs, add search domains under nameservers.search. Keep the list short. Long search paths slow every lookup.
/etc/hosts for local overrides
127.0.0.1 localhost
192.168.1.50 staging.myapp.local Use /etc/hosts for local staging hostnames before public DNS propagates. Do not rely on it for production. It does not scale across multiple servers.
Hostname and FQDN
sudo hostnamectl set-hostname web01
hostnamectl status Set the FQDN in Netplan or via hostnamectl. Mail servers and SSL workflows care about the FQDN matching your PTR and certificate CN. After DNS changes, test with dig +short yourdomain.com A from an external resolver. The regex tester helps validate log patterns when debugging resolver timeouts in application logs.
Official reference: the Netplan YAML reference documents every key. Cross-check against the Ubuntu Server networking documentation when upgrading between LTS releases.
How do you configure multiple IPs, bonds, and VLANs?
Single-NIC static IP covers most small VPS workloads. Larger setups need extra Netplan stanzas.
Secondary IP on one interface
network:
version: 2
ethernets:
ens3:
dhcp4: false
addresses:
- 192.168.1.50/24
- 192.168.1.51/24
routes:
- to: default
via: 192.168.1.1 VLAN tagging
network:
version: 2
vlans:
vlan100:
id: 100
link: ens3
addresses:
- 10.10.100.5/24 Link aggregation (bond)
Bonding needs switch support. A typical active-backup bond:
network:
version: 2
ethernets:
ens3: {}
ens4: {}
bonds:
bond0:
interfaces: [ens3, ens4]
parameters:
mode: active-backup
primary: ens3
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1 I have only needed bonds on dedicated hardware. Cloud VPS instances almost always expose a single virtual NIC. Keep the config simple unless your provider documents otherwise.
How do you harden and troubleshoot Ubuntu networking?
Network config and firewall rules are two sides of the same coin. UFW sits on top of netfilter. Open ports only after the interface carries traffic correctly.
UFW basics after networking works
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status verbose Pair this with the fail2ban configuration guide and broader Ubuntu security hardening guide. On production Laravel hosts, I open 443 and 22 only. Database ports stay on private interfaces or VPN tunnels.
Diagnostic command checklist
ip addr— addresses and interface stateip route— default gateway and static routesss -tulpn— listening sockets and owning processesping -c 3 GATEWAY— Layer 3 to the routerping -c 3 1.1.1.1— external routing without DNSdig example.com— resolver and record answerstraceroute 1.1.1.1— path diagnosticsjournalctl -u systemd-networkd -b— networkd logs
If ping to IP works but hostnames fail, suspect DNS — not the cable, not Nginx. If nothing leaves the box, check gateway and netmask first.
Common production mistakes
Wrong netmask is the classic SSH lockout cause. A /24 written as /32 removes the local subnet route. The server cannot reach its gateway.
Duplicate address entries across two Netplan files create unpredictable merges. Keep one authoritative file, or use numeric prefixes like 00-cloud-init.yaml and 99-custom.yaml with clear intent.
Forgetting to open port 22 in UFW after enabling the firewall blocks SSH even when Netplan is perfect. Always allow OpenSSH before ufw enable.
MTU mismatches on PPPoE or some VPN tunnels cause partial connectivity — small packets work, large TLS handshakes hang. Test with ping -M do -s 1472 GATEWAY and lower MTU in Netplan if needed:
network:
version: 2
ethernets:
ens3:
mtu: 1492
dhcp4: true After networking is stable, continue the stack build: install MySQL on Ubuntu, then install PHP, then harden with server hardening for Ubuntu web servers. The same order applies whether you host a WooCommerce shop or a legal-tech portal like Notary Kathmandu.
How does Ubuntu network configuration fit a full deployment workflow?
Networking is step one on every VPS I provision. The sequence below matches deployments for sites like Adventure Third Pole Trek and sister legal-tech properties on shared EC2 infrastructure.
- Apply static IP or confirm DHCP reservation with the hoster via domain and hosting setup.
- Set hostname and DNS A record; wait for propagation before requesting Let's Encrypt.
- Enable UFW and fail2ban before exposing any application port.
- Install the web stack — Nginx, PHP 8.3 or 8.4, MySQL 8.4 LTS or MySQL 9.7 where supported.
- Configure monitoring for interface errors and packet loss via the Ubuntu server monitoring guide.
- Document the Netplan file in your runbook so the next developer is not guessing gateway values.
Cloud-init on first boot may set a dynamic address. Snapshot the working Netplan file into your infrastructure repo. Treat it like application code. For Symfony or Laravel deploys, see the Symfony deployment on Ubuntu VPS walkthrough — the network steps are identical at the OS layer.
If you manage several Ubuntu boxes, standardise on one renderer per environment. Mixing NetworkManager on staging and networkd on production invites "works on my server" Netplan drift. The essential Ubuntu terminal commands cheat sheet complements the networking commands listed here.
Need hands-on help wiring a new VPS, migrating DNS, or fixing a post-deploy outage? Support and maintenance covers ongoing server work. For greenfield apps, web development services include full-stack delivery from network layer to application code. Read more about my background on the about page.
Key Takeaways
- On Ubuntu 22.04 and 24.04 LTS, edit
/etc/netplan/*.yaml— not legacy/etc/network/interfaces. - Always run
sudo netplan tryover SSH; the 120-second rollback prevents permanent lockouts. - Identify your renderer (networkd vs NetworkManager) before troubleshooting the wrong config path.
- Fix gateway and netmask before debugging Nginx, PHP, or Laravel — ping IP addresses before hostnames.
- Bind MySQL and Redis to localhost; expose only 22 and 443 on the public interface through UFW.
- Store working Netplan YAML in version control alongside your Deployer or CI/CD configuration.
People Also Ask
Where is the network config file in Ubuntu 24.04?
Ubuntu 24.04 LTS stores network settings in YAML files under /etc/netplan/. The exact filename varies — common examples are 50-cloud-init.yaml or 01-netcfg.yaml. List the directory with ls /etc/netplan/ and edit the file that defines your primary interface.
How do I restart networking on Ubuntu without rebooting?
Run sudo netplan apply after validating with sudo netplan try. For NetworkManager hosts, use sudo systemctl restart NetworkManager. For systemd-networkd, use sudo networkctl reload or restart the unit with sudo systemctl restart systemd-networkd.
Why does my Ubuntu server have no internet after setting a static IP?
The usual causes are a wrong default gateway, an incorrect CIDR prefix, or a missing route stanza in Netplan. Ping your gateway IP first. If that fails, the problem is local routing — not DNS or your upstream provider. Compare your YAML against the network details in your VPS control panel.
Should I use DHCP or static IP on an Ubuntu web server?
Use a static IP or a DHCP reservation tied to the server's MAC address on any production web host. DNS A records, firewall allow lists, and SSL validation all assume the address stays fixed. DHCP without reservation risks address changes after reboot or lease renewal.
Build on a solid network foundation
A reliable Ubuntu network configuration guide is not glamorous work. It is the difference between a clean backup and monitoring setup and a midnight console session because SSH died mid-edit. Master Netplan, test with netplan try, verify routing before DNS, and lock down UFW once traffic flows. That foundation supports everything above it — from a single WordPress site to a multi-app EC2 host running several legal-tech properties.
If you want someone to provision, harden, and maintain your Ubuntu servers alongside the application layer, contact us to discuss your project. Solid networking is not optional; it is the floor everything else stands on.
Frequently Asked Questions
0 Comments
Leave a comment
Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

