A static IP address keeps SSH bookmarks, port-forwarding rules, DNS records, and self-hosted services from changing every time DHCP hands out a new lease. To configure a static IP address on Ubuntu, start with the least risky option for your network: a router DHCP reservation when you control the router, Netplan on Ubuntu Server, and GNOME Settings or nmcli on Ubuntu Desktop.
The workflows here apply to Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. The examples use IPv4 because that is the common home lab, office LAN, and server management case, but the same planning rules apply to IPv6: choose an address your network actually routes, keep DNS explicit, and make the change from a console or rollback-safe session when remote access matters.
Choose a Static IP Method on Ubuntu
Pick the method that matches where the address should be controlled. A router reservation is usually safest on a home or office LAN because Ubuntu can keep using DHCP, while local static configuration is better when the machine must own its address independently.
| Method | Best For | What Changes | Main Caution |
|---|---|---|---|
| Router DHCP reservation | Home servers, media servers, printers, and port forwarding when you manage the router | The router always leases the same address to Ubuntu’s MAC address | Router menus vary, so use the vendor UI and avoid duplicate reservations |
| Netplan YAML | Ubuntu Server, headless systems, cloud images you fully control, and SSH-managed hosts | /etc/netplan/*.yaml defines the address, gateway, DNS, and renderer | Use sudo netplan try over SSH so a bad address can roll back |
| GNOME Settings | Ubuntu Desktop users who prefer a graphical workflow | NetworkManager stores the manual IPv4 settings and applies them to the selected connection | Reconnect the edited connection after applying the change |
nmcli | Desktop systems, scripts, and NetworkManager-managed servers | The active NetworkManager connection profile gets manual IPv4 values | Bringing a connection down and up can interrupt remote sessions |
Use a local static IP only when you know the subnet, gateway, DNS servers, and DHCP pool boundaries. If your router leases 192.168.1.100 through 192.168.1.200, choose an unused address outside that pool, or create a DHCP reservation instead.
Collect Ubuntu Network Details Before Editing
Record the current interface, address prefix, default gateway, and active NetworkManager profile before changing anything. These values tell you which interface to edit and give you a quick rollback reference.
ip -br link
ip -br -4 addr show scope global
ip route show default
A typical wired Ubuntu VM or server may show one active Ethernet device, one DHCP address, and one default route:
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP> enp0s3 UP 08:00:27:6b:d6:84 <BROADCAST,MULTICAST,UP,LOWER_UP> enp0s3 UP 192.168.50.219/24 default via 192.168.50.1 dev enp0s3 proto dhcp src 192.168.50.219 metric 100
In this example, enp0s3 is the interface, /24 is the prefix length, and 192.168.50.1 is the gateway. Your interface might be ens18, eno1, wlp2s0, or another predictable device name.
If NetworkManager is active, list the connection profile as well. This matters for the nmcli method because profile names often differ from interface names.
nmcli -t -f NAME,TYPE,DEVICE connection show --active
Ubuntu Desktop systems can report a profile created through Netplan or a normal wired profile:
netplan-enp0s3:802-3-ethernet:enp0s3 lo:loopback:lo
If you need to confirm the release before choosing a method, check the Ubuntu version first. Static IP commands do not require a package install on a normal Ubuntu system, but they do require administrator access.
Configure Static IP on Ubuntu Server with Netplan
Netplan is the standard network configuration layer on current Ubuntu releases. Ubuntu Server commonly renders Netplan through systemd-networkd, while Desktop commonly uses NetworkManager behind the graphical tools.
Find and Back Up the Netplan File
List the YAML files under /etc/netplan and identify the one that defines your active interface.
sudo find /etc/netplan -maxdepth 1 -type f -name '*.yaml' -print | sort
These commands use
sudobecause Netplan files belong to the system. If your account is not an administrator yet, add a new user to sudoers on Ubuntu before editing network configuration.
Common file names include installer and NetworkManager profiles:
/etc/netplan/00-installer-config.yaml /etc/netplan/01-network-manager-all.yaml
Back up the file you plan to edit. Replace the file name if your system uses a different Netplan file.
sudo cp /etc/netplan/00-installer-config.yaml /etc/netplan/00-installer-config.yaml.backup
Write the Static IPv4 Netplan Configuration
Open the Netplan file with your editor. The file name must match the backup step you used.
sudo nano /etc/netplan/00-installer-config.yaml
Use a configuration like this for a server interface managed by systemd-networkd. Replace enp0s3, 192.168.1.50/24, 192.168.1.1, and the DNS addresses with values from your network.
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
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
Keep the spacing exactly as YAML requires. Use spaces, not tabs, and keep nested lines aligned under the correct parent key. The routes block is the current form for the default gateway on supported Ubuntu LTS releases; avoid older gateway4 examples when writing fresh Netplan configuration.
Validate and Apply Netplan Safely
Validate the YAML before changing the running network. A clean configuration is silent; errors usually point to indentation, a misspelled key, or an invalid address format.
sudo netplan generate
Use Netplan’s rollback prompt when you are connected over SSH or any remote console that could be cut off by a bad address. If the new settings break the connection and you cannot confirm the prompt, Netplan rolls back after the timeout.
sudo netplan try --timeout 120
Confirm the prompt only after a second terminal or another machine can still reach the new address. If you are working from a local console and intentionally skipped the rollback prompt, apply the saved file directly.
sudo netplan apply
If the change fails at a local console, restore the backup and apply it again.
sudo cp /etc/netplan/00-installer-config.yaml.backup /etc/netplan/00-installer-config.yaml
sudo netplan apply
Set a Static IP on Ubuntu Desktop with Settings
GNOME Settings is the cleanest desktop path because it edits the selected NetworkManager connection instead of asking you to hand-write YAML. Use it when you are sitting at the machine or have graphical remote access.
- Open Settings.
- Select Network for wired connections or Wi-Fi for wireless connections.
- Open the gear icon for the active connection.
- Select the IPv4 tab and change the method from automatic DHCP to Manual.
- Enter the address, netmask, and gateway. For example,
192.168.1.50,255.255.255.0, and192.168.1.1represent the same network as192.168.1.50/24. - Turn off automatic DNS if you want fixed DNS servers, then enter one or more DNS addresses.
- Apply the change and reconnect the edited network connection.
If the desktop is also your remote access host, make the change from the local screen or a provider console. A wrong gateway or duplicate address can disconnect SSH, remote desktop, and file shares at the same time.
Set a Static IP with nmcli on Ubuntu
Use nmcli when the system is managed by NetworkManager and you want a repeatable terminal workflow. This is common on Ubuntu Desktop and on servers intentionally configured with NetworkManager.
Start by listing active profiles and choose the profile attached to the device you want to change.
nmcli -t -f NAME,TYPE,DEVICE connection show --active
Set a shell variable for the connection name. Keep the quotes because many desktop profile names contain spaces.
CONNECTION="netplan-enp0s3"
Change the profile to manual IPv4 addressing. Replace the address, gateway, and DNS servers with values that fit your subnet.
sudo nmcli connection modify "$CONNECTION" \
ipv4.method manual \
ipv4.addresses "192.168.1.50/24" \
ipv4.gateway "192.168.1.1" \
ipv4.dns "1.1.1.1 8.8.8.8"
Review the saved profile before reconnecting. The first line should be manual, and the remaining lines should match your chosen address, gateway, and DNS servers.
nmcli -g ipv4.method,ipv4.addresses,ipv4.gateway,ipv4.dns connection show "$CONNECTION"
Reconnect the profile from a local terminal or console. Running these two commands over SSH can interrupt the session before the second command finishes.
sudo nmcli connection down "$CONNECTION"
sudo nmcli connection up "$CONNECTION"
Verify the Static IP Address on Ubuntu
After applying the change, confirm the local address, default route, DNS servers, gateway reachability, and name resolution. Replace enp0s3 and 192.168.1.1 with your interface and gateway.
ip -br -4 addr show dev enp0s3
ip route show default
resolvectl dns enp0s3
ping -c 3 192.168.1.1
ping -c 3 1.1.1.1
getent hosts ubuntu.com
Read the checks in order. The address check should show your static IPv4 address, the route check should show the correct gateway, the DNS check should show your chosen resolvers, the gateway ping should prove local LAN access, the public IP ping should prove outbound routing, and getent hosts should prove DNS resolution.
If IP connectivity works but DNS does not, review the nameserver lines in Netplan or the DNS fields in NetworkManager. For deeper resolver checks, the guide to fixing curl could not resolve host covers common DNS failure patterns.
Avoid IP Conflicts on Ubuntu Networks
A static address must be unique on the subnet. The safest address is outside the DHCP pool but still inside the network prefix. On a typical 192.168.1.0/24 LAN, an address like 192.168.1.50 is valid only if the router uses 192.168.1.1, the netmask is 255.255.255.0, and no other device already owns 192.168.1.50.
Check the router or DHCP server before assigning the address. Many routers let you shrink the automatic pool or reserve a specific address for Ubuntu’s MAC address. A reservation avoids most duplicate-IP problems because the router remains the source of truth.
Duplicate address symptoms include intermittent SSH drops, one machine disappearing when another boots, failed pings that work a few seconds later, and router client lists that show the same IP beside different MAC addresses. If you see those signs, move the Ubuntu host to a different unused address or create a router reservation.
Handle Cloud-init and Provider Networks
Cloud images, VPS templates, and appliance images can regenerate Netplan files during boot. If a file under /etc/netplan says it is managed by cloud-init, do not treat a manual edit as durable until you confirm how that image is meant to receive network configuration.
For public cloud servers, prefer the provider’s static private IP, reserved public IP, floating IP, or cloud-init network configuration path. Disabling cloud-init networking by hand can lock you out of a remote instance if the provider expects cloud-init to restore routes, DNS, or interface names at boot.
On a local VM or lab image that you fully control, manual Netplan can be fine after you document the current file and keep console access available. When in doubt, snapshot the VM or confirm the provider rescue console before editing network ownership.
Troubleshoot Static IP Problems on Ubuntu
Netplan Reports a YAML Error
Netplan’s debug output names the file and line that failed. Most errors come from tabs, uneven indentation, missing colons, or values placed under the wrong parent key.
sudo netplan generate --debug
SSH Drops After Applying the Address
Use sudo netplan try --timeout 120 for remote changes so Netplan can roll back automatically. If you applied directly and lost access, use the VM console, physical console, or provider recovery console to restore the backup file.
The Gateway Works but DNS Fails
Check the DNS servers attached to the interface. For Netplan, make sure nameservers is indented under the same interface as the static address. For NetworkManager, make sure automatic DNS is off only when you entered manual DNS servers.
resolvectl dns enp0s3
getent hosts ubuntu.com
NetworkManager Reverts the Desktop Setting
Confirm that you edited the active profile and not a disconnected profile with a similar name. If the system uses Netplan-generated NetworkManager profiles, use GNOME Settings or nmcli for normal desktop changes instead of editing generated files under /run.
nmcli -t -f NAME,TYPE,DEVICE connection show --active
Older Netplan Gateway Examples Use gateway4
Use the routes block with to: default and via: on Ubuntu 26.04, 24.04, and 22.04. The older gateway4 key appears in many outdated examples, but new Netplan files should use the route syntax.
Return Ubuntu to DHCP
Undo the static address when the router will manage the reservation, when you move the machine to a different network, or when troubleshooting requires a clean automatic lease.
Restore DHCP in Netplan
For a server Netplan file, reduce the interface back to DHCP and remove the static address, route, and nameserver blocks unless you still need custom DNS.
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: true
Validate and apply the DHCP configuration with rollback protection.
sudo netplan generate
sudo netplan try --timeout 120
Restore DHCP with nmcli
For a NetworkManager profile, switch IPv4 back to automatic addressing and clear the manual address, gateway, and DNS properties.
sudo nmcli connection modify "$CONNECTION" \
ipv4.method auto \
ipv4.addresses "" \
ipv4.gateway "" \
ipv4.dns ""
Reconnect locally after confirming you are ready for the address to change.
sudo nmcli connection down "$CONNECTION"
sudo nmcli connection up "$CONNECTION"
Ubuntu Desktop users can make the same rollback in Settings by changing the IPv4 method from Manual back to Automatic DHCP and reconnecting the network.
Conclusion
Ubuntu now has a stable address path that matches the way the system is managed: router reservation for simple LAN ownership, Netplan for server configuration, and Settings or nmcli for NetworkManager profiles. After the address is stable, protect remote access with SSH on Ubuntu and review exposed services with the Ubuntu UFW firewall guide.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>