Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Ubuntu Network Configuration Guide

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.

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 nmcli or 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.

Ubuntu Network Stack/etc/netplan/*.yamlNetplan front endnetplan generatesystemd-networkdServer defaultNetworkManagerDesktop / cloudKernel: ip link, routing table, DNS resolver
Ubuntu network configuration guide — Netplan YAML is the single entry point on modern LTS releases

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:

  1. Run sudo netplan generate to catch syntax errors.
  2. Run sudo netplan try — you have 120 seconds to confirm or the old config restores.
  3. Press Enter when connectivity holds, or wait for automatic rollback.
  4. Run sudo netplan apply once 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.

ToolRoleBest forConfig location
NetplanYAML abstraction; generates backend configsAll modern Ubuntu Server and Desktop/etc/netplan/*.yaml
systemd-networkdLightweight network daemonHeadless servers, containers, VPS/run/systemd/network/ (generated)
NetworkManagerFull-featured connection managerDesktops, 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.

Static IP Setup FlowFind NICip -br linkEdit YAML/etc/netplan/netplan try120s rollbackApplyVerify routesping gateway + DNSSSH lockout riskKeep provider console open during netplan tryWrong gateway = no return path to your IP
Safe static IP workflow — always use netplan try before a permanent apply on remote Ubuntu servers

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

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 state
  • ip route — default gateway and static routes
  • ss -tulpn — listening sockets and owning processes
  • ping -c 3 GATEWAY — Layer 3 to the router
  • ping -c 3 1.1.1.1 — external routing without DNS
  • dig example.com — resolver and record answers
  • traceroute 1.1.1.1 — path diagnostics
  • journalctl -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.

Connectivity TroubleshootingNo connectivity?Link down?ip link set upIP correct?Check netplan YAMLGateway ping?Fix routesDNS resolves?nameservers blockApp layer: Nginx, PHP-FPM, UFW
Ubuntu network troubleshooting — work down from link layer to DNS before blaming the web stack

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.

Production Web Server LayoutInternetClientsUFW22, 443 openUbuntu VPSStatic IP via Netplanens3 203.0.113.10/24Internal services (localhost only)Nginx :443PHP-FPMMySQL :3306RedisDB and cache bound to 127.0.0.1 — not public NICLaravel / WordPress apps on same host
Typical production layout — public NIC carries HTTPS while database services stay on localhost

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.

  1. Apply static IP or confirm DHCP reservation with the hoster via domain and hosting setup.
  2. Set hostname and DNS A record; wait for propagation before requesting Let's Encrypt.
  3. Enable UFW and fail2ban before exposing any application port.
  4. Install the web stack — Nginx, PHP 8.3 or 8.4, MySQL 8.4 LTS or MySQL 9.7 where supported.
  5. Configure monitoring for interface errors and packet loss via the Ubuntu server monitoring guide.
  6. 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 try over 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

Network settings on Ubuntu 24.04 LTS live in YAML files under /etc/netplan/, often named 50-cloud-init.yaml or 01-netcfg.yaml. Run ls /etc/netplan/ to list them.

After validating with sudo netplan try, run sudo netplan apply. On NetworkManager hosts use sudo systemctl restart NetworkManager; on systemd-networkd use sudo networkctl reload or restart systemd-networkd.

Use a static IP or a DHCP reservation tied to the server MAC on production web hosts. DNS A records, firewalls, and SSL validation all assume a fixed address.

Ubuntu Server uses Netplan as the default abstraction layer starting from 18.04, and the pattern still holds on 22.04 and 24.04 LTS in 2026. You edit YAML under /etc/netplan/, and Netplan generates backend configuration for either NetworkManager or systemd-networkd depending on the renderer key. Legacy /etc/network/interfaces is rarely touched on new installs. Before changing anything, identify your active renderer with networkctl status or nmcli general status so you are not troubleshooting the wrong config path.

Find your interface with ip -br link show, then create or edit /etc/netplan/01-netcfg.yaml using spaces, not tabs. Set dhcp4: false, add your address with the correct CIDR prefix, define a default route via your gateway, and list nameservers. Run sudo netplan generate to catch syntax errors, sudo netplan try for the 120-second rollback safety net, then sudo netplan apply. Verify with ip addr show and ping your gateway before testing external hosts like 1.1.1.1.

You do not pick all three independently. Netplan is the YAML configuration layer at /etc/netplan/ that generates backend configs. systemd-networkd is lean and ideal for headless VPS servers; its generated files live under /run/systemd/network/. NetworkManager suits desktops, Wi-Fi, and VPN use, configured under /etc/NetworkManager/. Switching renderers requires changing the renderer key in Netplan and re-applying. Never hand-edit generated files under /run/ because they disappear on reboot.

The usual causes are a wrong default gateway, an incorrect CIDR prefix such as /32 instead of /24, or a missing routes stanza in Netplan. Ping your gateway IP first; if that fails, the problem is local routing, not DNS or your upstream provider. A /32 netmask is a classic SSH lockout cause because it removes the local subnet route and the server cannot reach its gateway. Compare your YAML against the network details listed in your VPS control panel.

Never run sudo netplan apply blindly over SSH. First run sudo netplan generate to catch YAML syntax errors. Then run sudo netplan try, which gives you 120 seconds to confirm connectivity or automatically rolls back to the previous configuration. Press Enter only when connectivity holds, then run sudo netplan apply once confident. Always keep your provider console access open as an out-of-band path. On production hosts I maintain with Deployer 7, a bad Netplan edit during off-hours maintenance is worse than a failed code release.

Add a nameservers block in your Netplan file with addresses and optional search domains for split DNS on internal LANs. After applying, check the effective resolver with resolvectl status and resolvectl query yourdomain.com. Use /etc/hosts for local staging hostnames before public DNS propagates, but do not rely on it in production. Set the hostname with sudo hostnamectl set-hostname web01 and ensure the FQDN matches your PTR and SSL certificate CN. Test external resolution with dig +short yourdomain.com A from an outside resolver.

On AWS, DigitalOcean, or Hetzner droplets, cloud-init may own the first Netplan file, often 50-cloud-init.yaml with a header comment mentioning cloud-init. Manual edits to that file can be overwritten on reboot unless you disable cloud-init networking or edit the correct persistent file. That surprise has burned more than one server administration engagement. Snapshot the working Netplan file into your infrastructure repo and treat it like application code so the next developer is not guessing gateway values.

DNS misconfiguration looks like a dead website when Nginx or Apache is fine. Browsers fail, but curl -I http://127.0.0.1 still returns 200. Separate name resolution from application issues early with resolvectl status and dig example.com. If ping to an IP like 1.1.1.1 works but hostnames fail, suspect DNS, not the cable or web stack. Check the nameservers block in Netplan and verify records propagate externally. Long search domain lists in Netplan also slow every lookup.

For a secondary IP on one interface, add another address under the same ethernet stanza. VLAN tagging uses a vlans block with id, link, and addresses. Link aggregation requires a bonds stanza with interfaces and parameters like mode: active-backup, but bonding needs switch support. 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.

Network config and firewall rules are two sides of the same coin. After traffic flows correctly, configure UFW on top of netfilter: default deny incoming, allow outgoing, allow OpenSSH, allow Nginx Full or your web ports, then enable with sudo ufw enable. Always allow port 22 before ufw enable or SSH dies even when Netplan is perfect. On production Laravel hosts I open 443 and 22 only. Database ports stay on private interfaces or localhost. Pair UFW with fail2ban for broader hardening.

Work down from link layer to DNS before blaming the web stack. Use ip addr for interface state, ip route for the default gateway, and ss -tulpn for listening sockets. Ping your gateway for Layer 3 local connectivity, then ping 1.1.1.1 for external routing without DNS. Use dig for resolver answers and traceroute for path diagnostics. For systemd-networkd hosts, check journalctl -u systemd-networkd -b for daemon logs. If nothing leaves the box, check gateway and netmask first.

Networking is step one on every VPS I provision. Confirm static IP or DHCP reservation with the hoster, set hostname and DNS A record, wait for propagation, then enable UFW and fail2ban before exposing application ports. Install Nginx, PHP 8.3 or 8.4, and MySQL 8.4 LTS or MySQL 9.7 where supported. Bind MySQL and Redis to localhost. Standardise on one renderer per environment to avoid Netplan drift between staging and production. Store working Netplan YAML in version control alongside Deployer or CI/CD configuration.

Share this article

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.

Quick Contact Options
Choose how you want to connect me: