6.1b Configuring static IPs with netplan (Ubuntu 18.04+) and YAML syntax¶
🌐 Context Introduction¶
When setting up servers for AI workloads, network interfaces often need fixed (static) IP addresses instead of dynamic ones assigned by DHCP. This ensures that compute nodes, storage servers, and management tools can always find each other at the same address. Ubuntu 18.04 and later versions use netplan as the default network configuration tool. Netplan reads simple YAML configuration files and translates them into the underlying network system (like systemd-networkd or NetworkManager). Understanding how to write these YAML files is essential for any engineer managing AI infrastructure.
⚙️ What is Netplan?¶
- Netplan is a utility that configures networking on Ubuntu systems using YAML syntax.
- It replaces older tools like /etc/network/interfaces.
- Configuration files live in the /etc/netplan/ directory.
- After editing a config file, you apply changes with a single command.
- Netplan supports both DHCP (automatic) and static (manual) IP assignment.
📄 YAML Syntax Basics for Netplan¶
YAML is a human-readable data serialization language. For netplan, you need to understand these key rules:
- Indentation matters: Use spaces (not tabs) to show hierarchy. Two spaces per level is standard.
- Colons separate keys from values.
- Dashes indicate list items.
- Quotes are optional for most values but required if the value contains special characters (like colons or spaces).
🛠️ Structure of a Netplan Configuration File¶
A typical netplan file has this layout:
- network: The top-level key.
- version: Always set to 2 for modern configurations.
- renderer: Optional; specifies the backend (e.g., networkd or NetworkManager).
- ethernets: A section listing your physical network interfaces (e.g., eth0, ens33).
- wifis: A section for wireless interfaces (rare in AI server environments).
🕵️ Identifying Your Network Interface Name¶
Before writing a config, you must know the exact name of your network interface. Common names include:
- eth0, eth1 — traditional naming
- ens33, ens160 — predictable naming based on firmware/PCI
- eno1, eno2 — embedded NIC naming
To find your interface name, you can check the output of a system command that lists network devices. The name will appear as a label like ens33 or eth0.
📊 Static IP vs DHCP — Quick Comparison¶
| Feature | DHCP | Static IP |
|---|---|---|
| IP assignment | Automatic from a server | Manually defined by you |
| Reliability | May change on reboot | Always the same address |
| Use case | Desktops, temporary nodes | Servers, AI compute nodes, storage |
| Configuration effort | Minimal | Requires careful planning |
| Risk of IP conflict | Low (server manages) | Possible if duplicates exist |
For AI infrastructure, static IPs are almost always used for critical components like: - Management nodes - GPU compute servers - Storage arrays - Monitoring systems
📊 Visual Representation: Netplan Configuration and Application Flow¶
This flowchart shows the Netplan architecture where a YAML configuration is generated and processed by netplan generate to configure network renderer daemons.
🧩 Example Netplan Configuration for a Static IP¶
Below is a reference example of a netplan YAML file that sets a static IP on an interface named ens33.
For reference:
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
📤 Output: After applying, the interface ens33 will have the static IP 192.168.1.100 with a subnet mask of 255.255.255.0 (the /24 notation), a default gateway of 192.168.1.1, and DNS servers 8.8.8.8 and 8.8.4.4.
🔍 Breaking Down the YAML Keys¶
- dhcp4: no — Disables automatic IP assignment from DHCP.
- addresses — A list of IP addresses with subnet prefix (e.g., 192.168.1.100/24).
- gateway4 — The default gateway for IPv4 traffic.
- nameservers — DNS server addresses your system will use.
- renderer: networkd — Tells netplan to use systemd-networkd (recommended for servers).
✅ Applying Your Netplan Configuration¶
After creating or editing a YAML file in /etc/netplan/, you must apply the changes. The process involves:
- Test the configuration — This validates your YAML syntax without applying it.
- Apply the configuration — This activates the new network settings.
- Check the result — Verify the interface now has the expected IP address.
If something goes wrong, you can revert to a previous configuration by reapplying the original file.
⚠️ Common Mistakes and How to Avoid Them¶
- Using tabs instead of spaces — YAML strictly requires spaces. Always use your editor's space key.
- Wrong interface name — Double-check the interface name before writing the config.
- Forgetting to disable DHCP — If dhcp4 is not set to no, the system may still get a dynamic IP.
- Incorrect subnet prefix — A /24 is not the same as /16. Know your network's subnet mask.
- Missing gateway — Without a gateway, the server cannot reach other networks.
🧪 Testing Your Configuration Safely¶
Before applying to a production server, consider these best practices:
- Use a test VM — Practice on a non-critical system first.
- Keep a backup — Copy the original netplan file before editing.
- Have console access — If you lock yourself out via SSH, you'll need physical or remote console access to fix it.
- Apply during maintenance windows — Network changes can disrupt active connections.
📚 Summary¶
Configuring static IPs with netplan on Ubuntu 18.04+ is a fundamental skill for engineers working with AI infrastructure. The process involves:
- Writing a YAML file in /etc/netplan/ with the correct syntax.
- Specifying the interface name, static IP, gateway, and DNS servers.
- Testing and applying the configuration.
- Verifying the new settings are active.
Mastering this ensures that your AI compute nodes, storage systems, and management tools maintain consistent network identities — a critical requirement for reliable operations.