Idantifying the Correct Configuration Path
Ubuntu's approach to static IP configuration diverges at the 17.10 release. First, confirm your release with lsb_release -r. The following procedures cover both modern and legacy setups.
Current Systems: Ubuntu 17.10 and Later (Netplan)
Netplan abstracts network configuration through YAML files. Locate your system's definition file:
ls /etc/netplan/
The output often shows a single file such as 01-network-manager-all.yaml or 00-installer-config.yaml. If multiple files exist, numerical prefix determines processing order.
Open the file for editing. Configure a static address by replacing the adapter block. The snippet below assumes the interface name is enp0s3; retrieve the actual name with ip link show.
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses:
- 10.0.2.15/24
routes:
- to: default
via: 10.0.2.1
nameservers:
search: [localdomain]
addresses: [9.9.9.9, 149.112.112.112]
Activate the new settings immediately:
sudo netplan apply
Should the adapter name not match, the apply step will fail. Use sudo netplan --debug apply to see detailed logs before troubleshoooting.
Legacy Distributions: Ubuntu 17.04 and Earlier (ifupdown)
For systems still relying on /etc/network/interfaces, define the static asssignment directly.
sudo nano /etc/network/interfaces
Populate it with a stanza similar to:
auto enp0s3
iface enp0s3 inet static
address 10.0.2.15
netmask 255.255.255.0
gateway 10.0.2.1
dns-nameservers 9.9.9.9 149.112.112.112
Restart the networking stack afterward:
sudo systemctl restart networking
Alternatively, cycle only the target interface:
sudo ifdown enp0s3 && sudo ifup enp0s3
Post-Configuration Verification
Validate that the adapter picked up the intended properties:
ip -brief address show enp0s3
Check Layer-3 reachability and name resolution:
ping -c 4 9.9.9.9
ping -c 4 10.0.2.1
host example.com
Safe Configuration Practices
-
Back up before editing. For Netplan:
sudo cp /etc/netplan/01-network-manager-all.yaml ~/netplan-backup.yamlFor ifupdown:
sudo cp /etc/network/interfaces ~/interfaces.backup -
Whitespace matters in YAML. Only spaces, never tabs, should be used for indentation within Netplan files.
-
Address collision risk. Verify the chosen static IP is outside any DHCP pool and not assigned to another host. Use
pingorarp-scanbeforehand.