A static IP address keeps a Linux server reachable when firewall rules, DNS records, monitoring checks, or port forwards expect one address. Setting the address in the active network configuration layer prevents the host from returning to a DHCP-assigned address after a lease renewal or reboot.

On current Ubuntu Server systems, Netplan reads YAML files under /etc/netplan and generates configuration for systemd-networkd or NetworkManager. A static IPv4 configuration disables DHCP on the target interface, sets an address with a prefix length, defines the default route, and lists the DNS servers that should be used for name lookups.

Wrong subnet, gateway, or DNS values can make a remote host unreachable even when the YAML parses cleanly. Confirm the interface name, unused address, prefix length, gateway, and resolvers before applying the change, and use a local console or out-of-band access path for servers that are administered over SSH. Ubuntu servers commonly use Netplan with systemd-networkd as the renderer; NetworkManager-managed desktops may need profile-specific handling.

Steps to configure a static IP address with Netplan:

  1. Display the current interface names and addresses.
    $ ip -br address show
    lo               UNKNOWN        127.0.0.1/8 ::1/128
    enp1s0           UP             192.0.2.40/24 2001:db8:10::40/64 fe80::5054:ff:fe12:3456/64
    enp2s0           DOWN

    The sample commands configure enp1s0. Replace it with the interface that carries the address being changed.

  2. Check the current default route.
    $ ip route show default
    default via 192.0.2.1 dev enp1s0 proto dhcp src 192.0.2.40 metric 100

    The address after default via is the gateway to use only when the static address remains in the same subnet.

  3. Check the current DNS servers for the interface.
    $ resolvectl dns enp1s0
    Link 2 (enp1s0): 192.0.2.53 192.0.2.54

    If resolvectl is unavailable, use the network manager output for the target system and record the resolver addresses supplied by the network administrator.

  4. List the existing Netplan files.
    $ ls /etc/netplan
    00-installer-config.yaml

    Netplan reads YAML files from /etc/netplan in lexical order. A later file can override scalar settings from an earlier file for the same interface.

  5. Create a new high-numbered Netplan file for the static address.
    $ sudo nano /etc/netplan/99-static-ip.yaml

    Using a separate file keeps the original installer or cloud image file intact and makes rollback as simple as removing the new file from local console access.

  6. Add the static IPv4 configuration for the selected interface.
    network:
      version: 2
      renderer: networkd
      ethernets:
        enp1s0:
          dhcp4: false
          dhcp6: false
          addresses:
            - 192.0.2.50/24
          routes:
            - to: default
              via: 192.0.2.1
          nameservers:
            addresses:
              - 192.0.2.53
              - 192.0.2.54

    Current Ubuntu examples use routes with to: default for the IPv4 default route. Use the older gateway4 key only on Ubuntu 18.04-era systems that do not understand that route syntax.

    Choose an unused address inside the subnet. Reusing an address already assigned to another device creates intermittent connectivity failures for both hosts.

  7. Restrict the file permissions so Netplan accepts the configuration without a permissions warning.
    $ sudo chmod 600 /etc/netplan/99-static-ip.yaml
  8. Generate backend configuration to catch YAML or Netplan syntax errors before applying the change.
    $ sudo netplan generate

    No output means the files parsed successfully. Fix any reported file and line number before continuing.

  9. Try the configuration with automatic rollback.
    $ sudo netplan try --timeout 120
    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.

    Run this from a console or keep a separate recovery session open. If connectivity drops and the prompt is not confirmed, Netplan attempts to revert after the timeout, but active SSH sessions can still be interrupted.

  10. Apply the confirmed configuration permanently.
    $ sudo netplan apply

    netplan apply regenerates backend configuration and asks the renderer to bring up the configured interfaces.

  11. Verify that the static IPv4 address is active on the interface.
    $ ip -4 address show dev enp1s0
    2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
        inet 192.0.2.50/24 brd 192.0.2.255 scope global enp1s0
           valid_lft forever preferred_lft forever

    valid_lft forever and preferred_lft forever indicate a static address rather than a lease with an expiry timer.

  12. Verify that the default route uses the static interface and gateway.
    $ ip route show default
    default via 192.0.2.1 dev enp1s0 proto static
  13. Verify that the interface has the expected DNS servers.
    $ resolvectl dns enp1s0
    Link 2 (enp1s0): 192.0.2.53 192.0.2.54
  14. Test reachability to the configured gateway.
    $ ping -c 3 192.0.2.1
    PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data.
    64 bytes from 192.0.2.1: icmp_seq=1 ttl=64 time=0.385 ms
    64 bytes from 192.0.2.1: icmp_seq=2 ttl=64 time=0.421 ms
    64 bytes from 192.0.2.1: icmp_seq=3 ttl=64 time=0.398 ms
     
    --- 192.0.2.1 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss
    rtt min/avg/max/mdev = 0.385/0.401/0.421/0.015 ms

    If the gateway responds but external names fail, troubleshoot DNS separately before changing the static address again.

  15. Re-check the address after the next maintenance reboot when persistence must be proven.
    $ ip -4 address show dev enp1s0
    2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
        inet 192.0.2.50/24 brd 192.0.2.255 scope global enp1s0
           valid_lft forever preferred_lft forever

    Schedule the reboot for a maintenance window when the host runs services or carries user traffic.