Unit

Configure a Static IP Address in Ubuntu

Learn how to configure and verify a persistent static IPv4 or IPv6 address in Ubuntu with Netplan, Settings, NetworkManager, or legacy ifupdown.

A static IP address is an address manually assigned to a host and intended to remain stable. This is useful for Ubuntu servers, network appliances, remote-administration systems, home-lab machines, and services with stable DNS records.

Before changing networking, make sure you understand IP routing, administrator privileges with sudo, and basic Linux terminal navigation.

Static IP addressing fundamentals

DHCP, the Dynamic Host Configuration Protocol, automatically leases settings such as an IP address, subnet prefix, gateway, and DNS servers to a client. A DHCP address can change when the lease expires, the router is replaced, or the client reconnects.

A static address is configured explicitly on the Ubuntu host. It normally remains the same until an administrator changes it. A router-side DHCP reservation is an alternative: the host continues using DHCP, but the router consistently assigns the same address based on the device's MAC address.

Use a static configuration when a service must be reachable at a predictable address, for example:

  • A web, file, database, or monitoring server.
  • A host used for SSH or other remote administration.
  • A printer, hypervisor, storage system, or other network appliance.
  • A machine referenced by a stable internal DNS record.

A complete IPv4 configuration normally includes these values:

  • IP address: the address assigned to the interface, such as 192.168.1.50.
  • CIDR prefix: the number after the slash, such as /24, identifying the network portion of the address.
  • Subnet mask: the dotted-decimal equivalent, such as 255.255.255.0.
  • Default gateway: the router used to reach destinations outside the local subnet.
  • DNS resolvers: servers that translate hostnames such as example.com into IP addresses.

The chosen static address must not be handed out to another DHCP client. Select an address outside the router's DHCP pool, or create a DHCP reservation. Otherwise, two devices can use the same address and cause intermittent connectivity or duplicate-address warnings.

Collect safe network values

First determine the local subnet and router. On a typical home LAN, an address such as 192.168.1.20/24 means the local network is 192.168.1.0/24. The router may be 192.168.1.1, but do not assume this without checking.

Choose an unused address in the same subnet. For example, if the router is 192.168.1.1, the prefix is /24, and DHCP leases occupy 192.168.1.100 through 192.168.1.200, an address such as 192.168.1.50 may be suitable if it is not already used. Confirm the choice in the router's client list or with the network administrator.

Static IP values to collect before configuration

SettingExamplePurposeHow to determine it

IP address — 192.168.1.50 — Identifies the Ubuntu host — Choose an unused address in the local subnet.

CIDR prefix — /24 — Defines the local network size — Read the current DHCP address or network documentation.

Default gateway — 192.168.1.1 — Sends non-local traffic to the router — Inspect the current default route.

DNS resolver — 192.168.1.1 or 1.1.1.1 — Resolves hostnames — Use the router, organizational DNS, or an approved public resolver.

Common IPv4 prefix equivalents include:

CIDR prefixSubnet maskUsual network size

/24255.255.255.0 — 256 total addresses, commonly 254 usable host addresses

/25255.255.255.128 — 128 total addresses, commonly 126 usable host addresses

/16255.255.0.0 — 65,536 total addresses

/8255.0.0.0 — 16,777,216 total addresses

For most small LANs, 255.255.255.0 and /24 describe the same network. Do not change the prefix merely because another network uses a different one.

Inspect the current Ubuntu network configuration

A network interface is a physical adapter or logical network device. Names such as enp0s3 and eth0 commonly identify wired interfaces; names such as wlan0 or wlp2s0 commonly identify Wi-Fi. Virtual machines, containers, bridges, bonds, and tunnels have other names. The lo device is the loopback interface and normally uses 127.0.0.1 or ::1.

ip -br addr
ip addr show
ip route show
ip route get 1.1.1.1
resolvectl status
cat /etc/resolv.conf

Look for an interface marked UP, its current IPv4 and IPv6 addresses, and a line beginning with default via. The route lookup shows which interface and gateway Ubuntu would use to reach an external IPv4 address. resolvectl status displays resolver information known to systemd-resolved; /etc/resolv.conf may be a generated file or symbolic link.

Netplan configuration is normally stored under /etc/netplan.

ls -l /etc/netplan/
sudo netplan get

Ubuntu commonly uses Netplan with one of two renderers. NetworkManager is common on desktop installations and manages interactive wired and wireless profiles. systemd-networkd is common on servers and applies declarative interface configuration. Older installations may use ifupdown, whose main configuration file is /etc/network/interfaces.

