In this article, we are going to learn how to configure a static IP address on Ubuntu 22.04. Typically, in most network configurations, the IP address is assigned dynamically by the router’s DHCP server. Setting a static IP address may be required in different situations, such as configuring port forwarding or running a media server or other service which is needed a static IP address.
Prerequisites
- Ubuntu system
- User with Sudo privileges
In this tutorial you will learn how to:
- Set the static IP address on Ubuntu Desktop using a NetworkManager
- Configure the static IP address on the Ubuntu server via the network daemon
Static IP Address on Ubuntu
There are two ways to configure static IP addresses on Ubuntu.
- GUI Interface Mode
- Command Linux Interface Mode
GUI Interface Mode
The simplest approach how to configure a static IP address on Ubuntu Desktop is via GNOME graphical user interface:
Go to Settings > Network > Click on the Setting icon. Click on IPv4 > Select the manual option. And then enter your static IP address.
Command Linux Interface Mode
To configure a static IP address on your Ubuntu server you need to modify a relevant netplan network configuration file within the /etc/netplan/ directory.
To set your network interface enp0s3 to static IP address 192.168.1.233 with gateway 192.168.1.1 and DNS server as 8.8.8.8 and 8.8.4.4 replace the above configuration with the one below.
# This file is generated from information provided by # the datasource. Changes to it will not persist across an instance. # To disable cloud-init's network configuration capabilities, write a file # /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: # network: {config: disabled} network: version: 2 renderer: networkd ethernets: ens33: dhcp4: no addresses: [192.168.3.3/24] gateway4: 192.168.3.1 nameservers: addresses: [8.8.8.8,8.8.4.4]
Ubuntu server configured with the static IP address. Now you can deploy any service over here.
Once ready apply changes with:
$ sudo netplan apply
In case you run into some issues execute:
$ sudo netplan --debug apply
Conclusion
That is all! In this article, you have learned about static IP addresses on the Ubuntu system. Now you can easily change your IP address if you do not want the DHCP server IP address. All the commands and procedures described in this article are also valid for Debian, Mint, and previous Ubuntu releases.