On Ubuntu (version 22.04, 21.04, or older releases), it’s possible to assign a static IP address through the Settings interface or the Terminal using commands, and in this guide, you will learn how.
Once you complete the installation of the Ubuntu Server (or client version), the device will receive a network configuration assigned automatically by the Dynamic Host Configuration Protocol (DHCP) server available in the local network. Although this configuration is enough to access the network and internet, it’s a good idea to assign a static network configuration as you probably are setting up the system to serve different services, such as file and print sharing and others.
The reason is that a dynamic configuration can change at any time, and a static network configuration is permanent, meaning that devices in the network will be able to always reach the server with the address.
This guide will teach you the steps to configure a static IP address for your Ubuntu Server installation. You can also use these instructions for the client version of the Linux distro.
- Set static IP address configuration on Ubuntu Linux (GUI)
- Set static IP address configuration on Ubuntu Linux (command)
Set static IP address configuration on Ubuntu Linux (GUI)
To assign a static IP address on Ubuntu (server or client) through the Settings app, use these steps:
-
Open Settings.
-
Click on Network.
-
Click the Settings button for the “Wired” network interface.
-
Click the IPv4 tab.
-
Select the Manual option for the “IPv4 Method” setting.
-
Under the “Addresses” section, confirm the static IP address in the “Address” setting — for example, 10.1.4.201.
-
Confirm the subnet mask in the “Netmask” settings — for example, 255.255.255.0.
-
Confirm the gateway address (usually the router’s IP) in the “Gateway” setting.
-
Turn off the Automatic toggle switch for the “DNS” setting.
-
Confirm the DNS address(es) for this static configuration — for example, the router IP address or your preferred DNS address, such as the ones from Google Public DNS, 8.8.8.8, 8.8.4.4.
Quick note: You have to use a comma (,) to separate multiple addresses. -
(Optional) Click the IPv6 tab.
-
Select the Disable option in the “IPv6 Method” setting.
-
Click the Apply button.
-
(Optional) Turn off and on the Wired toggle switch on the “Network” page if the configuration isn’t working.
Once you complete the steps, the Linux distro will start using the new static network configuration.
Set static IP address configuration on Ubuntu Linux (command)
To assign a static IP address on Ubuntu Linux (server or client), use these steps:
-
Open Terminal
-
Type the following command to determine the network interface name and press Enter:
sudo ip a
-
Type the following command to open the configuration file and press Enter:
sudo nano /etc/netplan/01-network-manager-all.yaml
-
Copy and paste the following configuration (changing the TCP/IP settings with your settings):
network: renderer: networkd ethernets: ens33: addresses: - 10.1.4.201/24 nameservers: addresses: [8.8.4.4, 8.8.8.8] routes: - to: default via: 10.1.4.1 version: 2
In the command, change “ens33” for the name of your server network adapter name and “10.1.4.201/24” for the static IP address and subnet mask after the forward slash (/) you want to assign to the Ubuntu Server. For example, the “/24” assigns the “255.255.255.0” address. Also, change “8.8.4.4, 8.8.8.8” for static DNS addresses. The comma (,) is only required when setting up multiple addresses. And change “10.1.4.1” for the default gateway of your network (usually the router IP address).
-
Press “Ctrl + O,” “Enter,” and “Ctrl + X” to save the changes and exit the text editor.
-
Type the following command to apply the new static IP address configuration and press Enter:
sudo netplan apply
-
(Optional) Type the following command to confirm the static network configuration and press Enter:
ip addr show ens33
In the command, change “ens33” to the name of the adapter.
After you complete the steps, the static IP address configuration will apply to the network adapter on Ubuntu (server or client).