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 8.8.8.8 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.
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.
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How do I set a static IP in Ubuntu 20.04.3 LTS?
I'm trying to set up a lab computer as a ssh server following this guide . One of the steps is setting up a static IP address. So, I was glad to find this answer . Following it, I created /etc/netplan/50-cloud-init.yaml file, pasted
where my_ethernet_num == enp9s0 . Buuuut, after this ip a showed no ip address for the Ethernet:
and sudo lshw -C network yielded *-network DISABLED . Then I tried to use that guide (section 'Static IP Address Assignment'). I created /etc/netplan/99_config.yaml , pasted the necessary code, run sudo netplan apply . Nothing changed except that I STOPPED SEEING wired connections in network settings... I tried the answer from here , and the 'Wired' section returned. But I can't change anything (for example, I can't pick 'Manual' option).
So, the questions are: how can I return the ability of changing it (in order to follow one more guide ), or is there any other solution that will succeed in setting static ip address?...
--EDIT from 12/05/2021--
Here are all of my .yaml files showed by ls -al /etc/netplan :
01-network-manager-all.yaml:
50-cloud-init.yaml:
99_config.yaml:
- network-manager
- 1 Probably you should delete/revert all changes that you have made, to get back to the original configuration. Then just use "Manual" option from the GUI. No need to mess with configuration files manually. – raj Nov 29, 2021 at 12:44
- @raj, thank you for your comment! If I only knew how to revert all the changes... By the way, after rebooting, I suddenly found out that I can make changes to the settings! So, I'll try the the GUI option and write about results :) – TopCoder2000 Nov 29, 2021 at 13:31
- Why does your .yaml use enp0s3, when your interface is enp9s0? Are you using a Server or Desktop installation? – heynnema Nov 29, 2021 at 23:37
- @heynnema, because it was in the answer for 'How do I set a static IP in Ubuntu?' . As we can see, enp0s25 is used in the question, but then enp0s3 is used in the answer, so I thought that it always must be enp0s25. > Are you using a Server or Desktop installation? I would like to use a Desktop installation, but I don't know concretely which one I was using... Is there any difference? I tried to follow Desktop installation but I could get confused. – TopCoder2000 Dec 1, 2021 at 19:31
- @TopCoder2000 Your network can't possibly be working with enp0s3 in the .yaml file. It needs to be enp9s0. But if you're using a Desktop installation, then your .yaml is all wrong anyway. A Desktop installation has a GUI, a Server installation is CLI only. Also, your self-accepted answer doesn't really make a lot of sense. – heynnema Dec 1, 2021 at 19:37
Pick ONE of the following two configurations...
Server installation with static IP...
Delete /etc/netplan/01-network-manager-all.yaml
Delete /etc/netplan/50-cloud-init.yaml
Edit /etc/netplan/99_config.yaml to look EXACTLY like this...
Note : regarding 192.168.0.116, make sure this address is outside of the DHCP range set in your router, and is not already used elsewhere.
Note : For DNS nameservers, settle on servers from one source... Google, Cloudflare, OpenDNS, etc. (3 max).
sudo netplan generate
sudo netplan apply
Desktop installation with static IP...
Delete /etc/netplan/99_config.yaml
Edit /etc/netplan/01-network-manager-all.yaml to look EXACTLY like this...
Note : Use the NetworkManager GUI to setup your static IP for "Wired Connection".
Note : See https://netplan.io/examples/ for examples and design info about netplan.
- Thank you for your answer and netplan examples! Now ip a shows correct output. But how do I setup a static IP with NetworkManager GUI? – TopCoder2000 Dec 6, 2021 at 18:28
- @TopCoder2000 Firstly, you can't use both parts of my answer at the same time. It's part 1 or part 2. If you're using part 2, then my answer says "Use the NetworkManager GUI to setup your static IP for "Wired Connection"" . See the IPv4 tab. Click on the manual button. Fill in the address, mask, gateway, and DNS servers, and turn off DNS Auto. – heynnema Dec 6, 2021 at 18:44
- yes, I remember! I'll accept it as soon as I don't have any questions :) Yes, I'm using the second option. But you also wrote yesterday that 'Static IPs should be set to be outside of the DHCP range set in the router'. But how do I know that set? For example, the second answer from here says that we have to check DHCP server configuration... – TopCoder2000 Dec 7, 2021 at 6:51
- @TopCoder2000 You must log into the admin page of your router and find the DHCP server settings. For your computer's static IP, you'll need to pick an address outside of the DHCP server's range of addresses. – heynnema Dec 7, 2021 at 15:01
- Ah, good! Thanks! – TopCoder2000 Dec 9, 2021 at 7:07
You must log in to answer this question.
Not the answer you're looking for browse other questions tagged networking 20.04 network-manager ethernet ..
- The Overflow Blog
- The creator of PyTorch Lightning on the AI hype cycle
- Exploring the inclusive tech revolution sponsored post
- Featured on Meta
- What would you like to change about the moderator election process?
- Site maintenance - Saturday, February 24th, 2024, 14:00 - 22:00 UTC (9 AM - 5...
Hot Network Questions
- What kind of inexpensive paper/material is suitable for acrylic paint?
- Book identification. Very old Sci-Fi picture book with spaceships traveling in space and taking off from the Earth and strange aliens on other planets
- Isn't the fact that we believe our minds are able to reason or find truth is an axiom by itself?
- Coloring the line in ListLinePlot according to a rule
- Is there any crossover between Star Trek TV shows after Enterprise?
- What is the significance of GPT's "Partition Type GUIDs"?
- Does `which` output "no" when executable cannot be found?
- Could a deadly fire start within a spacesuit?
- Doctor won't let me self-pay because I've "already presented" them my insurance card?
- Conformal Killing fields satisfy a third order PDE
- What does "I believe they’re superior to grandmothers" mean?
- Are partially cooked foods subject to bishul/Pat akum
- Meta-connect wall
- How to foster a positive relationship with my supervisor while balancing experience disparities in a PhD program?
- How to determine the Doppler radar frequency required to measure an object moving at a given speed
- Is it safe to excavate soil next to concrete slab?
- What are rebuttals to the argument that Christians only worship God to give their lives meaning?
- Why does my hot water arrive at point of use slowly after water heater replacement?
- Chlorine monoxide formation
- Mapping function across its arguments
- A movie about sun heat
- Motivation and physical interpretation of the Laplace transform
- Reynolds double butted 531C top tube rusted, worth repair or not?
- Use of special characters in filename
Learn Ubuntu
Set static IP in Ubuntu using Terminal
Table of Contents
Normally, the router's DHCP server handles assigning the IP address to every device on the network, including your computer.
The DHCP server may also give you a new IP address occasionally. This could cause a problem if you have a home lab or server setup that works on a fixed IP address.
You need to set a static IP address on your Ubuntu system to avoid problems.
Please enable JavaScript
Step 1: Identify the correct network interface
The first step is always to know the name of your network interface.
"But why?" you might ask. That is because since Ubuntu 20.04, the network interfaces are named using predictable network interface names . This means your one and only ethernet interface will not be named 'eth0'.
Ubuntu Server and Ubuntu Desktop use different renderers for 'netplan', they are 'systemd-networkd' and 'NetworkManager', respectively. So let's go over their differences.
Ubuntu Server
To see available network interfaces on Ubuntu Server, run the following command:
Doing so will show a similar result:
The output enumerates network interfaces with numbers.
From this, I can see that the ethernet interface is 'enp1s0'.
Ubuntu Desktop
The advantage (at least in my opinion) of having Ubuntu Desktop is having NetworkManager as the renderer for netplan .
It has a pretty CLI output :)
Run the following command to view the available network interfaces:
That will give you the device name, type, state and connection status.
Here is what it looks like on my computer:
This is more readable at first glance. I can make out that my ethernet interface is named 'enp1s0'.
Step 2: See current IP address
Now that you know which interface needs to be addressed, let us edit a file .
Before I change my IP address/set a static one, let us first see what my current IP address is .
Nice! But let's change it to '192.168.122.128' for demonstration purposes.
Step 3: See the gateway
A gateway is a device that connects different networks (basically what your all-in-one router is). To know the address of your gateway, run the following command:
The gateway address will be on the line that begins with "default via".
Below is the output of running the ip command on my computer:
On the line that starts with "default via", I can see that my gateway address '192.168.122.1'
Make a note of your gateway address.
Step 4: Set static IP address
Now that you have detail like interface name and gateway address, it is time to edit a config file.
Step 4-A: Disable cloud-init if present
The easiest way to know if cloud-init is present or not is to check if there is a package with that name.
Run the following command to check:
If you get an outupt, you have 'cloud-init' installed.
Now, to disable could-init, create a new file inside the /etc/cloud/cloud.cfg.d directory. The name does not matter, so I will call it '99-disable-cloud-init.cfg'.
Add the following line to it:
Please reboot your Ubuntu system now so that cloud-init does not interfere when we set our static IP address in the next step. :)
Back to Step 4
Once the 'cloud-init' related configuration is complete, we must now edit the netplan configuration to add our static IP address.
Go to the /etc/netplan directory. It is better if there is one file (easier to know which one to edit), but in some cases, there might also be more than one file with the extension '.yml' or '.yaml'.
When in doubt, grep for the name of your network interface. Use the following command if you are not comfortable with grep:
Since the name of network interface for my ethernet is 'enp1s0', I will run the following command:
running this command shows that the file I am looking for is '00-installer-config.yaml'. So let us take a look at it.
You might have noticed a line that says 'ethernet' and our network interface name under that. Under this is where we configure our 'enp1s0' network interface.
Since we do not want DHCP assigned IP address, let us change that field from true to no .
Add a field called addresses . Write the IP address you wish to assign your computer along with the network prefix. So I will write 192.168.122.128/24 in the addresses field.
Finally, we also need to specify DNS nameservers. For that, create a new field called nameservers and under that, create a field called addresses which contains the IP address for your DNS servers . I used Cloudflare's DNS servers but you can use whatever you want.
This is what my '00-installer-config.yaml' file looks like after editing it to my liking.
To apply the settings, run the following command:
This will take only a few seconds, and the IP address will be updated once it is done.
You can check the IP address using the hostname -I command.
Perfect! The IP address has now changed successfully.
I know that it feels complicated but this is the proper procedure when you are trying to assign static IP via the command line in Ubuntu.
Let me know if you are stuck at some point or encounter any technical issues.
You might also like
How to Open and Edit bashrc file in Ubuntu
How to Quit the Terminal in Ubuntu
How to Find SSH Keys in Ubuntu
How to Assign Static IP Address on Ubuntu 20.04 LTS
It is always recommended to assign a static IP address to a Linux system because static ip address will be persistent across the reboots. Recently canonical has released its stable operating system “ Ubuntu 20.04 LTS (Focal Fossa) ” for both desktop and servers. In this article we will demonstrate how to assign a static ip address on Ubuntu 20.04 LTS Server and desktop.
Assign Static IP Address On Ubuntu 20.04 LTS Server
In Ubuntu 20.04 LTS server, network configuration is controlled and managed by netplan utility. But during the installation, cloud-init configure a dynamic ip to interface on server if the dhcp server is available. so, to configure a static ip, first we must make sure and confirm that network interface is not managed by cloud-init.
Open cloud-init file “ /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg ” and make sure entry “ network: {config: disabled} ” is there. In case this entry is missing, then add it manually.
Use “ ip addr show ” command from the console to view ip address,
As we can see above, a dynamic ip is assigned automatically on interface card “ enp0s3 ”. So, to make this ip address static, we must edit the netplan configuration file “ /etc/netplan/00-installer-config.yaml ”.
Above are the default entries, which shows that interface “ enp0s3 ” is getting the IP from DHCP server. As it is an yaml file, so while making the changes in the file we must follow correct indentation. Add the following lines to the yaml file,
save and close the file.
Run the following “ netplan apply ” command to make the above changes into the effect.
Now run “ ip addr show ” and “ ip route show ” command to view ip address and route details.
Output of above command would look like below,
Perfect, output confirms that Static IP has been assigned successfully on interface ‘ enp0s3 ‘. Even if we reboot the server, this ip address will be consistent.
Now, let’s move to Ubuntu 20.04 LTS desktop.
Assign Static IP Address on Ubuntu 20.04 LTS Desktop
Network configuration in Ubuntu desktop is controlled by network manager. Configuring a static ip address on Ubuntu 20.04 desktop is very easy. Login to your desktop environment and click on network icon and then choose wired settings .
In the next window, Click on ‘ gear box ’ icon under wired option,
In the next window, Choose IPV4 Tab and then select Manual and specify the IP details like IP address, netmask, gateway and DNS Server IP.
Click on Apply to save these changes and we must disable and enable interface once to assign the ip address to interface.
Once you enable and disable the interface then static IP should be assigned to the interface, we can verify by looking at the Details Tab from Wired Settings .
Perfect, above confirms that static ip address has been assigned to the interface successfully. This conclude the article; I hope these steps help you to configure static IP Address on your Ubuntu 20.04 LTS server and desktop. Please do share your feedback and comments.
12 thoughts on “How to Assign Static IP Address on Ubuntu 20.04 LTS”
Thanks for the excellent article, It is always recommended to assign a static IP address to a Linux system because static ip address will be persistent across the reboots. that is understood. where exactly i see the advantage of assigning static ip address to my linux desktop? How circled point 3, 4, 5 in IPv4 tab are assigned, especially entries 192.168.1.210 and 255.255.255.0. If these two are explained, then it will be great.
ok, ifconfig and netstat -r gives netmask and gateway. but still i would like to know the advantage of assigning static ip address to my linux desktop preferably with example applications. thanks.
Imagine you open a network service on your linux desktop, let’s assume it is a web server running on port 80, and you want to expose this service to the internet.
You would have to add a port translation rule into your internet box to forward connections on your public ip to your linux desktop system. And the configuration in the box is static, you need a fixed and consistent ip addr on your internal network.
You achieve that either with static ip that you assign by yourself, or by configuring the dhcp server inside your internet box to reserve an ip associated to your linux destop mac address.
Hi Narayan, If your desktop is connected to the modem or a switch where DHCP server is configured with subnet “192.168.1.0/24”. So when your desktop tries to get ip from DHCP server then it will always picks one ip from the pool “192.168.1.2 – 192.168.1.254” . But if you want to map a fixed ip to desktop then you can assign that IP as static.
$ip addr show just hung my SSH session. I don’t know how long it will take to time out.
nice but i cannot follow your tutorial cause i just using phone Hehe
Thank You Very Much My Problem has fixed now All credit goes to you 🙂
Hello, I’m running ubuntu server 20.04 on a hyper-v environment, i did all steps in the page, but when I want to run update, can´t connect to internet. Please help.
I got the same problem. I’m running ubuntu 20.04 on virtualbox. I fixed it by changing the “gateway4: 192.168.1.1” to “gateway4: 192.168.0.1”. Flipping the 1 to a 0, or to the same number as the one in my own ip in that place. Happy debugging!
Thanks for the good informations…
Useful article. I am using usb broadband modem and for my case it was also useful to use such command to find out default gateway $ ip route | grep default It has given: default via 10.1.1.3
I saw this link at askubuntu.com I was having issue statically assigning IP in ubuntu and after following your steps it worked. Thanks so much and keep it up
Leave a Comment Cancel reply
How to set a static ip address in Ubuntu Server 20.04
When you install Ubuntu server, its network setting defaults to dynamic IP addressing, that is, the network management daemon in Ubuntu searches for a DHCP server on the connected network and configures the network with the IP address assigned by DHCP. Even when you start an instance in the cloud, the network is configured with dynamic addressing using the DHCP server setup by the cloud service provider. In this chapter, you will learn how to configure the network interface with static IP assignment.
Follow these steps to connect to the network with a static IP:
Step 1 : Open /etc/netplan/50-cloud-init.yaml and find the following lines:
Step 2 : Change the preceding lines to add an IP address, net mask, and default gateway (replace samples with the respective values):
Step 3 : Then run sudo netplan apply
Step 4 : Try to ping a remote host to test the network connection
Recommended
How to Configure SELinux on CentOS Stream 9
2 months ago
How To Install FirewallD on CentOS Stream 9
How to Update CentOS Stream 9
CentOS Stream 9 Guides
How to Install CentOS Stream 9
How to Create Bootable USB installer for CentOS Stream 9
How to Install RabbitMQ on on Rocky Linux 9
How to Install and Configure Jenkins on Rocky Linux 9
How To Install Memcached on Rocky Linux 9
How to Install and Configure VNC Server on Rocky Linux 9
How to Install and Use rsync on Rocky Linux 9
How to Install PHP 8.3 on Rocky Linux 9
How To Install and Configure Postfix on Rocky Linux 9
How to Configure Static IP Address on Rocky Linux 9
How to Manage Network Interfaces on Rocky Linux 9
How to Configure Static IP Address on Ubuntu 20.04
Usually, when a client system connects to a network via WiFi or an ethernet cable, it automatically picks an IP address from the router. This is made possible through the DHCP server which auto-assigns IP addresses to clients from a pool of addresses.
The drawback with DHCP is that once the DHCP lease time has lapsed, the IP address of a system changes to a different one, and this leads to a disconnection in case the system was used for a particular service such as a file server. For this reason, you may want to set a static IP address so that it never changes even when the lease time is up.
In this guide, you will learn how to configure a static IP address on Ubuntu 20.04 server and desktop.
Network Configuration
Ubuntu uses the NetworkManager daemon for managing network configuration. You can configure a static IP either graphically or on the command line.
For this guide, we will focus on setting a static IP address using both the GUI and on the command line, and here is the IP configuration:
This information will be different for you, so replace the values accordingly according to your subnet.
On this page
- Set Static IP Address on Ubuntu 20.04 Desktop
- Set Static IP Address on Ubuntu 20.04 Server
How to Set Static IP Address On Ubuntu Desktop
To get started, Launch ‘ Settings ’ from the application menu as shown.
On the window that appears, click on the ‘ Network ’ tab at the left sidebar and then hit the gear icon on the network interface that you wish to configure. In my case, I’m configuring my wired interface.
In the new window that appears, your interface’s network settings will be displayed as shown. By default, the IP address is set to use DHCP to automatically pick an IP address from the Router or any other DHCP server.
In our case, the current IP address assigned is 192.168.2.104 .
Now select the IPv4 tab to start setting the static IP address. As you can see, the IP addressing is set to Automatic (DHCP) by default.
Click on the ‘ Manual ’ option and new address fields will be displayed. Fill out your preferred static IP address, netmask, and default gateway.
The DNS is also set to automatic. To manually configure the DNS, click on the toggle to turn off Automatic DNS. Then provide your preferred DNS entries separated by a comma as shown.
Once all is done, click on the ‘ Apply ’ button at the top right corner of the window. For the changes to apply, restart the network interface by clicking on the toggle to disable it and enable it again.
Once again, click on the gear icon to reveal the new IP configuration as shown.
You can also confirm the IP address on the terminal by running the ifconfig or ip addr command .
To confirm the DNS servers, run the command:
How to Set Static IP Address on Ubuntu Server Using Netplan
We have seen how we can configure a static IP address graphically on Ubuntu 20.04 desktop. The other option is configuring a static IP address on the terminal using Netplan .
Developed by Canonical, Netplan is a command-line utility used to configure networking on modern Ubuntu distributions. Netplan makes use of YAML files to configure network interfaces. You can configure an interface to acquire an IP dynamically using DHCP protocol or set a static IP.
Open your terminal and head over to the /etc/netplan directory. You will find a YAML configuration file which you will use to configure the IP address.
In my case the YAML file is 01-network-manager-all.yaml with the default settings as shown.
For the Ubuntu server, the YAML file is 00-installer-config.yaml and these are the default settings.
To configure a static IP, copy and paste the configuration below. Be mindful of the spacing in the YAML file.
Next, save the file and run the netplan command below to save the changes.
You can thereafter confirm the IP address of your network interface using the ifconfig command .
This wraps up today’s article. We hope you are now in a position to configure a static IP address on your Ubuntu 20.04 desktop & server system.
Previous article:
Next article:
Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.
Related Posts
How to Configure Network IP Connections Using ‘nmcli’ in Linux
A Beginner’s Guide to Configuring IPv4 and IPv6 Addresses in Linux
What’s Wrong with IPv4 and Why We Are Moving to IPv6
What IP – A Network Information Tool for Linux
How to Configure Network Static IP Address on RHEL/CentOS 8/7
How to Create NIC Teaming or Bonding in CentOS 8 / RHEL 8
21 thoughts on “How to Configure Static IP Address on Ubuntu 20.04”
DHCP is that once the DHCP lease time has lapsed, the IP address of a system changes to a different one, and this leads to a disconnection in case the system was used for a particular service such as a file server.
For this reason, you may want to set a static IP address so that it never changes even when the lease time is up.
Thanks for documenting this. However, after a reboot, I am left with the old IP address (DHCP). Guess there is another process that overrules the yaml file, but what??
Hey Pieter, that’s awkward. Ideally, the IP should not change since it’s a static IP. Did you try out both procedures. I’m just curious.
I had a static IP in the yaml file and this does not get an update if you adjust its IP via.
netplan ip a prior to gui adjustments gui DHCP => ip DHCP Gui static ip b => ip a It seems that netplan is not updated via GUI adjustments Enjoy the coffee ‘)
Could this lead to a clash of IP addresses between two computers on the same network? Another computer (computer B) which gets its IP address dynamically comes online when the computer with the static IP (computer A) is offline.
The dhcp server could assign the IP to computer B. Subsequently, when computer A comes online and tries to join the network there would be an IP conflict and both computers could end up not being able to connect to network resources or perform other network operations.
In some routers, this can be managed by restricting the range of IP addresses that the router can dynamically assign. Many routers don’t have that option.
To avoid the potential of such conflicts, I assign static IP addresses on the dhcp server to computers on the network based on the MAC addresses of their NICs.
I would appreciate your thoughts on how to prevent IP conflicts when the network is made of some devices that have static in and others have dynamic IP addresses assigned to them. This scenario is more common today where network devices like smart phones, tablets, smart TVs, and media streaming devices connecting to the network.
Managing IP addresses by MAC addresses is a pain and it would be very helpful if there is an easier way to prevent IP conflicts.
Your concern is very valid. To avoid a conflict in IP address assignment in a network, as you have just described, consider reserving the IP assigned to the server on the router. Say for example, if you want to assign Server A an IP of 172.16.0.100, simply login into your router and reserve the IP address. This prevents the IP from being made available to client PCs & other network devices via the DHCP protocol.
Ideally, before the static assignment, proper mapping of your network is advised so as to know which device is using which IP address. You can use nifty tools like Nmap to scan your network to get to know which IP addresses are in use to avoid assigning a duplicate IP statically on the server.
I hope this answers your question.
Wonderful post. Very simple and to the point. Thank you!!!! Keep it up!!!
Thank you very much Jaidev Shah. Keep it Tecmint.
Hi, why when we use the desktop method, the interfaces file does not get updated ? Where does the desktop tool write the information ?
That’s actually a very interesting question and I did not think about it before. I just configured a static IP on one of my Ubuntu boxes and used grep from /etc/ folder recursively to search for that IP. The IP address was written in:
/etc/NetworkManager/system-connections/Wired\ connection\ 1
So if you need to look where the desktop tool has written your settings, you can look at:
/etc/NetworkManager/system-connections/
Hey Marin, thanks for your contribution. I hadn’t actually seen it from that angle. Quite interesting I must say.
Great article just wondering about this part: “Remember to replace “enp0s3” with the name of your network adapter??? what do u mean by this? do you mean we should not change this name enp0s3 or changed with our network adapter? Cheers
Means, you should change “enp0s3” with your network adapter name for example, eth0 or eth1..
Sorry for my english, I would put a secondary IP in the same interface, like old versions (eth0 192.168.1.100… eth0:1 10.10.0.100) I know how to do it in the old versions, but in version 15.10, they have changed the commands. Can you help me?
Hello Nikon,
As the answer of this question is too long for the comment section, I would recommend you to submit your question to our Linuxsay discussion forum, where we will gladly provide more details:
http://linuxsay.com/
Where do the Nameserver numbers obtained? Elaborate on “Make sure to use your own settings depending on the network to which you are connected to.”
Can you please expand on this? IMPORTANT NOTE: For the purpose of this tutorial, I will be using the following settings:
IP Address: 192.168.0.100 Netmask: 255.255.255.0 Gateway: 192.168.0.1 Nameserver: 8.8.8.8 Nameserver: 8.8.4.4 Make sure to use your own settings depending on the network to which you are connected to. Where do you obtain the Nameserver numbers?
This depends on few things:
If your machine is connected to a router, you should see the settings in there.
If you are plugging your ISP’s internet cable directly to your computer (i.e no router, modem etc), you should use your ISP’s settings.
I want 1st IP by DHCP and 2nd static but, in Ubuntu 15.10 mi interface isn’t eth0 it is eno1 and if I put eno1:1 don’t works.
Actually the init script does exactly that – it calls systemctl. You can see it in the screenshot:
“restarting networking (via systemctl): networking service”
Both scripts do the same.
Why not use systemd to restart networking directly?
`systemctl restart network`
Got something to say? Join the discussion. Cancel reply
Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.
Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.
Save my name, email, and website in this browser for the next time I comment.
How to Configure Static IP Address on Ubuntu 20.04
A static or fixed IP address is an IP address that does not change. Whether you reboot your device or home router, your device with a static IP address will get the same IP address. The opposite of a static IP address is the dynamic IP address. A device that does not have a static IP address will get a dynamic IP address assigned by the DHCP (Dynamic Host Configuration Protocol) server, and it may change from time to time.
By default, a device connected to your home router whether it’s using cable or connected through WiFi will most likely get a dynamic IP address. And, if you use your managed Ubuntu VPS also as an FTP server of web server you would want to configure a static IP address for it, so you can reach the server using the same IP address. In this tutorial, we will show you how to configure a static IP address on Ubuntu 20.04.
Configure Static IP Address on Ubuntu Server 20.04
In Ubuntu server 20.04, the network configuration is managed by a utility called NetPlan. NetPlan is a new network configuration tool introduced in Ubuntu 17.10 to manage network settings. And during the Ubuntu 20.04 server installation, cloud-init will configure a dynamic IP address for the network interface on the server if the DHCP server is available.
First of all, we need to check what is the ethernet interface card that we want to configure the IP address for, we can run ip a or ip link command to see it. In this example, the interface that we are going to configure the static IP is ‘ens33’.
To proceed with configuring a static IP address on Ubuntu server 20.04, we have to make sure that cloud-init does not manage the network interface. To do it, let’s open cloud-init file at /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg and make sure that “network: {config: disabled}” entry is there. If the entry is missing, we have to create it.
Now, to configure a static IP address, we need to modify the YAML configuration file at /etc/netplan/00-installer-config.yaml. Please note, when editing a YAML file, make sure you follow the YAML code indentation standards. The suggested syntax for YAML files is to use 2 spaces for indentation, do not use TABS. If the indentation and syntax are incorrect, the changes will not work.
As seen in the file, DHCP is available and the server is getting the IP address from the DHCP server. To change your server IP address, for example to 192.168.1.100, let’s back up the file /etc/netplan/00-installer-config.yaml
and open the file
to replace the content of /etc/netplan/00-installer-config.yaml above with these lines.
When editing the file, make sure the ethernet interface match with the one we see when invoking the ‘ip a’ or ‘ip link’ command.
To check the new configuration file without applying the changes, we can run this command:
If everything is okay, you will see a message as seen in the picture below. You can hit ENTER to accept the changes or leave it to revert the changes back to the previous configuration.
Configure Static IP Address on Ubuntu Desktop 20.04
Most modern home routers have configuration options to allow you to reserve an IP address for a specific device connected to the same network. With this option in your home router, your devices on the network will get static/fixed IP addresses. This is the easiest and most recommended way to assign an IP address to your device, and this is called static DHCP or DHCP reservation.
If you do not want to configure it on the router, you can do it on the device itself. At this moment, we will show you how to configure a static IP address on Ubuntu desktop 20.04. Let’s click on the network icon on the top right of your screen.
Clicking the icon will bring you to the new window, as seen in the picture below
Now just $ 43 .99 /mo
In this example, we will configure the static IP address for the wired connection. So, we need to click on the cog icon next to the on-off slider in the wired connection section. To configure your WiFi connection, then you need to click on the cog icon in the WiFi connection section.
This will open a new window, click on the IPv4 as shown in the picture below
In the next window, choose “Manual” in IPv4 Method and fill the following information in the forms
You can leave the DNS part blank if you want to set it to automatic or use your own DNS address, separate the IP addresses with commas, for example, 1.1.1.1, 8.8.8.8 , then click on the APPLY button above.
Congratulations! you have successfully configured a static IP address on Ubuntu 20.04.
Of course, you don’t need to configure a static IP address on Ubuntu 20.04 yourself if you use one of our Linux VPS Hosting services and have additional IP addresses. In which case you can simply ask our expert Linux admins to configure and set this up for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post on How To Configure a Static IP Address on Ubuntu 20.04, please share it with your friends on social networks, or simply leave a reply below. Thanks.
Leave a Comment
Save my name, email, and website in this browser for the next time I comment.
Yes, add me to your new blog post notifications list
How-To Geek
How to set a static ip address in ubuntu.
When static is the way forward.
Quick Links
What is a static ip address, setting a static ip in ubuntu, set a static ip in ubuntu with the gui, connection convenience, key takeaways.
After gathering your connection name, subnet mask, and default gateway, you can set a static IP address in the terminal using the nmcli command. Or, in the GNOME desktop, open your connection settings and click the + icon, then enter the info for your static IP address there.
Your home network relies on IP addresses to route data between devices, and sometimes on reconnecting to the network a device's address can change. Here's how to give an Ubuntu Linux computer a permanent IP address that survives reboots.
Everything on your network home network, whether it's using a wired connection or Wi-Fi, has an IP address . IP stands for Internet Protocol. An IP address is a sequence of four numbers separated by three dots. Each IP address that is unique within that network.
IP addresses act as numeric labels. Your router uses these labels to send data between the correct devices. Usually, your router assigns IP addresses. It knows which IP addresses are in use and which are free. When a new device connects to the network, it requests an IP address and the router allocates one of the unused IP addresses. This is called DHCP, or dynamic host configuration protocol .
When a device is restarted or powered off and on, it may receive its old IP address once more, or it might be allocated a new IP address. This is normal for DHCP and it doesn't affect the normal running of your network. But if you have a server or some other computer that you need to be able to reach by its IP address, you'll run into problems if its IP address doesn't survive power downs or reboots.
Pinning a specific IP address to a computer is called allocating a static IP address . A static IP address, as its name suggests, isn't dynamic and it doesn't change even if the computer is power-cycled .
Nmcli is the command-line network manager tool , and can be used to change your IP address, configure network devices, and --- relevant to our purposes --- set up a static IP in Ubuntu.
We're demonstrating this technique on Ubuntu 22.04 LTS, but it ought to work on any Linux distribution, including Ubuntu 23.04. The nmcli tool was released in 2004, so it should be present on just about any standard distribution.
Let's take a look at the network connections that already exist on the computer. We're using the connection command with the show argument.
nmcli connection show
This displays some information about each connection. We only have a single connection configured.
The output is wider than the terminal window. This is the information that we're shown.
- Name : Our network connection is called "netplan-enp0s3."
- UUID : The universally unique identifier Linux uses to reference this connection internally.
- Type : This is an ethernet connection.
- Device : This connection is using the "enp0s3" network interface. It's the only network card in this computer.
We can use the ip command to discover the IP address this computer is using.
In the output we can see the "enp0s3" entry, and its current IP address, 192.168.86.117. The "/24" is a shorthand way of saying that this network uses a 255.255.255.0 subnet mask . Take a note of this number, we'll need to use it later.
We need to choose the IP address we're going to set as our static IP address. Obviously, you can't use an IP address that is already in use by another device. One safe way to proceed is to use the current IP address assigned to the Ubuntu system. We know for certain that nothing else is using that IP address.
If we want to use a different IP address, try pinging it. We're going to test whether IP address 192.168.86.128 is in use. If everything else on your network uses DHCP and you get no response to the ping command, it should be safe to use.
ping 192.168.86.128
Even if another device had previously used that IP address, it'll be given a new IP address when it next boots up. Nothing responds to the ping requests, so we're clear to go ahead and configure 192.168.86.128 as our new static IP.
We also need to know the IP address of your default gateway , which will usually be your broadband router. We can find this using the ip command and the route option, which we can abbreviate to "r."
The entry that starts with "default" is the route to the default gateway. Its IP address is 192.168.86.1. Now we can start to issue commands to set up our static IP address.
The first command is a long one.
sudo nmcli con add con-name "static-ip" ifname enp0s3 type ethernet ip4 192.168.86.128/24 gw4 192.168.86.1
Taken in small chunks, it's not as bad as it looks. We're using sudo . The nmcli arguments are:
- con : Short for "connection."
- add : We're going to add a connection.
- con-name "static-ip" : The name of our new connection will be "static-ip."
- ifname enp0s3 : The connection will use network interface "enp0s3."
- type ethernet : We're creating an ethernet connection.
- ip4 192.168.86.128/24 : The IP address and subnet mask in classless inter-domain routing notation . This is where you need to use the number you took note of earlier.
- gw4 192.168.86.1 : The IP address of the gateway we want this connection to use.
To make our connection a functioning connection, we need to provide a few more details. Our connection exists now, so we're not adding anything, we're modifying settings, so we use the mod argument. The setting we're changing is the IPv4 DNS settings. 8.8.8.8 is the IP address of Google's primary public DNS server , and 8.8.4.4 is Google's fallback DNS server.
Note that there is a "v" in "ipv4." In the previous command the syntax was "ip4" without a "v." The "v" needs to be used when you're modifying settings, but not when adding connections.
nmcli con mod "static-ip" ipv4.dns "8.8.8.8,8.8.4.4"
To make our IP address static, we need to change the method which the IP address obtains its value. The default is "auto" which is the setting for DHCP. We need to set it to "manual."
nmcli con mod "static-ip" ipv4.method manual
And now we can start or "bring up" our new connection.
nmcli con up "static-ip" ifname enp0s3
We didn't get any error messages which is great. Lets use nmcli to look at our connections once more.
nmcli con show
Here's the output:
Our static-ip connection is active and using device "enp0s3." The existing connection "netplan-enp0s3" is no longer associated with a physical network interface because we've pinched "enp0s3" from it.
Click the icons at the far-right end of the system bar to show the system menu, then click on the "Wired Connected" menu option. If you're using a wireless connection, instead click the name of your Wi-Fi network.
The available connections are displayed. A dot indicates which is in use. Click the "Wired Settings" or "Wi-Fi Settings" menu option. The details of the active connection are displayed.
If you followed our previous instructions the new connection will be the active connection. We can see our new "static-ip" connection has the IP address, default gateway, and DNS servers that we set for it.
To create a new connection using the "Settings" application, click the " + " icon on the "Networks" page, above the list of wired connections.
A dialog appears. We need to provide a name for our new static IP connection.
We're calling our new connection "static-2." Click the "IPv4" tab.
Select the "Manual" radio button, and complete the "Address", "Netmask", and "Gateway" fields. Also complete the DNS field, and then click the green "Apply" button. Note the comma between the DNS entries.
Our new connection is listed in the "Wired" connections pane.
You can swap between the available connections by clicking directly on their names.
If you want to modify a connection after you create it, click the cog icon. In this case, we'll enter the settings for the "static-ip" connection.
A dialog box opens. Click on the "IPv4" tab.
Because we set our new IP address to be static, the "Manual" radio button is selected. You could change this back to DHCP by selecting the "Automatic (DHCP)" radio button, and clicking the green "Apply" button.
Using the nmcli command or the GNOME desktop and apps, you can hop between network connections very easily and very quickly.
It's more convenient to have a selection of connection profiles and move between them as you need to, rather than to have one that you keep editing. If something goes horribly wrong with the connection you're editing or adding, you can always fall back on one of the existing connections.
Set IP static on Ubuntu 20.04 LTS Server with netplan
[Updated on Date: 2021-01-30] A static IP is an IP address that is fixed and does not change. You can set it for your devices that use an IP address to be configured for having a static IP address. Since the network configuration is controlled and managed by netplan in Ubuntu 20.04, join us to review how to set IP static on ubuntu 20.04 LTS Server with netplan . Netplan enables configuring networking on a system via YAML files easily. And processes the YAML and generates the required configurations for either Network Manager or systemd-network the system’s renderer. To buy your own Linux VPS visit Eldernode and find the best suitable package due to your needs.
To let this tutorial work better, please consider the below Prerequisites :
A non-root user with sudo privileges.
To set up, follow our Initial server setup on Ubuntu 20.04 .
Table of Contents
Tutorial Set IP static on Ubuntu 20.04 LTS Server with netplan
Using netplan utility as a new command-line network configuration helps you to manage and configure network settings easily in Ubuntu systems.
How to check Interface na me
In the first step, you need to check all interfaces on the Ubuntu 20.04 LTS server. Enter the below command for getting the N etwork I nterface C ontroller name.
When you enter the command, you can see your interface name. You need the name for network configuration later.
How to Set the IP address on Ubuntu 20.04 server
Go to /etc/netplan directory and check the name of the YAML file.
After that, you can use the ls command to see the YAML file.
It is time to set IP static on Ubuntu 20.04 LTS Server.
Remember : Do not forget to edit your yaml file.
Type your Static IP and other information like this
Please attention below picture, you will see some space and some rules. If you do not consider rules, netplan can not detect your configuration.
After adding IP static and other information on the file, save, and exit.
Point : you can save and exit with Ctrl + x key and press Enter key twice.
Apply configuration with the following command.
Now you can check Network configuration by ping your IP or ip addr command.
Also, you could see the video on the Eldernode Youtube channel.
In this article, you learned how to Set IP static on Ubuntu 20.04 LTS Server with netplan. From now on you can look at the bigger infrastructure by using the static IP to avoid network problems. In case you are interested in learning more, find our related article on How to find server public IP Address in Linux terminal .
How useful was this post?
Click on a star to rate it!
Average rating 0 / 5. Vote count: 0
No votes so far! Be the first to rate this post.
It would be nice that manuals for native ipv6 are written. Basically they are the same, however if you add a static IP(v6) in netplan or dhcpcd ther is always a hardware address added. That address is the default source address for outgoing connections.
So far only native networking with interfaces is working correct.
Thanks for your comment, we will inform you that in future posts, how to Set IPv6 on Ubuntu 20.04 LTS Server with netplan will be written. Please follow our articles.
Hi, very good. How can i be aware about new articles once publishing?
You mentioned how to check Network configuration by ping your IP or ip addr command. Please explain how to assign a static IP address to my phone?
Yes, sure. First tap on the settings icon beside the Wi-Fi network name. Once the pop-up opens, you will see IP settings at the bottom of the menu. The default option is “DHCP”. Tap on it to change the IP configuration.
Ifupdown? What is this? How could I install it?
To explain fast, please consider the 3 below steps to go for that: Run update command to update package repositories and get latest package information. Run the install command with -y flag to quickly install the packages and dependencies. sudo apt-get install -y ifupdown. Check the system logs to confirm that there are no related errors.
What if we do not prefer to use the netplan?
In this case you should be aware that on a running system, netplan can be removed by installing ifupdown, configuring /etc/network/interfaces manually as users have done before and finally removing the netplan.io package altogether.
why we use netplan to Set IP static on Ubuntu?
Netplan is a new command-line network configuration utility introduced in Ubuntu 17.10 to manage and configure network settings easily in Ubuntu systems. It allows you to configure a network interface using YAML abstraction.
How Netplan processes the YAML and generates the required configurations?
Since, Ubuntu has switched to Netplan for configuring network interfaces; Netplan is based on YAML based configuration system that makes configuration process very simple. Netplan has replaced the old configuration file /etc/network/interfaces which was used for configuring network interfaces in Ubuntu.
How can I display all available network interfaces names under Linux operating systems?
You can use the following commands to see all network interfaces under Linux operating systems: ip command – It is used to show or manipulate routing, devices, policy routing and tunnels. netstat command – It is used to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. ifconfig command – It is used to display or configure a network interface
Is setting a static IP addresses in windows same as this ?
You can have a look at our article on ( https://blog.eldernode.com/set-static-ip-in-windows-server-2016/ ) But if i want to explain you, please trace below steps: Click Start Menu > Control Panel > Network and Sharing Center or Network and Internet > Network and Sharing Center. Then, click change adapter settings. After detecting your area connection, click properties and Select Internet Protocol Version Again Click Properties and select use the following IP address.
Dear admin, could you please explain me what is the steps of setting IP static briefly?
Dear user, let’s see this overview together. After selecting the settings of the network interface you wish to configure to use a static IP address, you need to click the settings icon to start configuration. And when you select IPv4 tab, then you will select manual and enter your desired static IP address, netmask, gateway and DNS settings.
Should I connect a router overlay to configure a network?
Yes you need. Because the router is the gateway between the Internet and your home network. Also you should Access the router’s interface and lock it down.
Is setting a static IP addresses in windows same as this?
Leave Your Comment
Your email address will not be published.
Starting From $15.86/mo
- Advance (1135)
- Beginner (137)
- Instant Setup Vps Servers
- Windows Vps
Cheap Linux VPS
$20 discount for annually order.
Buy Linux VPS with Instant Activation
We are by your side every step of the way
Think about developing your online business; we will protect it compassionately.
+8595670151
7 days a week, 24 hours a day
The Simple Guide to Linux File Management: Counting Files in Directories Explained
How to remove git remote origin on linux: the ultimate guide, step-by-step guide: how to rename a directory in linux, static ip on ubuntu 20.04: a comprehensive tutorial for beginners.
Are you a developer, system administrator, or someone who wants a stable and reliable operating system? If so, Ubuntu 20.04 is a popular Linux distribution that you may have heard of. One of the most important aspects of setting up a Linux system is configuring the network settings. In this tutorial, we will cover how to set up a static IP on Ubuntu 20.04.
Table of Contents
Why Setting Up a Static IP on Ubuntu 20.04 is Important
A static IP address is a unique identifier assigned to a device on a network. Unlike a dynamic IP address, which is automatically assigned by a DHCP server, a static IP address remains fixed unless it is manually changed.
Setting up a static IP address on Ubuntu 20.04 is important for several reasons:
- Provides a reliable and consistent connection to the network
- Makes it easier to connect to your Ubuntu 20.04 system from other devices on the network
- Allows you to have more control over your network settings
With a static IP address, you dont have to worry about your IP address changing every time you reboot your system or your DHCP lease expires. This is especially important if youre running services that require a fixed IP address, such as a web server or a database server.
What This Article Will Cover
This article aims to provide a comprehensive tutorial for beginners on how to set up a static IP address on Ubuntu 20.04. We will cover the following topics:
- Understanding static IP
- Choosing an IP address
- Configuring a static IP
- Troubleshooting common issues
By the end of this tutorial, you’ll have a solid understanding of how to set up a static IP address on Ubuntu 20.04 and troubleshoot common issues that may arise.
My Expertise in Setting Up a Static IP on Ubuntu 20.04
As a seasoned Linux user and a professional software engineer, I have extensive experience in configuring network settings on Ubuntu 20.04, including setting up static IP addresses. In this tutorial, I will share my knowledge and expertise on this topic to help you successfully configure a static IP address on your Ubuntu 20.04 system.
Understanding Static IP
Before we dive into the steps of setting up a static IP address on Ubuntu 20.04, let’s understand what a static IP address is and how it differs from a dynamic IP address.
What is a Static IP Address?
A static IP address is a fixed address assigned manually to a device on a network. It doesnt change unless it is manually changed. This is in contrast to a dynamic IP address, which is automatically assigned by a DHCP server and can change over time.
Static vs. Dynamic IP Address
The main difference between static and dynamic IP addresses is how they are assigned. A static IP address is manually assigned to a device, whereas a dynamic IP address is automatically assigned by a DHCP server. Dynamic IP addresses are more common because they are easier to manage and require less manual configuration.
Benefits of Using a Static IP Address
There are several benefits to using a static IP address on Ubuntu 20.04. Firstly, it provides a reliable and consistent connection to the network. Secondly, it makes it easier to connect to your Ubuntu 20.04 system from other devices on the network. Finally, it allows you to have more control over your network settings.
Choosing an IP Address
Before you can configure a static IP address on your Ubuntu 20.04 system, you need to choose an IP address that is compatible with your network. This involves selecting an IP address and subnet mask that are compatible with your network.
Why Choosing the Right IP Address is Important
Choosing the right IP address ensures that your Ubuntu 20.04 system can communicate with other devices on your network. If you choose an IP address that is already in use by another device on your network, youll run into conflicts and connectivity issues.
How to Choose an IP Address and Subnet Mask
To choose an IP address and subnet mask that is compatible with your network, follow these steps:
- Open the Terminal on your Ubuntu 20.04 system.
- Type ip addr and press Enter. This will display your current IP address, subnet mask, and other network information.
- Identify the network interface that you want to configure. This is usually eth0 or enp0s3 .
- Check the current IP address range of your network. This is usually in the form of 192.168.0.0/24 or 10.0.0.0/24 .
- Choose an IP address that is not already in use by another device on your network. This should be within the IP address range of your network.
- Choose a subnet mask that is compatible with your network. This is usually 255.255.255.0 for most home networks.
Once you have chosen an IP address and subnet mask that are compatible with your network, proceed to the next section and configure a static IP address on your Ubuntu 20.04 system.
Section 5: Real-Life Example
Setting up a static IP on Ubuntu 20.04 might seem like a daunting task, but it can make a significant difference in your network’s stability and security. For instance, Jane works as a graphic designer and uses Ubuntu 20.04 on her desktop to create her designs. She used to have a dynamic IP, which caused her network to drop frequently, leading to a loss of unsaved work. She also experienced slow network speeds, which affected her productivity.
After reading this article, Jane decided to set up a static IP on her Ubuntu 20.04 system. She followed the step-by-step instructions in Section 3 and chose an IP address that was compatible with her network. Once she configured her system with the new static IP, she noticed a significant improvement in her network’s stability and speed. She no longer experienced any network drops, and her network speed increased, allowing her to work efficiently.
Jane’s experience demonstrates the importance of setting up a static IP on Ubuntu 20.04. It can improve your network performance, stability, and security.
Configuring a Static IP
To configure a static IP address on your Ubuntu 20.04 system, you need to edit the network configuration file and set the IP address, subnet mask, default gateway, and DNS servers.
Step-by-Step Instructions
To configure a static IP address on your Ubuntu 20.04 system, follow these steps:
- Type sudo nano /etc/netplan/00-installer-config.yaml and press Enter. This will open the network configuration file in the Nano text editor.
- Locate the network interface that you want to configure. This is usually eth0 or enp0s3 .
- Add the following lines to the configuration file, replacing 192.168.0.10 with the IP address that you chose in the previous section:
addresses: – 192.168.0.10/24 gateway4: 192.168.0.1 nameservers: addresses: [8.8.8.8, 8.8.4.4]
- addresses sets the IP address and subnet mask of the network interface.
- gateway4 sets the default gateway of the network interface.
- nameservers sets the DNS servers to use.
- Press Ctrl+O to save the changes to the configuration file.
- Press Ctrl+X to exit the Nano text editor.
- Type sudo netplan apply and press Enter. This will apply the changes to the network configuration.
Once you have configured the static IP address, you can test the connection by pinging another device on your network.
Troubleshooting
Setting up a static IP address on Ubuntu 20.04 is usually a straightforward process, but sometimes things can go wrong. Here are some common issues that you may encounter and how to troubleshoot them:
Incorrect IP Address
If you have chosen an IP address that is already in use by another device on your network, youll run into conflicts and connectivity issues. To fix this issue, choose a different IP address that is not in use by another device on your network .
Incorrect Subnet Mask
If you have chosen an incorrect subnet mask, you may experience connectivity issues. To fix this issue, choose a subnet mask that is compatible with your network.
DNS Server Issues
If youre experiencing DNS server issues, you may not be able to connect to the internet or resolve domain names. To fix this issue, check your DNS server settings and make sure they are correct. You can use the nslookup command to test DNS resolution.
Firewall Issues
If youre unable to connect to your Ubuntu 20.04 system from other devices on the network, you may have firewall issues. To fix this issue, check your firewall settings and make sure they are configured to allow incoming connections on the port youre using.
Setting up a static IP address on Ubuntu 20.04 is an essential step in configuring your network settings. By following the steps outlined in this tutorial and using the troubleshooting tips provided, you should be able to configure a static IP address on your Ubuntu 20.04 system successfully. If you want to learn more about networking and Ubuntu 20.04, there are plenty of resources available online.
Who needs to set a static IP on Ubuntu 20.04?
Anyone who wants a consistent IP address for their Ubuntu machine.
What is a static IP on Ubuntu 20.04?
A fixed IP address that remains the same even after rebooting the machine.
How do I set a static IP on Ubuntu 20.04?
By editing the netplan configuration file in the /etc/netplan/ directory.
What if I make a mistake while editing the netplan file?
Use the “netplan –debug apply” command to check for errors and revert changes.
How can I verify that my static IP is working on Ubuntu 20.04?
Use the “ifconfig” or “ip addr show” command to check the IP address assigned.
What if my network configuration uses DHCP instead of static IPs?
Follow the same steps but replace “dhcp” with “static” in the netplan file.
Related Posts
Linux port checking made easy: a beginner’s guide, step-by-step: how to mount a filesystem on linux, the ultimate guide to installing nvidia drivers on ubuntu 20.04, mounting a filesystem in linux: a step-by-step guide for beginners, leave a reply cancel reply.
Save my name, email, and website in this browser for the next time I comment.
Type above and press Enter to search. Press Esc to cancel.
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.
Pre-requisites:
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 8.8.8.8 which is Google's primary DNS server and the second value is 8.8.8.4 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 Configure Static IP Address on Ubuntu 20.04 - DesignLinux
Usually, when a client system connects to a network via WiFi or an ethernet cable, it automatically picks an IP address from the router. This is made possible through the DHCP server which auto-assigns IP addresses to clients from a pool of addresses.
The drawback with DHCP is that once the DHCP lease time has lapsed, the IP address of a system changes to a different one, and this leads to a disconnection in case the system was used for a particular service such as a file server. For this reason, you may want to set a static IP address so that it never changes even when the lease time is up.
In this guide, you will learn how to configure a static IP address on Ubuntu 20.04 server and desktop.
Network Configuration
Ubuntu uses the NetworkManager daemon for managing network configuration. You can configure a static IP either graphically or on the command line.
For this guide, we will focus on setting a static IP address using both the GUI and on the command line, and here is the IP configuration:
This information will be different for you, so replace the values accordingly according to your subnet.
On this page
- Set Static IP Address on Ubuntu 20.04 Desktop
- Set Static IP Address on Ubuntu 20.04 Server
How to Set Static IP Address On Ubuntu Desktop
To get started, Launch ‘ Settings ’ from the application menu as shown.
On the window that appears, click on the ‘ Network ’ tab at the left sidebar and then hit the gear icon on the network interface that you wish to configure. In my case, I’m configuring my wired interface.
In the new window that appears, your interface’s network settings will be displayed as shown. By default, the IP address is set to use DHCP to automatically pick an IP address from the Router or any other DHCP server.
In our case, the current IP address assigned is 192.168.2.104 .
Now select the IPv4 tab to start setting the static IP address. As you can see, the IP addressing is set to Automatic (DHCP) by default.
Click on the ‘ Manual ’ option and new address fields will be displayed. Fill out your preferred static IP address, netmask, and default gateway.
The DNS is also set to automatic. To manually configure the DNS, click on the toggle to turn off Automatic DNS. Then provide your preferred DNS entries separated by a comma as shown.
Once all is done, click on the ‘ Apply ’ button at the top right corner of the window. For the changes to apply, restart the network interface by clicking on the toggle to disable it and enable it again.
Once again, click on the gear icon to reveal the new IP configuration as shown.
You can also confirm the IP address on the terminal by running the ifconfig or ip addr command .
To confirm the DNS servers, run the command:
How to Set Static IP Address on Ubuntu Server Using Netplan
We have seen how we can configure a static IP address graphically on Ubuntu 20.04 desktop. The other option is configuring a static IP address on the terminal using Netplan .
Developed by Canonical, Netplan is a command-line utility used to configure networking on modern Ubuntu distributions. Netplan makes use of YAML files to configure network interfaces. You can configure an interface to acquire an IP dynamically using DHCP protocol or set a static IP.
Open your terminal and head over to the /etc/netplan directory. You will find a YAML configuration file which you will use to configure the IP address.
In my case the YAML file is 01-network-manager-all.yaml with the default settings as shown.
For the Ubuntu server, the YAML file is 00-installer-config.yaml and these are the default settings.
To configure a static IP, copy and paste the configuration below. Be mindful of the spacing in the YAML file.
Next, save the file and run the netplan command below to save the changes.
You can thereafter confirm the IP address of your network interface using the ifconfig command .
This wraps up today’s article. We hope you are now in a position to configure a static IP address on your Ubuntu 20.04 desktop & server system.
Bash Select (Make Menus)
Sysmon – a graphical system activity monitor for linux.
How to Configure Static IPv4 Address on Ubuntu 20.04
Question – How do I set a static IP Address on Ubuntu 20.04 LTS Desktop systems? Steps to set the static IP address on your Ubuntu Desktop system
Ubuntu 20.04 systems uses netplan from the previous LTS system. The desktop systems provide an attractive graphical user interface to work with it. Using the GUI, you can easily change or set a static IP address on your Ubuntu system.
Set A Static IP on Ubuntu 20.04
You must have a root or sudo privileged account in the Ubuntu system. Login to your Ubuntu 20.04 Desktop system. After that open settings on your machine as shown in the below screenshot.
In the settings window, click on Network tab in the left sidebar. After that click icon to open the setting for your systems network interface as shown on the below screen.
This window will show you the current IP address configured on your system.
Now select the IPv4 tab Then under the IPv4 Method select the “ Manual ” option. In the Addresses section and set your IP Address, Netmask, and Gateway. You may also set remote DNS IP addresses. If you don’t know what to set here use 8.8.8.8 and 8.8.4.4 as shown in below screenshot.
View Current IPs on Ubuntu
You can view the current static IP under the details tab.
To view IP on the command line. Press CTRL + ALT + T to launch the terminal on your Ubuntu system. Then type the following command to view all IP addresses configured on your system.
Related Posts
Apt configuration file options /etc/apt/apt.conf.
A Step-by-Step Guide to Installing OpenDKIM with Postfix on Ubuntu – Unleash the Power of DKIM!
How to Install and Use Composer on Ubuntu 22.04
Leave a reply cancel reply.
Save my name, email, and website in this browser for the next time I comment.
Type above and press Enter to search. Press Esc to cancel.
IMAGES
VIDEO
COMMENTS
How to Configure Static IP Address on Ubuntu 20.04 Published on Sep 15, 2020 • 5 min read This article explains how to set up a static IP address on Ubuntu 20.04. Typically, in most network configurations, the IP address is assigned dynamically by the router DHCP server.
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 8.8.8.8 and the Router's IP.
Login to your Ubuntu server 22.04, look for the netplan configuration file. It is located under /etc/netplan directory. $ cd /etc/netplan/ $ ls -l total 4 -rw-r--r-- 1 root root 116 Oct 12 04:03 00-installer-config.yaml $ Run below cat command to view the contents of '00-installer-config.yaml'
How do I set a static IP in Ubuntu 20.04.3 LTS? Ask Question Asked 2 years, 2 months ago Modified 1 year, 9 months ago Viewed 9k times 0 I'm trying to set up a lab computer as a ssh server following this guide. One of the steps is setting up a static IP address. So, I was glad to find this answer.
Step 1: Identify the correct network interface The first step is always to know the name of your network interface. "But why?" you might ask. That is because since Ubuntu 20.04, the network interfaces are named using predictable network interface names. This means your one and only ethernet interface will not be named 'eth0'.
In this example we will set a static IP address on the Ubuntu 20.04 server to 192.168.1.202/24 with default gateway to 192.168.1.1 and DNS servers 8.8.8.8 8.8.4.4 192.168.1.1. Locate and edit with administrative privileges the /etc/netplan/50-cloud-init.yaml file with the following configuration.
Configuring a static ip address on Ubuntu 20.04 desktop is very easy. Login to your desktop environment and click on network icon and then choose wired settings. In the next window, Click on ' gear box ' icon under wired option,
Step 1 : Open /etc/netplan/50-cloud-init.yaml and find the following lines: dhcp4: true Step 2 : Change the preceding lines to add an IP address, net mask, and default gateway (replace samples with the respective values): addresses: [ 192.168.1.80/24 ] gateway4: 192.168.1.1 nameservers: addresses: [ 8.8.8.8, 8.8.4.4 ] dhcp4: no
Network Configuration Ubuntu uses the NetworkManager daemon for managing network configuration. You can configure a static IP either graphically or on the command line. For this guide, we will focus on setting a static IP address using both the GUI and on the command line, and here is the IP configuration:
October 6, 2021 by Jeff Wilson A static or fixed IP address is an IP address that does not change. Whether you reboot your device or home router, your device with a static IP address will get the same IP address. The opposite of a static IP address is the dynamic IP address.
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. $ ip addr. In this you can directly assign a static IP address through Ubuntu Desktop as well ...
Method 2: Use Netplan YAML network configuration. On Ubuntu 22.04|20.04|18.04, you can use Netplan which is a YAML network configuration tool to set static IP address. This configuration assumes your network interface is called eth0. This may vary depending on your working environment. Create a network configuration file.
Or, in the GNOME desktop, open your connection settings and click the + icon, then enter the info for your static IP address there. Your home network relies on IP addresses to route data between devices, and sometimes on reconnecting to the network a device's address can change.
The best possible way to set a static IP address to your Ubuntu 20.04 device is to use DHCP reservation. DHCP reservation is a feature built-in to most routers and allows you to set a specific IP. Basically, this feature ensures that the router keeps the IP address aside and only hands it to your device.
Go to /etc/netplan directory and check the name of the YAML file. cd /etc/netplan After that, you can use the ls command to see the YAML file. ls It is time to set IP static on Ubuntu 20.04 LTS Server. Sudo nano 00-installer-config.yaml Remember: Do not forget to edit your yaml file. Type your Static IP and other information like this
It will then open the GNOME Network Configuration settings. You need to click on the cog icon now. 2) Then, the Network interface settings dialog box will appear: 3) In the "IPV4" Method section, you need to select "Manual" and enter your static IP address, the Netmask, and Gateway. After completing, click on the Apply button.
Why Setting Up a Static IP on Ubuntu 20.04 is Important. A static IP address is a unique identifier assigned to a device on a network. Unlike a dynamic IP address, which is automatically assigned by a DHCP server, a static IP address remains fixed unless it is manually changed. Setting up a static IP address on Ubuntu 20.04 is important for ...
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.
You have two options when configuring the IP address on your Ubuntu Server, and that is either a static IP address or DHCP. A static IP address allows you to manually select your IP address by configuring it on the Linux system, whereas DHCP relies on the router or DHCP server to lease you an IP address - either a reserved one or the next available one that is currently free, depending on ...
Ubuntu Network Method. Click on the ' Manual ' option and new address fields will be displayed. Fill out your preferred static IP address, netmask, and default gateway. Set Manual Network. The DNS is also set to automatic. To manually configure the DNS, click on the toggle to turn off Automatic DNS.
To temporarily configure an IP address, you can use the ip command in the following manner. Modify the IP address and subnet mask to match your network requirements. sudo ip addr add 10.102.66.200/24 dev enp0s25 The ip can then be used to set the link up or down. ip link set dev enp0s25 up ip link set dev enp0s25 down
4. Apply the New IP Address. Now apply the new configuration: sudo netplan apply. This will set your new static IP address. Verify you can access the server at the new IP. 5. Troubleshoot DNS Issues. If you have issues resolving domains after setting the static IP, you may need to reconfigure DNS. First try restarting the DNS service:
Set A Static IP on Ubuntu 20.04. You must have a root or sudo privileged account in the Ubuntu system. Login to your Ubuntu 20.04 Desktop system. After that open settings on your machine as shown in the below screenshot. ADVERTISEMENT. In the settings window, click on Network tab in the left sidebar. After that click icon to open the setting ...
Change IP address on Ubuntu Server; An Introduction to Linux Automation, Tools and Techniques; Ubuntu 22.04: Connect to WiFi from command line; How to add static route with netplan on Ubuntu 22.04 Jammy… Ubuntu 22.04 Network Setup; Assigning File Permissions to Specific Users with chmod and… Setting Up a Secure Apache Server on Ubuntu 24.04