VMware ESXi and vSphere Cluster Management
Configure a Persistent Static IP Address in Ubuntu
Learn how to choose and configure a persistent static IPv4 address in Ubuntu using legacy ifupdown or modern Netplan, then verify routes, DNS, and reboot persistence.
A static IP address is a manually selected, stable IPv4 address assigned to a host. By contrast, DHCP automatically leases network settings to a client. A DHCP lease can remain unchanged for a long time, but it may change when the lease expires or the device reconnects.
A predictable address is useful for servers, remote administration, DNS records, port forwarding, monitoring, and reliable access from other devices on a LAN. The address must belong to the local subnet, must use the correct gateway, and must not conflict with another device. Choose an unused address outside the router's DHCP allocation range, or create a DHCP reservation for the address in the router.
Understand the values you need
A network interface is a network adapter represented by a Linux name. An IPv4 address is commonly written in dotted-decimal form, such as 192.168.198.160. A subnet mask, such as 255.255.255.0, identifies the network and host portions of the address. The equivalent CIDR prefix is /24.
The default gateway is usually the local router used to reach destinations outside the subnet. DNS translates names such as example.com into IP addresses. DNS is separate from basic IP routing: a host can reach an IP address while still being unable to resolve a hostname.
| Setting | Example value | Purpose | Where to obtain it |
|---|---|---|---|
| Interface name | enp0s3 | Identifies the network adapter | ip addr show |
| IPv4 address | 192.168.198.160 | Stable address for the Ubuntu host | Network plan or administrator |
| Subnet mask or prefix | 255.255.255.0 or /24 | Defines the local subnet | Router, DHCP details, or network administrator |
| Default gateway | 192.168.198.2 | Route to other networks | Router or current DHCP configuration |
| DNS servers | 192.168.198.2, 1.1.1.1 | Resolve hostnames | Router, organization, or DNS provider |
| Network and broadcast | Optional for legacy setups | Used by some older ifupdown configurations | Calculated from the address and mask |
Identify the active interface and current settings
Do not assume the interface is eth0. Older Ubuntu installations often use names such as eth0. Current systems commonly use predictable names such as enp0s3, ens33, or eno1.
ip addr show
ip route show
ip -4 addr show dev eth0
Replace eth0 in the last command with the actual interface name. Look for an inet line to find an existing IPv4 address and for a route beginning with default via to find the current gateway. The ip utility is preferred; ifconfig is an older verification tool that may not be installed.
Temporary versus persistent network settings
A runtime command can change an interface immediately, but it does not necessarily change the configuration used at the next startup. For example, an address added with ip addr can disappear after a reboot, interface reset, or network service restart. Temporary changes are useful for testing, but persistent configuration is the appropriate method for a static address.
Ubuntu uses different network management frameworks. Older installations may use ifupdown, which reads /etc/network/interfaces. Many supported Ubuntu releases use Netplan, whose YAML files are typically under /etc/netplan/ and are rendered to NetworkManager or systemd-networkd. Desktop Ubuntu commonly uses NetworkManager, which can be managed through graphical settings or nmcli.
| Configuration method | Typical Ubuntu environment | Primary configuration location | Apply command or tool |
|---|---|---|---|
| ifupdown | Older Ubuntu installations | /etc/network/interfaces | ifdown and ifup |
| Netplan with systemd-networkd | Many Ubuntu servers | /etc/netplan/*.yaml | netplan try or netplan apply |
| Netplan with NetworkManager | Many Ubuntu desktops | /etc/netplan/*.yaml or NetworkManager profiles | Graphical settings, nmcli, or Netplan |
Configure a legacy Ubuntu system with ifupdown
Use this method only when ifupdown manages the interface. Its traditional persistent configuration file is /etc/network/interfaces. Before editing, make a backup.
sudo cp /etc/network/interfaces /etc/network/interfaces.bak
Edit the file with an editor available on your system. The following example assigns 192.168.198.160 with a /24 subnet and gateway 192.168.198.2 to eth0:
auto eth0
iface eth0 inet static
address 192.168.198.160
netmask 255.255.255.0
gateway 192.168.198.2
| Directive | Example | Meaning |
|---|---|---|
auto | auto eth0 | Bring the interface up during the normal boot process |
iface | iface eth0 inet static | Defines the interface, IPv4 family, and static method |
address | address 192.168.198.160 | Sets the host's IPv4 address |
netmask | netmask 255.255.255.0 | Sets the subnet mask |
gateway | gateway 192.168.198.2 | Sets the default gateway |
Some older ifupdown systems use resolvconf or a compatible resolver setup. If supported by the installed configuration, DNS can be specified with an option such as:
dns-nameservers 192.168.198.2 1.1.1.1
Do not add this directive blindly to a system using a different resolver manager. Confirm how the system manages DNS before editing it. Network and broadcast directives may also appear in legacy configurations, but they are often calculated automatically from the address and netmask.
Apply the ifupdown profile
sudo ifdown eth0
sudo ifup eth0
Replace eth0 with the real interface. These commands take the interface down and bring it back up, so an SSH connection through that interface can be severed. Prefer a local console or out-of-band channel. If neither is available, schedule a recovery action and keep the backup ready before applying the change.
Configure a modern Ubuntu system with Netplan
First determine whether the installed release uses Netplan and which renderer manages the interface. Inspect /etc/netplan/ and the active network tools rather than editing /etc/network/interfaces by habit. Do not mix configuration methods for the same interface.
Create or edit a YAML file such as /etc/netplan/01-static-ip.yaml. YAML indentation is significant:
network:
version: 2
ethernets:
enp0s3:
dhcp4: false
addresses:
- 192.168.198.160/24
routes:
- to: default
via: 192.168.198.2
nameservers:
addresses:
- 192.168.198.2
- 1.1.1.1
Here, enp0s3 is the interface, /24 is the CIDR prefix, the route defines the default gateway, and nameservers supplies DNS resolvers. The filename and renderer can vary by installation.
sudo netplan generate
sudo netplan try
sudo netplan apply
netplan generate checks and generates backend configuration. netplan try applies the configuration with a rollback window and is preferred for remote changes when available. Use netplan apply after validation when an immediate permanent application is appropriate.
NetworkManager alternative
On desktop Ubuntu, NetworkManager may manage the connection through the graphical settings panel. Its command-line inspection commands are:
nmcli connection show
nmcli device status
Use the graphical panel or an appropriate nmcli connection profile to set the address, prefix, gateway, and DNS servers. The important rule is to change the active NetworkManager profile rather than an unrelated file.
Verify the address, route, gateway, and DNS
| Check | Command | Expected result | What failure suggests |
|---|---|---|---|
| Interface address | ip -4 addr show dev eth0 | The intended address and prefix appear | Wrong interface, invalid profile, or unapplied configuration |
| Default route | ip route show default | default via points to the intended gateway | Missing or incorrect gateway |
| Gateway reachability | ping -c 4 192.168.198.2 | Replies from the local router | Incorrect subnet, gateway, link, or address conflict |
| External IP connectivity | ping -c 4 1.1.1.1 | Replies from an external IP | Default route or upstream connectivity problem |
| DNS resolution | getent hosts example.com | A hostname resolves to an address | Missing, unreachable, or incorrect DNS configuration |
Use the actual interface and gateway for your network. Testing an external IP separately from a hostname distinguishes routing problems from DNS problems. After successful tests, reboot the system and run the address and route checks again. A persistent configuration should restore the intended address and default route after reboot.
Troubleshoot common failures
The address disappears after restart or reboot
This usually means only a temporary runtime command was used, the wrong configuration framework was edited, or another network manager overrode the setting. Determine whether the system uses ifupdown, Netplan, NetworkManager, or systemd-networkd. Put the definition in the active framework and reapply it.
Local devices work, but the internet does not
Inspect ip route show and confirm that the default route uses the correct gateway. The gateway must be reachable through the configured subnet. Then ping the gateway before testing an external IP.
IP addresses work, but hostnames do not
Compare ping -c 4 1.1.1.1 with getent hosts example.com. If the first succeeds and the second fails, inspect the resolver configuration and add valid DNS servers through the active network management method.
The connection drops after applying changes
The system may have been accessed over the interface being changed, the interface name may be wrong, the address or prefix may not match the LAN, or a Netplan file may contain invalid YAML indentation. Use console access, validate the configuration, check ip addr show, and restore the backup if necessary.
A duplicate IP address is reported
The selected address may already be in use or may overlap the router's DHCP pool. Check DHCP leases and reservations, then choose an unused address outside the pool or reserve the address in DHCP. Duplicate addresses commonly cause intermittent connectivity.
ifup or ifdown is unavailable
This indicates that ifupdown may not manage the interface. Inspect /etc/netplan/, check NetworkManager's active profiles, and determine which service controls the link. Use that service's configuration format and apply commands.
Exam-relevant points
- A static IP is manually selected and stable; DHCP leases settings automatically.
- The address, prefix or subnet mask, and gateway must describe the same local network.
- A static address should not conflict with another host or the DHCP allocation range.
eth0is a traditional name; modern predictable names includeenp0s3,ens33, andeno1.- Runtime interface commands are temporary unless a persistent configuration source is updated.
- Older ifupdown systems use
/etc/network/interfaces; many modern Ubuntu systems use Netplan YAML under/etc/netplan/. - A default route controls traffic for destinations without a more-specific route, while DNS controls hostname resolution.
- Never apply a remote network change without a recovery path.
For this lesson's complete reference, see Configure a static IP address in Ubuntu.