Assign a Static IP Address to an Ubuntu Server

Modern Ubuntu server releases use netplan to manage their network settings. In this post, you will update your Ubuntu server to have a static IP address. This would be a first step in building a new server since it assures communication even when other services, such as DHCP may not be available.

0 . Latest updates and prerequisites.

2025.09.14 – Updated for Ubuntu 24.04 Server.

Check back for updates, if you run into trouble. Leave a comment if the post is missing some detail.

You need sudo or root access, at minimum, to change the IP network settings.

1 . Check current settings.

With a default installation, the server is often using DHCP to get IP settings. If you check your server’s current settings, you can verify the name of the adapter as well as some other details you may need for this task. First, get the name of the active network adapter with “ip a”:

admin@server40:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  inet 127.0.0.1/8 scope host lo
  valid_lft forever preferred_lft forever
  inet6 ::1/128 scope host
  valid_lft forever preferred_lft forever
2: eno1: mtu 1500 qdisc fq_codel state UP group default qlen 1000
  link/ether 00:22:4d:6a:d8:30 brd ff:ff:ff:ff:ff:ff
  altname enp0s25
  inet 172.16.30.129/24 metric 100 brd 172.16.30.255 scope global dynamic eno1
  valid_lft 690809sec preferred_lft 690809sec
  inet6 fe80::222:4dff:fe6a:d830/64 scope link
  valid_lft forever preferred_lft forever

From this output, you can see the network card name is “eno1” as this is the network card with a valid IP configuration. Now query netplan to see what the DHCP client values are for that adapter with “netplan ip leases <network card name>”:

admin@server40:~$ netplan ip leases eno1
#This is private data. Do not parse.
ADDRESS=172.16.30.129
NETMASK=255.255.255.0
ROUTER=172.16.30.1
SERVER_ADDRESS=172.16.30.30
T1=345600
T2=604800
LIFETIME=691200
DNS=172.16.30.30
DOMAINNAME=home.domain
CLIENTID=ffb6691d9b

The output tells you what the DHCP client services see as a valid network configuration. This information is useful to change the IP address as you will need it for the new netplan configuration.

The default netplan configuration is set in a yaml file created by the Ubuntu installer. On Ubuntu 24.04 servers, this is /etc/netplan/00-installer-config.yaml. You can “cat” this file to check its contents to be sure:

admin@server40:~$ cat /etc/netplan/00-installer-config.yaml
#This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      dhcp4: true
  version: 2

Notice the indentations in the file, this indentation is important to preserve. This file shows no configuration other than DHCP for IPv4, for the active adapter, eno1. You are going to change this now to a static address and add some detail if needed.

2 . Update the yaml file.

You need to backup the file first, just to be sure, by copying it to another location so that it is not additionally read during the network service restart:

admin@server40:~$ cp /etc/netplan/00-installer-config.yaml ~/00-installer-config.yaml.bak

The tilde symbol, “~” is short-hand for the current user’s home folder.

Based on information from the previous step, update your IP settings to a fixed address using the DNS and gateway settings of this network by modifying the yaml file, done here with the “nano” editor as sudo.

The values for the static configuration are known to you or given to you by a network administrator. They must be valid for the network in which this server will reside:

sudo nano /etc/netplan/00-installer-config.yaml

Yaml files are particular about indentations, make sure the formatting is perfect, then save the file and exit the editor. Substitute the values, in this file, to settings that work for your server’s current network:

network:
  version: 2
  ethernets:
    eno1:
      dhcp4: no
      dhcp6: no
      addresses:
        - 172.16.30.40/24
      routes:
        - to: default
          via: 172.16.30.1
      nameservers:
        addresses:
        - 172.16.30.30
        - 172.16.30.31
        search:
        - home.domain

Make sure the editing and indentation is perfect.

Apply appropriate permissions to the configuration file:

admin@server40:~$ sudo chmod 600 /etc/netplan/00-installer-config.yaml

The new settings are not taken automatically, netplan must be applied, first.

3 . Check, then update the server.

Use “netplan generate”, as sudo, to check and save the configuration. This netplan option will alert to any syntax errors in the yaml file:

admin@server40:~$ sudo netplan generate
/etc/netplan/00-installer-config.yaml:16:7: Error in network definition: unknown key 'search'
    search:
    ^

