Setting a Static IP in Ubuntu – Linux IP Address Tutorial
In most network configurations, the router DHCP server assigns the IP address dynamically by default. If you want to ensure that your system IP stays the same every time, you can force it to use a static IP.
That's what we will learn in this article. We will explore two ways to set a static IP in Ubuntu.
Static IP addresses find their use in the following situations:
- Configuring port forwarding.
- Configuring your system as a server such as an FTP server, web server, or a media server.
To follow this tutorial you will need the following:
- Ubuntu installation, preferably with a GUI.
- sudo rights as we will be modifying system configuration files.
How to Set a Static IP Using the Command Line
In this section, we will explore all the steps in detail needed to configure a static IP.
Step 1: Launch the terminal
You can launch the terminal using the shortcut Ctrl+ Shift+t .
Step 2: Note information about the current network
We will need our current network details such as the current assigned IP, subnet mask, and the network adapter name so that we can apply the necessary changes in the configurations.
Use the command below to find details of the available adapters and the respective IP information.
The output will look something like this:
For my network, the current adapter is eth0 . It could be different for your system
- Note the current network adapter name
As my current adapter is eth0 , the below details are relevant.
It is worth noting that the current IP 172.23.199.129 is dynamically assigned. It has 20 bits reserved for the netmask. The broadcast address is 172.23.207.255 .
- Note the subnet
We can find the subnet mask details using the command below:
Select the output against your adapter and read it carefully.
Based on the class and subnet mask, the usable host IP range for my network is: 172.23.192.1 - 172.23.207.254 .
Subnetting is a vast topic. For more info on subnetting and your usable IP ranges, check out this article .
Step 3: Make configuration changes
Netplan is the default network management tool for the latest Ubuntu versions. Configuration files for Netplan are written using YAML and end with the extension .yaml .
Note: Be careful about spaces in the configuration file as they are part of the syntax. Without proper indentation, the file won't be read properly.
- Go to the netplan directory located at /etc/netplan .
ls into the /etc/netplan directory.
If you do not see any files, you can create one. The name could be anything, but by convention, it should start with a number like 01- and end with .yaml . The number sets the priority if you have more than one configuration file.
I'll create a file named 01-network-manager-all.yaml .
Let's add these lines to the file. We'll build the file step by step.
The top-level node in a Netplan configuration file is a network: mapping that contains version: 2 (means that it is using network definition version 2).
Next, we'll add a renderer, that controls the overall network. The renderer is systemd-networkd by default, but we'll set it to NetworkManager .
Now, our file looks like this:
Next, we'll add ethernets and refer to the network adapter name we looked for earlier in step#2. Other device types supported are modems: , wifis: , or bridges: .
As we are setting a static IP and we do not want to dynamically assign an IP to this network adapter, we'll set dhcp4 to no .
Now we'll specify the specific static IP we noted in step #2 depending on our subnet and the usable IP range. It was 172.23.207.254 .
Next, we'll specify the gateway, which is the router or network device that assigns the IP addresses. Mine is on 192.168.1.1 .
Next, we'll define nameservers . This is where you define a DNS server or a second DNS server. Here the first value is 22.214.171.124 which is Google's primary DNS server and the second value is 126.96.36.199 which is Google's secondary DNS server. These values can vary depending on your requirements.
Step 4: Apply and test the changes
We can test the changes first before permanently applying them using this command:
If there are no errors, it will ask if you want to apply these settings.
Now, finally, test the changes with the command ip a and you'll see that the static IP has been applied.
How to Set a Static IP Using the GUI
It is very easy to set a static IP through the Ubuntu GUI/ Desktop. Here are the steps:
- Search for settings .
- Click on either Network or Wi-Fi tab, depending on the interface you would like to modify.
- To open the interface settings, click on the gear icon next to the interface name.
- Select “Manual” in the IPV4 tab and enter your static IP address, Netmask and Gateway.
- Click on the Apply button.
- Verify by using the command ip a
In this article, we covered two methods to set the static IP in Ubuntu. I hope you found the article useful.
What’s your favorite thing you learned from this tutorial? Let me know on Twitter !
You can read my other posts here .
I am a DevOps Consultant and writer at FreeCodeCamp. I aim to provide easy and to-the-point content for Techies!
If you read this far, thank the author to show them you care. Say Thanks
Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started
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.
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.
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.
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,
Run following ip command to view the ip address on interface,
To view the default route, run
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.
10 thoughts on “How to Set Static IP Address on Ubuntu Server 22.04”
How do I use Netplan to set up a static IP address on WIFI?
change the network device “ens33” to something else, it will be listed when you run “ip a”; it;s probably wlan0 but that’s not guaranteed.
there will be a config file for the wifi interface. look for something like 00-installer-config-wifi.yaml
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!
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.
try paste the YAML into here ‘https://www.yamllint.com/’
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
Your article is quite nice and clear! but after followed, following error occurred when ping google.com: “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.
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..
i successfully set up my static ip but I cant ping to 192.168.1.1 why
Leave a Comment Cancel reply
How to Configure Static IP Address on Ubuntu 22.04 LTS and 22.10
Switching from dynamic IP allocation to static IP addresses is easy on Ubuntu 22.04 "Jammy Jellyfish" and 22.10.
The IP addresses of most devices today are generated by Dynamic Host Configuration Protocol (DHCP) servers. A DHCP server assigns a dynamic IP address to your device when it's connected to a network. Thus, you have the chance to change this IP address from time to time.
On the other hand, a static IP refers to a fixed, immutable address, different from dynamic IPs. You can set static IP settings for Ubuntu 22.04 LTS and 22.10 in three different ways. Here's how to get started.
Understanding IP Configuration in Ubuntu
Ubuntu's progression in network management has made configuring settings like the static IP more user-friendly. The feature to set a static IP in Ubuntu 22.04, in particular, has advantages in terms of network efficiency and stability.
Unlike dynamic IPs, which might vary over sessions, a static IP in Ubuntu remains consistent. This is especially advantageous for servers where consistent address recognition is paramount. For these servers, static IP configurations can become a necessity.
While the graphical interface offers a more intuitive way to handle IP configurations, using the static IP command line can offer more precision. For users who want granular control over their network configurations, command-line methods are a preferred choice. By mastering this method, users can ensure optimal Ubuntu IP configuration for their needs.
However, the benefits of a static IP in Ubuntu, especially in the 22.04 version, come with responsibilities. Ensuring that these IPs are correctly set up is crucial, as misconfigurations can lead to network vulnerabilities.
So follow the steps below to configure a static IP address on your Ubuntu machine correctly.
Set a Static IP on Ubuntu With the nmcli Command
It's pretty easy to configure Ubuntu 22.04 static IP settings using the nmcli command . nmcli is a text-based utility used to check the status of the wired connections you are using on your device.
With this command, you can access additional networking information such as your connection status, the name of your host device, and general permissions in your network configuration. If you're aiming to set a static IP on an Ubuntu server, this command proves invaluable.
You can get information about your connection with:
The output of this command will be as follows:
Create a static link with the command given below. Then, manually configure the enp0s3 and ipv4 settings with the appropriate parameters in the nmcli command:
If you use the nmcli connection show command again, you can see that the static link has been added.
After this process, add the static connection you created to the DNS IP:
Now use the command below to activate the connection:
If the output displays "connection successfully activated," you've successfully set up a static IP address on your machine.
You can consider using static IP addresses to avoid connection problems caused by dynamic IP addresses. A static IP address allows you to have a fixed identity and location when connected to the internet.
You can verify the static IP you want to assign to your device by running:
Using netplan for Static IP Settings on Ubuntu
Just like nmcli, another command you can use for setting a static IP on Ubuntu is netplan. You can easily make Ubuntu static IP settings using the netplan command in 22.04 LTS and 22.10 versions. To do this, follow the steps below.
First, find out the name of your network interface using:
What you see here is your network interface name. This name may be different on each device.
Now, create a file named 01-netcfg.yaml in the /etc/netplan folder. Edit it with your favorite text editor.
Add the following lines to the file:
As you can see, you have disabled the DHCP IP setting with the dhcp4: no statement. You've then added the IP address and DNS settings assigned by Google.
After saving this file, run the following to apply the changes:
Configure Static IP Settings on Ubuntu Graphically
The graphical network interface in Ubuntu 22.04 is quite useful if you don't want to use the command line. So much so that you can easily set the Ubuntu static IP address using this interface.
To do this, click on the Network icon in the upper right corner of your desktop. Then, select Wired Settings from the drop-down menu. Click on the Gear icon to open the settings window.
Then, switch to the IPv4 tab in the window that opens.
As you can see, DHCP is enabled by default. Change the IPv4 Method to Manual as you want to use a static IP instead of a dynamic one. Next, change your address, netmask, and gateway settings. Finally, modify your DNS setting and click the Apply button.
You must restart this wired connection for all these actions to take effect. To do this, simply toggle the switch next to the network name on and then off.
Why Should You Use Static IP Addresses on Ubuntu?
You've now understood how to configure a static IP in Ubuntu, especially in the "Jammy Jellyfish" 22.04 LTS version and 22.10, using both graphical and command-line methods with nmcli and netplan.
Due to insufficient IP addresses, some service providers may assign the same address to two different users. In this case, connection problems can occur. Using static IP addresses instead does not cause such problems as it is user-specific, but beware as someone can misuse your IP address in several ways.
How to Configure Static IP Address on Ubuntu 20.04
Mostly when a user connects to a network through WIFI or eternal cable, the DHCP server automatically picks and assigns IP addresses to the system. Here the downside is that once the lease time of DHCP expires, another IP address is assigned to the system.
Such changes might cause disconnection of the system and due to this it’s recommended to set static IP addresses to the system so that the ip addresses do not change even when the lease time has expired. In this guide, we’ll tell you about how to configure a static IP address on Ubuntu 20.04.
Static IP Configuration on Ubuntu Server
The Ubuntu system uses predictable network interfaces names to identify the interfaces of the network. Firstly, to set up a static IP address we need to identify the name of the interface that we want to configure. For this we will use “ ip_link ”.
This will print out all the available network interfaces such as “ enp0s3 ” that we’ll configure.
Netplan is used as a default network management tool by Ubuntu and its files are written using YAML syntax with extension of “ .yaml ”. In order to configure the interface with Netplan a yaml description is needed to be created and the required configuration files for that particular render tool will be generated by Netplan.
Configuration file of Netplan is stored in “ /etc/netplan ”. Here there might be some YAML files with the names “ 01-netcfg.yaml ”, “ NN_interfaceName.yaml ” or “ 50-cloud-init.yaml ”, but they differ in each system.
Now, we need to disable cloud instances just in case your Ubuntu is provisioned with cloud-init.
This will open the file, in it write the following.
Now, we need to assign an IP address and for this open the configuration file of the YAML file.
This will open the configuration file in which you need to add the following:
Here you need to understand some key points:
- Each YAML file of Netplan is supposed to start with “ network ”.
- Networks contain a minimum two elements.
- Here, the first element is the network configuration format’s version.
- Second element is device type which can be ethernets, VLANS or bridges.
- Renders: Incase ubuntu was installed in server mode, render use networkd as back end.
In this under ethernets you can define various interfaces. We defined “enp0s3” that obtains an IP address from dhcp4. Now, in order to assign “enp0s3” an IP address which is static we will edit the file:
- Set no to dhcp4 which is a DHCP server.
- Give a static IP address using addresses: and provide one or more IPv4 or IPv6.
- Specify gateway
- Set the IP address of nameserver under nameservers .
After this save the file and run the below command in order for the changes to apply.
Now after everything is completed, verify the changes using the command provided below.
That’s all, you’ve successfully provided a static IP address to your Ubuntu server.
The easiest way to assign a static IP address is through Ubuntu Desktop as you do not need any technical knowledge as well as no worry about syntax. All you’ve to do is select Settings and go to the Network or WiFi tab. Select the cog icon next to the interface and go to IPv4 tab and there select manual and provide IP address.
After this select Apply and in order to verify run the command below.
In this you can directly assign a static IP address through Ubuntu Desktop as well as through the command line.
Assigning static IP addresses is beneficial as the IP address won’t change even when the lease has expired. This can be done through various ways. In this guide we showed you how to assign static IP addresses through Ubuntu server as well as through Desktop.
Personally the easiest way is through Desktop as it doesn’t require a lot of technical knowledge and involves just a few steps. Now following this guide you can assign a static IP address to your system.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY
Setting a Static IP Address on Ubuntu Server 22.04
- #Ubuntu Server
Ubuntu Server 22.04 uses a utility called ‘netplan’ for networking. To set a static IP we need to edit the config file.
In the terminal, go to the netplan config file location:
The file should be called 00-installer-config.yaml . To edit it we need to run nano as root so we can make changes to it.
The static IP config should look similar to this:
- eth0: is the name of my network interface - yours may differ.
- Under addresses: is the static IP to set, you’ll need to use CIDR notation, so /24 is 255.255.255.0 .
- DNS servers are configured under nameservers: multiple servers should be command separated.
- The default gateway is set under routes: and - to: default .
Save the file with CTRL + O and press enter to overwrite the existing file. Exit with CTRL + X
To apply the changes run the following command:
To confirm the settings, run the following to see the current IP:
run the following to see the default gateway:
And now you know, and knowing is half the battle.
Support My Work
If you would like to support me, please check out the links below.
If you have any questions or comments please leave them below.
- Deploy Windows 10 22H2 Reference Image
- Build and Capture Windows 10 22H2 Reference Image
- Restore The Legacy Context Menu in Windows 11
- Deploy Windows 11 22H2 Reference Image
- Build and Capture Windows 11 22H2 Reference Image
Configure Static IP Address on Ubuntu 20.04 (Server CLI and Desktop)
In your IT environment, sometimes you may be compelled to configure a static IP instead of relying on the DHCP protocol. A perfect example is when you are setting up a Ubuntu server to act as a file or a web server for your organization. A static IP, as the name suggests, ensures that the IP address of your system remains unchanged. With DHCP, the IP address changes once the lease time for the IP address expires and this is undesirable for servers.
In this guide, we will explore two ways of manually assigning a static IP on Ubuntu 20.04. We will demonstrate how you can configure a static IP on an instance of Ubuntu server and Ubuntu desktop.
Assign a static IP on Ubuntu server 20.04
From Ubuntu 17.10 and later versions, networking is controlled by the Netplan feature. The configuration files for Netplan are located in the /etc/netplan directory and are written in YAML. Inside this directory, you will find YAML configuration files labeled either 50-cloud-init.yaml , or 00-installer-config.yaml .
However, If you are running a cloud instance of Ubuntu, chances are that it is managed by cloud-init which auto-assigns it an IP address by leveraging the DHCP protocol. Before we proceed further, you need to disable cloud-init. To achieve this, open the subiquity-disable-cloudinit-networking.cfg cloud-init configuration file in the /etc/cloud/cloud.cfg.d/ directory
Set the ' network ' directive to ' disabled '.
Save the changes and quit. Next, head over to the Netplan configuration file. In my case, I have the 00-installer-config.yaml file.
From the configuration file, we can see the ' network' directive that has 2 elements. The first one is the ' ethernets ' which specifies the network interface and the second one is the version of the renderer which is ' systemd-networkd ' for non-GUI instances and NetworkManager for Ubuntu desktop ( With GUI )
We are going to set the ' dhcp4 ' value to ' no ' to disable the DHCP protocol and specify the interface's Static IP as follows.
To assign a static IP address to ens3 interface, modify the file as follows:
- Specify the static IP address of the server. in the addresses : section, specify an IPv4 address to be assigned to the network interface.
- Next, Specify the gateway.
- Under nameservers , specify the DNS or IP addresses of the nameservers. Here, we have specified Google's DNS which is 188.8.131.52 and the Router's IP.
Save the YAML file and exit. To apply the changes made, run the command:
You can use the ifconfig or ip command to verify that your network interface is set to use the static IP configured moments ago.
Additionally, you can use the IP route show command to display the new routes on your system.
Perfect! We have successfully configured a static IP on the Ubuntu server. Let's now switch gears and see how you can replicate the same on Ubuntu Desktop 20.04
Configure Static IP on Ubuntu 20.04 Desktop
If you are running a Desktop GUI, then configuring a static IP should be quite easy. Click on the ' Network icon ' at the top right corner of your screen and select the 'Wired Settings ' option.
This opens the 'Network ' configuration page. In the 'Wired ' section, click on the gear wheel icon.
This displays a summary of your current IP configuration. By default, the system obtains its IP configuration via the DHCP protocol. We will change from using DHCP to Manual.
So, click on the ' IPv4 ' tab which directs you to this section. As anticipated, DHCP is turned on.
Switch from ' Automatic (DHCP) ' to ' Manual '. Then specify the static IPv4 address including the netmask, gateway, and DNS servers. To save the changes, click on the ' Apply ' button.
Head back to the ' Network' section and restart the networking service by toggling off and on.
Once again, click on the gear wheel icon and confirm that the static IP settings have reflected.
And it's as simple as that. We have successfully configured a static IP on Ubuntu Desktop.
Ubuntu, like most other systems, comes configured with DHCP to obtain an IP from the DHCP server, or router. In this guide, we have covered how you can apply static IP settings on command-line and using the GUI. Before setting a static IP, it's always recommended to reserve the IP that you want to assign to your server on the router. Equally important is to ensure that no other client system is using that IP address to avoid an IP conflict.
If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks
Sorry about that.
About The Author
James Kiarie is a skilled and certified LPIC Linux administrator with a strong passion for technical writing, specializing in the Linux domain. With over four years of experience, he has crafted numerous technical guides, helping a wide audience navigate through various Linux distributions.
Nmap to Scan Open Ports – Examples + Screenshots
How to List Network Interfaces in Linux
How to Get IP address in Linux
How to Permanently add Static Route in Linux
Ping IPv6 Address from Windows and Linux CLI
How to Check Ports in Use in Linux (Listening Ports)
Tshark Examples with Cheat Sheet
How to Learn Linux – A Master Guide
13 Modern Alternatives to Linux Commands
Basic Linux Commands You Should Know
14 Command Line Tools to Check CPU Usage in Linux
13 Cool Things to Do with Linux
Leave a Reply
Leave a comment cancel reply.