To inspect NetworkManager:

nmcli device status
nmcli connection show

A device shown as connected by NetworkManager is usually managed through a NetworkManager connection profile. Do not edit a Netplan file and an independent NetworkManager or ifupdown profile for the same interface unless that arrangement is deliberate. Multiple managers can overwrite one another's settings.

Choose the Ubuntu configuration method

MethodTypical environmentPrimary location or toolWhen to use itCautions

Netplan with NetworkManager — Ubuntu Desktop — /etc/netplan/*.yaml or Settings — Use the system's declared Netplan and desktop connection model — Do not create competing profiles.

Netplan with systemd-networkd — Ubuntu Server — /etc/netplan/*.yaml — Use for server interfaces managed by networkd — YAML indentation and interface names must be exact.

NetworkManager command line — Desktop or a directly managed workstation — nmcli — Use when NetworkManager owns the connection profile — Modify the active profile, not an unrelated profile.

ifupdown — Older Ubuntu systems — /etc/network/interfaces — Use only when ifupdown is the intended manager — Avoid mixing it with Netplan or NetworkManager.

Configure a static IPv4 address with Netplan

Netplan is Ubuntu's declarative network configuration layer. Its YAML files describe interfaces, addresses, routes, DNS resolvers, and the renderer that applies them. File names vary, so inspect the directory rather than assuming a particular file.

Back up the current files before editing:

sudo cp -a /etc/netplan /etc/netplan.backup

The following example configures a wired interface named enp0s3 on a small LAN. It uses systemd-networkd, disables IPv4 DHCP, assigns 192.168.1.50/24, sets a default route through 192.168.1.1, and defines two DNS resolvers.

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:
          - 192.168.1.1
          - 1.1.1.1

For a NetworkManager-managed system, retain the same structure but select the NetworkManager renderer:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: false
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 192.168.1.1
          - 1.1.1.1

Replace enp0s3, the address, prefix, gateway, and DNS values with values from your network. The interface name must exactly match the output of ip -br addr. Set dhcp4: false so DHCP does not replace the fixed IPv4 settings.

YAML uses indentation to express structure. Use spaces, not tabs. The dash introduces an item in a list, so addresses and the DNS addresses value contain indented list items. A misplaced space can change the structure or make the file invalid. Also check all files in /etc/netplan, because multiple files may be merged and conflicting keys can produce unexpected results.

Generate configuration first, then test it with a rollback-capable confirmation period:

sudo netplan generate
sudo netplan try

netplan try applies the proposed configuration temporarily and asks for confirmation. If connectivity is lost or confirmation is not completed, it can roll back. Confirm only after testing the address, route, and DNS. Once satisfied, apply the configuration normally:

sudo netplan apply

Configure a static address through Ubuntu Settings

Ubuntu Desktop commonly uses NetworkManager for graphical connections. The exact labels can differ slightly by release, but the process is generally:

  1. Open Settings and select Network for Ethernet or Wi-Fi for a wireless connection.
  2. Select the connected network and open its connection settings, often using a gear button.
  3. Open the IPv4 section and change the method from Automatic (DHCP) to Manual.
  4. Enter the address, netmask or prefix, and gateway. For example, enter address 192.168.1.50, netmask 255.255.255.0 or prefix /24, and gateway 192.168.1.1.
  5. Enter one or more DNS servers, separated as required by the interface, such as 192.168.1.1 and 1.1.1.1.
  6. Save the connection, disconnect, and reconnect it. For Wi-Fi, reconnect to the wireless network.

Graphical settings normally update a NetworkManager connection profile. On systems where Netplan also generates NetworkManager configuration, the graphical profile and Netplan files may coexist. Determine which layer is authoritative before making later changes, and avoid configuring the same interface independently through multiple managers.

Configure a static address with NetworkManager and nmcli

Use nmcli when NetworkManager directly manages the connection. Find the device and the saved connection profile first:

nmcli device status
nmcli connection show

Modify the existing profile. The quoted name must match the output of nmcli connection show:

sudo nmcli connection modify "Wired connection 1" ipv4.method manual ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1 ipv4.dns "192.168.1.1 1.1.1.1"
sudo nmcli connection up "Wired connection 1"

ipv4.method manual disables automatic IPv4 DHCP for that profile. The address includes the CIDR prefix, while the gateway and DNS values are separate properties. If the profile is already active, bringing it up again may briefly interrupt connectivity.

Legacy ifupdown configuration

ifupdown is an older Ubuntu networking method. It is identified by configuration in /etc/network/interfaces and is found mainly on older installations or deliberately maintained legacy systems.

auto eth0
iface eth0 inet static
    address 192.168.1.50
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1 1.1.1.1

The basic fields are the interface name, static address, subnet mask, gateway, and DNS servers. Use this only when ifupdown is the intended manager on that host. Do not mix Netplan, NetworkManager, and ifupdown for one interface unless the system design explicitly supports it.

IPv6 considerations

IPv6 is a 128-bit addressing system and is managed independently from IPv4. A host may use IPv4 DHCP while obtaining IPv6 settings from router advertisements, DHCPv6, or a manual configuration. Changing IPv4 does not automatically configure IPv6.

A static IPv6 design needs an IPv6 address, a prefix length such as /64, an IPv6 default gateway or router route, and suitable DNS resolvers. Conceptually, a Netplan interface might contain:

dhcp6: false
accept-ra: false
addresses:
  - 2001:db8:1234:1::50/64
routes:
  - to: default
    via: 2001:db8:1234:1::1
nameservers:
  addresses:
    - 2001:4860:4860::8888

The 2001:db8::/32 range is documentation-only; use addresses assigned by your network provider or organization. Unless your network specifically requires manually assigned IPv6, retain automatic IPv6 behavior so router advertisements and prefix changes continue to work.

Verify the configuration

Check the interface, route, gateway, external connectivity, and DNS in that order. A successful gateway test does not prove that DNS or Internet access is working.

ip -br addr
ip route show
ping -c 4 192.168.1.1
ping -c 4 1.1.1.1
ping -c 4 example.com
getent hosts example.com
resolvectl status

For the example, the interface should show 192.168.1.50/24, the routing table should contain a default route through 192.168.1.1, the gateway should answer, and the external IP and hostname tests should succeed.

CheckCommand or actionExpected resultWhat failure suggests

Assigned address — ip -br addr — Intended address appears on the intended interface — Wrong interface, invalid configuration, or DHCP still active.

Default route — ip route show — A default route points to the expected gateway — Missing or incorrect gateway or route.

Gateway reachability — ping -c 4 192.168.1.1 — Local router responds — Wrong subnet, address conflict, link problem, or incorrect gateway.

External IP connectivity — ping -c 4 1.1.1.1 — Public IP is reachable — Missing route, router outage, or outbound filtering.

DNS resolution — getent hosts example.com — A hostname resolves to an address — Incorrect DNS settings or resolver failure.

Persistence — Reconnect or reboot, then repeat the checks — The same address and route return — Temporary change, wrong profile, or another manager overwriting settings.

Troubleshoot common problems

Connectivity disappears after applying the change

Likely causes include an incorrect address, prefix, gateway, interface name, or connection profile. An address conflict can have the same symptom. Use local or console access, run ip addr and ip route, restore the backup, or allow netplan try to roll back.

The gateway works, but the Internet does not

Inspect the default route and compare it with another working device on the same LAN. Then test a public IP. If the public IP fails, check the router's upstream connection and outbound restrictions.

IP connectivity works, but hostnames fail

Review resolvectl status and verify that the nameservers in Netplan or the NetworkManager profile were applied. Test with getent hosts example.com. The problem is likely DNS rather than addressing or routing.

Netplan rejects the YAML

Run sudo netplan generate to expose parsing errors. Check indentation, list dashes, spelling, interface names, and every file under /etc/netplan. Use spaces consistently and ensure keys are nested at the correct level.

The address disappears after reboot

The change may have been temporary, applied to the wrong profile, or overwritten by another manager. Inspect Netplan files, NetworkManager profiles, and whether cloud-init generates network configuration. Confirm that the intended connection is configured to autoconnect.

Another device reports a duplicate address

The address may already be in use or inside the active DHCP pool. Check the router's lease and client lists, choose another unused address, adjust the DHCP pool, or create a router-side DHCP reservation.

Static assignment versus DHCP reservation

A host-side static address gives Ubuntu direct control and is useful when the machine must work independently of a DHCP server. A router-side reservation preserves centralized DHCP management, automatically supplies the gateway and DNS values, and still provides a stable address. For many home and small-office networks, a reservation is the safer operational choice.

Related learning