As above, in the first attempt, the indentation was not correct. Once all errors are resolved, run the netplan generate command again, to be sure the syntax is perfect, then the configuration can be applied with the “netplan apply” option. At that point, the new configuration is applied and connectivity might be lost if the address is changing:

admin@server40:~$ sudo netplan apply

4 . Test the new settings.

Create a console connection to the new IP address and login again, then check the running configuration with “ip a”:

admin@server40:~$ ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  inet 127.0.0.1/8 scope host lo
  valid_lft forever preferred_lft forever
  inet6 ::1/128 scope host
  valid_lft forever preferred_lft forever
2: eno1: mtu 1500 qdisc fq_codel state UP group default qlen 1000
  link/ether 00:22:4d:6a:d8:30 brd ff:ff:ff:ff:ff:ff
  altname enp0s25
  inet 172.16.30.40/24 brd 172.16.30.255 scope global eno1
  valid_lft forever preferred_lft forever
  inet6 fe80::222:4dff:fe6a:d830/64 scope link
  valid_lft forever preferred_lft forever

As you can see, the new network configuration is taken. You cannot check the configuration with the “ip leases” option used above because the network card is no longer running as a DHCP client.

You can check the DNS settings are correct with “resolvectl status”, this lists the running DNS configuration:

admin@server40:~$ resolvectl status
Global
    Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
    resolv.conf mode: stub
    Link 2 (eno1)
  Current Scopes: DNS
    Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  Current DNS Server: 172.16.30.30
    DNS Servers: 172.16.30.30 172.16.30.31
    DNS Domain: home.domain

And of course the DNS capability can be tested by first “ping”-ing a hostname on your network (to check if the search functionality is working), then “ping”-ing a public service to check if the gateway, nameservices and network settings all work altogether:

admin@server40:~$ ping server30
PING server30.home.domain (172.16.30.30) 56(84) bytes of data.
64 bytes from server30.home.domain (172.16.30.30): icmp_seq=1 ttl=128 time=0.204 ms
--- server30.home.domain ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.204/0.204/0.204/0.000 ms
...
localadmin@server40:~$ ping google.com
PING google.com (142.251.36.206) 56(84) bytes of data.
64 bytes from muc12s12-in-f14.1e100.net (142.251.36.206): icmp_seq=1 ttl=119 time=8.16 ms
--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 8.162/8.162/8.162/0.000 ms

To ping a remote host by name requires that DNS, the IP stack itself and routing all work together.

If all of this works, you have successfully set an Ubuntu server to have a static IP address.

In some cases, search domains do not work well and a manual entry must be made to /etc/systemd/resolved.conf. Use an editor such as nano and un-comment the line “domains” to have the search domain, such as this:

# FallbackDNS=
Domains=home.domain
# DNSSEC=no

The above steps only cover IPv4. If you want to configure a yaml file for a dual stack IP network and multiple network cards, your server’s yaml file will look like this:

network:
    version: 2
    ethernets:
        eth0:
            accept-ra: false
            addresses:
            - 2A03:B0C0:0003:1234:1234:1234:15F3:B001/64
            - 167.172.144.79/20
            - 10.19.0.5/16
            match:
                macaddress: da:16:ff:a6:12:ff
            mtu: 1500
            nameservers:
                addresses:
                - 67.207.67.3
                - 67.207.67.2
                search: [mydomain.com]
            routes:
            -   to: ::/0
                via: 2a03:b0c0:3:d0::1
            -   to: 0.0.0.0/0
                via: 167.172.160.1
            set-name: eth0
        eth1:
            addresses:
            - 10.135.88.123/16
            match:
                macaddress: 32:07:23:91:99:51
            mtu: 1500
            nameservers:
                addresses:
                - 67.207.67.3
                - 67.207.67.2
                search: [myotherdomain.com]
            set-name: eth1

Of course, the values should match the network in which the server will reside. If you do not know the IP address values, you need to speak to the network administrator, check your modem/router or use the DHCP client, as above.

5 . Supporting this blog.

This type of content takes a lot of effort to write. Each post is drafted, researched, then tested multiple times, even a simple step or detail might take more than a few hours to go from the idea to a published blog post.

If you feel I have saved you some time, you can support me by;

  • buying me a beer through PayPal – PayPal.

© HorseFreeGlue, 2025. Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited.

Leave a Reply 0

Your email address will not be published. Required fields are marked *

two × four =