How to Set Static IP Address on Ubuntu 22.04

Hello folks, in this guide, we will cover how to set static ip address on Ubuntu 22.04 (Jammy Jellyfish) step by step.

There are two ways to configure static ip address on Ubuntu 22.04,

  1. Command line
  2. GUI (Desktop Environment)

From command line we use either nmcli or netplan command to set static ip address.

Set Static IP address using nmcli command

Open the terminal, run following nmcli commands.

To view the existing connection, run

$ nmcli connection show
$ nmcli

nmcli-connection-show-ubuntu

As we can see above, my system has an existing connection named ‘Wired connection 1’ which is using physical nic ‘enp0s3’. In my case, this interface is getting IP address from DHCP server. So, to set the fixed static ip run,

Note: Replace the IP address and connection name as per your environment.

$ sudo nmcli con modify 'Wired connection 1' ifname enp0s3 ipv4.method manual ipv4.addresses 192.168.1.167/24 gw4 192.168.1.1

Add the DNS IP address,

$ sudo nmcli con mod 'Wired connection 1' ipv4.dns 192.168.1.1

Disable & enable the connection, run

$ sudo nmcli con down 'Wired connection 1' && sudo nmcli con up 'Wired connection 1'

Output of above commands would look like below:

nmcli-command-static-ip-address-ubuntu

Now this ip address is persistent across the reboot. To verify ip address run following ip commands,

$ ip add show
$ ip route show

View-IP-Address-Route-Ubuntu

Alternate way to configure static ip address is via netplan utility.

Create ‘01-netcfg.yaml‘ under the directory /etc/netplan with following content,

$ sudo vi /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3: #Change the interface name as per setup
      dhcp4: no
      addresses:
        - 192.168.1.167/24
      routes:
        - to: default
          via: 192.168.1.1
          metric: 100
      nameservers:
        addresses:
          - 192.168.1.1
          - 8.8.4.4

netplan-network-file-ubuntu

Save and close the file.

To make the above changes into the affect, run

$ sudo netplan apply

View the IP address, run

# ip address show

netplan-apply-ip-address-show-ubuntu

Perfect, above confirms that static ip address has been assigned to enp0s3 interface.

Setup Static IP address via GUI (Desktop Environment)

If you are not comfortable with command line, then you can set static ip address from desktop GUI.

From the Desktop Activity –>Search Settings –> Go to Network section

Network-Settings-Ubuntu-Desktop

Click on the gearbox icon then following window will be shown. Select IPv4 Tab,

Automatic-IPv4-Option-Network-Settings-Ubuntu

Change the IPv4 Method from Automatic to Manual. Specify the IP address details along with DNS IP.

Static-IP-address-Desktop-GUI-Ubuntu

Click on Apply to save the changes.

Now disable and enable the interface by toggling the icon.

Disable-Enable-Card-Desktop-GUI

Close the settings window and verify the ip address using following commands

Verify-IP-From-Desktop-Terminal-Ubuntu

That’s all from this guide, I hope you have found it informative. Kindly do post your feedback and queries in below comments section.

Read Also: How to Install Docker on Ubuntu 22.04 / 20.04 (Step by Step)

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

Leave a Comment

4 × 5 =