How to Set a Static IP Address On Ubuntu 22.04 – Holhol24

0

The first task anyone would do after installing Ubuntu is setting an IP address to a system to connect to the network/internet. If the Wi-Fi router, ISP, or network doesn’t provide DHCP services, you must manually assign IP addresses.

Here, we will see how to set a static IP Address on Ubuntu 22.04, using,

You can use any method to set a static IP address on Ubuntu 22.04.

Find Network Interfaces on Ubuntu 22.04

You can run any of the below commands in a terminal to get a list of network interfaces available on the system.

sudo ifconfig -a

OR

sudo ip a

The output of the ifconfig command on a desktop:

enp0s3: flags=4163  mtu 1500
        ether 08:00:27:36:34:ae  txqueuelen 1000  (Ethernet)
        RX packets 226971  bytes 327928478 (312.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 60417  bytes 4869126 (4.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 4714  bytes 6158753 (5.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4714  bytes 6158753 (5.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

The output of the ifconfig command on a laptop:

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 188  bytes 13462 (13.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 188  bytes 13462 (13.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlo1: flags=4163  mtu 1500
        ether 7c:8b:ca:0d:69:b6  txqueuelen 1000  (Ethernet)
        RX packets 972  bytes 346365 (346.3 KB)
        RX errors 0  dropped 465  overruns 0  frame 0
        TX packets 426  bytes 66875 (66.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Here, we will see how to configure a static IP for enp0s3 (Wired) / wl01 (Wi-Fi).

IP Address: 192.168.0.10
Netmask: 255.255.255.0
Gateway: 192.168.0.1
DNS Server 1: 192.168.0.1
DNS Server 2: 8.8.8.8
Domain Name: holhol24.local

Set Static IP Address on Ubuntu 22.04 Desktop

1. Using GNOME Network Manager

Using the GNOME network control center to set a static IP address on In Ubuntu 22.04 desktop is straightforward.

Set IP for Wired Interface using GNOME

Open the Gnome control center using the gnome-control-center network command or go to Activities >> Settings >> Network.

Click on the gear icon on the Wired interface page and then IPv4 tab >> Manual >> Enter IP address, Netmask, Gateway, DNS (Toggle to disable Automatic DNS configuration) >> Apply.

Set IP for Wired Interface

Finally, use the toggle in the Network page to disable and enable the network interface to apply the IP address.

Set IP Address for Wi-Fi using GNOME

Open the Gnome control center using the gnome-control-center wifi command or go to Activities >> Settings >> Wi-Fi.

Click on your Wifi router name and then enter the router’s password to connect. Your laptop will automatically receive an IP address from a Wi-Fi router with a built-in DHCP service on a successful connection.

Wi-Fi Access Points How to Set a Static IP Address On Ubuntu 22.04 - Holhol24 How to Set a Static IP Address On Ubuntu 22.04 – Holhol24 svg xml  3Csvg 20xmlns 3D 22http 3A 2F 2Fwww
Wi-Fi Access Points

To assign a static IP address or Wi-Fi interface, click on the gear icon on the Wi-Fi interface page and then IPv4 tab >> Manual >> Enter IP address, Netmask, Gateway, DNS (Toggle to disable Automatic DNS configuration) >> Apply.

Set IP for Wired Wi-Fi How to Set a Static IP Address On Ubuntu 22.04 - Holhol24 How to Set a Static IP Address On Ubuntu 22.04 – Holhol24 svg xml  3Csvg 20xmlns 3D 22http 3A 2F 2Fwww
Set IP for Wired Wi-Fi

Finally, disable and enable the Wi-Fi interface to apply the IP address.

2. Using Netplan

Netplan is a utility for easily configuring networking on a Ubuntu system. It reads the configuration files .yaml present in the /etc/netplan directory.

This utility supports both networkd and Network Manager as backends. However, using Network Manager as a backend renderer: NetworkManager is recommended for the Ubuntu desktop. The remaining configurations are the same as that of the networkd.

3. Using NetworkManager CLI

Set IP for Wired Interface using nmcli

First, let us list the available network connections.

nmcli connection show

Output:

NAME                UUID                                  TYPE      DEVICE
Wired connection 1  db3b0cfc-d875-3a71-86c4-626adfc5834a  ethernet  enp0s3

Then, configure static IP address to wired interface.

sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.0.10/24

sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.0.1

sudo nmcli con mod "Wired connection 1" ipv4.dns "192.168.0.1","8.8.8.8"

sudo nmcli con mod "Wired connection 1" ipv4.method manual

sudo nmcli con mod "Wired connection 1" ipv6.method disabled

Finally, run the below commands to apply the IP address.

sudo nmcli con down "Wired connection 1" && sudo nmcli con up "Wired connection 1"

Set IP Address for Wi-Fi using nmcli

First, list the available Wi-Fi access points using the below command.

nmcli device wifi

Output:

IN-USE  BSSID              SSID        MODE   CHAN  RATE        SIGNAL  BARS  SECURITY  
        BA:DD:71:A3:D9:A4  Raj         Infra  6     270 Mbit/s  100     ▂▄▆█  WPA2

Next, connect to the Wi-Fi access point.

nmcli device wifi connect Raj password MyPass ifname wlo1 name My-Wifi

And then, configure static IP address to Wi-Fi interface.

sudo nmcli con mod "My-Wifi" ipv4.addresses 192.168.0.10/24

sudo nmcli con mod "My-Wifi" ipv4.gateway 192.168.0.1

sudo nmcli con mod "My-Wifi" ipv4.dns 192.168.0.1

sudo nmcli con mod "My-Wifi" ipv4.method manual

sudo nmcli con mod "My-Wifi" ipv6.method disabled

Finally, run the below commands to apply the IP address

sudo nmcli con down "My-Wifi" && sudo nmcli con up "My-Wifi"

Set Static IP Address Using NetPlan on Ubuntu 22.04 Server

Netplan is a network configuration utility that reads YAML files and generates all network configurations for the renderer tool (NetworkManager or networkd) to configure the network on a system.

Netplan configuration files are found in the /etc/netplan/ directory.

Remove any configuration files .yaml present in the /etc/netplan directory.

sudo rm -rf /etc/netplan/*

Set IP for Wired Interface using Netplan

Now, create a new netplan configuration for the wired network interface.

sudo nano /etc/netplan/01-wired-interface-1.yaml

Then, make changes to the below information and use it for your requirement.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.0.10/24
      routes:
        - to: default
          via: 192.168.0.1
      nameservers:
        addresses:
          - 192.168.0.1
          - 8.8.8.8
        search:
          - holhol24.local

And then generate the required configuration for the renderers.

sudo netplan generate

Finally, apply all network configurations and restart renderers.

sudo netplan apply

Set IP Address for Wi-Fi using Netplan

Wi-Fi Interface Name: wl01
Wireless Access Point Name: Raj
Wireless Access Point PasswordMyPass

First, create a new netplan configuration for the wired network interface.

sudo nano /etc/netplan/01-wireless-interface-1.yaml

Then, make changes to the below information and use it for your requirement.

network:
  version: 2
  renderer: networkd
  wifis:
     wlo1:
        dhcp4: no
        dhcp6: no
        addresses: 
          - 192.168.0.10/24
        routes: 
          - to: default
            via: 192.168.0.1
        nameservers:
          addresses: 
             - 192.168.0.10
             - 8.8.8.8
          search: 
             - holhol24.local
        access-points:
          Raj:
            password: MyPass

And then generate the required configuration for the renderers.

sudo netplan generate

Finally, apply all network configurations and restart renderers.

sudo netplan apply

Verify Static IP Address on Ubuntu 22.04

Verify the static IP address using the below commands.

sudo ifconfig -a

OR

sudo ip a

Output:

enp0s3: flags=4163  mtu 1500
        inet 192.168.0.10  netmask 255.255.255.0  broadcast 192.168.0.255
        ether 08:00:27:81:43:e1  txqueuelen 1000  (Ethernet)
        RX packets 1684  bytes 1211790 (1.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1004  bytes 140357 (140.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 549  bytes 44488 (44.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 549  bytes 44488 (44.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Also, verify the DNS server’s entries.

sudo resolvectl status

Output:

Global
       Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub

Link 2 (enp0s3)
    Current Scopes: DNS
         Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.0.1
       DNS Servers: 192.168.0.1 8.8.8.8
        DNS Domain: holhol24.local

Conclusion

That’s All.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More