How to Set Static IP Address on Ubuntu Server 22.04

In this post, we will cover how to set static ip address on Ubuntu server 22.04.

It is highly recommended to have a static ip on linux server because it would be persistent across the reboot. Static IP plays an important role for servers like Mail Server, Web Server and File server etc.


  • Minimal Installed Ubuntu Server 22.04
  • Regular User with sudo admin rights

In Ubuntu server 22.04, networking is controlled by netplan utility, so we will use netplan to configure static ip address on Ubuntu server.

Note: we cannot use nmcli utiltity as it is not the part of default installation on Ubuntu server.

Setting up Static IP address on Ubuntu Server 22.04

Login to your Ubuntu server 22.04, look for the netplan configuration file. It is located under /etc/netplan directory.

$ cd /etc/netplan/
$ ls -l
total 4
-rw-r--r-- 1 root root 116 Oct 12 04:03 00-installer-config.yaml

Run below cat command to view the contents of ‘00-installer-config.yaml’

Note: Name of configuration file may differ as your per setup. As it is an yaml file, so make sure to maintain the indentation and syntax while editing.

$ cat 00-installer-config.yaml



As per above output, it says that we have ens33 interface and it is getting ip from dhcp server. Alternate way to view interface name is via ip command.

Now, to configure static ip in place of dhcp, edit netplan configuration file using vi or nano editor and add the following content.

$ sudo vi 00-installer-config.yaml
# This is the network config written by 'subiquity'
  renderer: networkd
        addresses: [,]
        - to: default
  version: 2

save and close the file.


In the above file we have used following,

  • ens33 is the interface name
  • addresses are used to set the static ip
  • nameservers used to specify the DNS server ips
  • routes used to specify the default gateway

Note: Change the IP details and interface name as per your environment.

To make above changes into the effect the apply these changes using following netplan command,

$ sudo netplan apply

Run following ip command to view the ip address on interface,

$ ip addr show ens33

To view the default route, run

$ ip route show

Output of above commands,


Perfect, above commands’ output confirms that static ip and route has been configured successfully.

That’s all from this post. Kindly do post your queries and feedback in below comments section.

11 thoughts on “How to Set Static IP Address on Ubuntu Server 22.04”

  1. Hey! thanks I had problems before setting up the DNS and none config would work!
    This one did and you made this post really simple to follow!

  2. Your text for configuring a static IP address does not work in my Ubuntu 20.04.5 server’s NIC. No matter how I space or tab the indentations, I get “Ivalid YAML: inconsistent indentation: addresses:

    I’ve been at the problem for a couple of weeks, with no fix in site; no spacing or tabbing change I make fixes it. Can anyone please advise me? Thanks.

    • Copy paste not work here, you should try typing instead or if you paste, try to delete all the space before each line and tab key until the same format

    • The spacing must be done with the space key. If you try to make spaces in a yaml file with the tab key it will not work.
      Also you should let correct the file for you

  3. Your article is quite nice and clear! but after followed, following error occurred when ping
    “temporary failure in name resolution”, meanwhile localhost can be visited. Is anyone facing this issue as well? I’ll quite appreciate it if can get some advise.

  4. can we use default DHCP ip configuration along with another static ip in ubuntu 22.04 ?
    i already have ens33 then i added eth0 as static ip , netplan apply did not thrown any errors but unable to see my static ip , when i do ifconfig 🙁
    even after reboot its not applying, any suggestions..


Leave a Comment