Static IP addressing keeps critical services reachable at a predictable location, avoiding surprises when a router reboots or a DHCP lease expires. Servers, network appliances, and lab machines benefit from a fixed address that matches firewall rules, DNS records, and port forwarding setups.
On modern Ubuntu and many other Linux distributions, IP configuration is driven by declarative files rather than ad-hoc scripts. On current Ubuntu Server releases, /etc/netplan YAML files describe interfaces, and netplan translates those settings into concrete configuration for systemd-networkd or NetworkManager at boot. A static address is achieved by disabling DHCP for the interface and specifying the address, prefix length, gateway, and DNS servers.
Incorrect network parameters can detach a host from the network or break routing. Reliable configuration requires knowing the correct subnet, default gateway, and name servers before editing any files, ideally with local or out-of-band console access in case connectivity is lost. The steps below assume Ubuntu 20.04 LTS or later using netplan with systemd-networkd as the renderer; other distributions may use different tooling such as NetworkManager profiles or legacy /etc/network/interfaces syntax.
Steps to configure a static IP address:
- Open a terminal on the Linux system with a user that can run sudo.
$ whoami sysadmin - Display current IP configuration to note the interface name and existing address.
$ ip -br address lo UNKNOWN 127.0.0.1/8 ::1/128 enp0s3 UP 192.168.1.23/24 fe80::a00:27ff:fe4e:66a1/64
The interface name in this example is enp0s3; values such as ens33 or eth0 are also common.
- Show the current default route to capture the gateway used by the system.
$ ip route default via 192.168.1.1 dev enp0s3 proto dhcp metric 100 192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.23 metric 100
The address after default via (here 192.168.1.1) is the gateway to reuse in the static configuration.
- List existing netplan configuration files in /etc/netplan.
$ ls /etc/netplan 00-installer-config.yaml
Actual filenames vary by installation; only one or two YAML files are typically present.
- Create a backup of the primary netplan file before editing.
$ sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.bak
Retaining a backup allows recovery from misconfiguration by restoring the original file from local console access.
- Open the netplan configuration file in a text editor.
$ sudo nano /etc/netplan/00-installer-config.yaml
- Replace or add an ethernets section that defines a static IPv4 configuration for the chosen interface.
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: no dhcp6: no addresses: - 192.168.1.50/24 gateway4: 192.168.1.1 nameservers: addresses: - 1.1.1.1 - 8.8.8.8Adjust the interface name, address (with prefix length), gateway, and DNS servers so they match the actual network; avoid choosing an address already used by another device.
- Validate the new configuration and apply it temporarily to reduce the risk of being locked out.
$ sudo netplan try Do you want to keep these settings? Press ENTER before the timeout to accept the new configuration. Changes will revert in 120 seconds if not confirmed.
If connectivity is lost and the prompt is not confirmed in time, netplan reverts to the previous configuration, but active sessions can still be interrupted.
- Apply the configuration permanently after confirming that connectivity and access remain stable.
$ sudo netplan apply
No output from netplan apply indicates the configuration was accepted.
- Display the IPv4 address on the interface to verify that the static address is active.
$ ip -4 addr show enp0s3 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 inet 192.168.1.50/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever
- Check the routing table to confirm that the default route matches the configured gateway.
$ ip route default via 192.168.1.1 dev enp0s3 proto static 192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.50
- Test connectivity to the gateway and an external address.
$ ping -c 3 192.168.1.1 PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data. 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.504 ms 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.489 ms 64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.497 ms --- 192.168.1.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss rtt min/avg/max/mdev = 0.489/0.497/0.504/0.010 ms $ ping -c 3 1.1.1.1 ##### snipped #####
Successful replies from the gateway and an external host confirm both local connectivity and upstream routing.
- Confirm persistence during a maintenance window by rebooting and re-checking the address and routes.
$ sudo reboot
Rebooting is disruptive for users and services; schedule the restart appropriately and verify that critical workloads tolerate a brief outage.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
