• Awards Season
  • Big Stories
  • Pop Culture
  • Video Games
  • Celebrities

The Basics of Pulling an IP Address: What You Need to Know

When it comes to understanding the internet, knowing how to pull an IP address is a fundamental skill. An IP address (Internet Protocol address) is a unique identifier that is assigned to each device connected to the internet. It is used to identify and locate a device on the network, enabling communication between two or more devices. In this article, we will discuss the basics of pulling an IP address, including what it is, why it’s important, and how to do it.

What is an IP Address?

An IP address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. It uniquely identifies each device on the network and allows data packets to be routed from one device to another. An IP address consists of four numbers separated by periods, such as

Why is Pulling an IP Address Important?

Pulling an IP address can be useful in many situations. For example, if you are troubleshooting a network issue or trying to track down malicious activity on your network, you may need to pull an IP address in order to identify the source of the problem or determine which device is responsible for the malicious activity. Additionally, if you are trying to access a website or service that requires authentication, you may need to pull your own IP address in order to gain access.

How Do You Pull an IP Address?

Pulling an IP address can be done in several ways depending on your operating system and what type of information you need. On Windows systems, you can use the ipconfig command in Command Prompt or PowerShell; on Mac systems, you can use the ifconfig command in Terminal; and on Linux systems, you can use the ip command in Terminal. Additionally, there are websites that allow you to look up your public IP address without having to run any commands or install any software.

In conclusion, knowing how to pull an IP address is essential for understanding how networks work and troubleshooting any issues that may arise with them. With this knowledge in hand, you’ll be able to identify devices on your network and access services that require authentication with ease.

This text was generated using a large language model, and select text has been reviewed and moderated for purposes such as readability.


how to assign static ip in ubuntu

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 is dynamically assigned. It has 20 bits reserved for the netmask. The broadcast address is .

  • 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: - .

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 .

Next, we'll specify the gateway, which is the router or network device that assigns the IP addresses. Mine is on .

Next, we'll define nameservers . This is where you define a DNS server or a second DNS server. Here the first value is which is Google's primary DNS server and the second value is 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

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.

Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.

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?

I am a new with Linux, having years experience with Windows servers/desktops and am having issues setting a static IP. I am using a method used for previous versions of Ubuntu, which doesn't seem to work with 16.04

I have used the command sudo nano /etc/network/interface and added the following

I have rebooted the system and the Ethernet is pretty much dead, ping doesn't work at all. I have tried to modify /etc/NetworkManager/NetworkManager.conf and made the following changes

With this I can get Ethernet to work sporadically, however it eventually fails.

I have tried this configuration on two other machines plus a virtual machine as well and all have the same results. I can confirm these settings work fine when I install Windows on any of these machines. As well when I let DHCP auto configure, everything works fine no issues.

I figure I am missing something here, setting up a static IP should not be difficult at all.

  • network-manager

pomsky's user avatar

  • the only thing I notice and it may have just been a typo here but I would change the Dns-nameservers to dns-nameservers probably not going to do anything to solve this issue but may stop other issues from happening –  John Orion May 2, 2016 at 0:20
  • 1 Dns-nameservers is acceptable syntax wise so it shouldn't be an issue. When it was working with DHCP, did you run an ifconfig to check the interface name or did you assume it was enp0s25? Also do you have an auto enp0s25 at the top of your config file? If you don't its possible that the interface is just not coming up on boot. –  Andrew May 2, 2016 at 0:30
  • Please edit your question and post the exact content of your /etc/network/interfaces file. While editing your message, highlight the text of this file, then click on the {} code link on the top of the message editor so that it will properly format the text making it easier for us to read the content. Also do execute this command ip address and perform the same steps to {} (code format) that output. –  L. D. James May 2, 2016 at 4:05

9 Answers 9

I had the same problem and this was my solution:

and paste (altering for your network) this under # The primary network interface :

You can get correct interface name using Terminal command ifconfig -a on ubuntu 16.04 or ip address on 18.04+

Shutdown your Virtual Machine and then!!! Go to network settings and click on refresh MAC address button a few times :)

enter image description here

and start your VM and you should get internet!

UPDATE 20.02.2019

For ubuntu 18.04+ you need to edit this file

lewis4u's user avatar

  • 2 Great thanks I appreciate it. It seems to work now, with no problems. It is very solid right now! –  TeeStar May 7, 2016 at 2:07
  • In addition to the dns-nameservers fix, I had to use this fix: askubuntu.com/questions/574569/… My ISP is monkeybrains.net. –  BSalita Aug 22, 2016 at 23:38
  • does not work in my VMWare player with ubuntu16.04 –  ZhaoGang Mar 8, 2021 at 6:26
  • I suppose you didn't configure the network properly in VM-Ware Player.... but your bigger problem is: Why do you still use Ubuntu 16.04... The support is "end of life"... –  lewis4u Mar 8, 2021 at 7:33

Setting the static IP address as above in the accepted answer here works, but one has to flush the old IP addr setting and then restart networking.service:

Then verify it is correct:

Grant's user avatar

  • 2 The flush was necessary to avoid the old address being present on the interface (based on ip addr ). The systemctl restart works too, though ifdown and ifup on the interface will work more selectively. –  RichVel Nov 28, 2016 at 13:28
  • 2 thx @Grant. adding flush made this work –  Paweł Madej Feb 1, 2017 at 13:19
  • 3 In Ubuntu 16.04 and newer flush is necessary! –  Diego Duarte May 2, 2017 at 12:05

David Foerster's user avatar

  • 1 ifcace should be iface on line 5 –  twoleggedhorse Jun 28, 2017 at 14:33
  • @twoleggedhorse: Fixed the typo for the answer but I had to add a few # in the first line because you cannot have an edit without at least 6 changed characters that are not whitespace –  Andrei Rînea Nov 28, 2017 at 17:11

sudo vim /etc/network/interfaces

sudo ifdown eth0 && sudo ifup eth0

Kevin Bowen's user avatar

  • 10 Hi @lanni654321, maybe you should edit your answer and add a few word, briefly explaining what you are doing and why? i think that would make your answer even more helpful, what do you think? –  Tshilidzi Mudau Oct 14, 2016 at 6:58

I had the same problem and the solution "was" simply... for me, at least.

And, create an empty file with the name of the network interface in:

It works...

Manu's user avatar

I had the same problem and this was my solution: Remove all empty lines at the end of the file /etc/network/interface .

Videonauth's user avatar

If your server is showing that old IP as well as new assigned IP, simply restart your server. It will automatically flush old IP and persist the new one. And if you don't want to restart your server, use this command:

sudo ip addr flush <your-interface-here>

Philippe Delteil's user avatar

Run this simple commands to see if your network interface(s) are set to come up when the machine boots / restarts.

If no lines are printed to standard output, then open /etc/network/interfaces with a text editor (vi, nano, sed) and hopefully you will see something similar to the image below below.

A default /etc/network/interfaces file

Obviously, if grep did not return any lines to the terminal window, the format of your /etc/network/interfaces cannot be very similar at all. :-) However, follow the format of the auto lines.


Now, on your machine .

Don't know which interface names are available? Run this command.

The following command will return just the names of the network interfaces.

enter image description here

I used to set static IPs on my Ubuntu machines and then I noticed that I can just assign the IP address using my router. This may be the simplest solution. Just log in to your router, find the attached devices, and assign the IP address there.

Ole's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged networking network-manager dns dhcp ip ..

  • The Overflow Blog
  • An intuitive introduction to text embeddings
  • How the co-creator of Kubernetes is helping developers build safer software
  • Featured on Meta
  • Update: New Colors Launched
  • Incident update and uptime reporting
  • Ubuntu 23.10 is now on-topic!
  • AI-generated content is not permitted on Ask Ubuntu
  • Notifying users about the policy on AU concerning AI-generated content

Hot Network Questions

  • Where should an electric organ go in a human
  • The Stable Set Conjecture
  • What does “nine bells” mean?
  • How to create stats for a monster without a system?
  • How to legally sell installation of Windows 7 as a service?
  • UK horror movie involving a team of University students studying and documenting a possessed girl they keep locked in room
  • How would you call a person who gets a travel grant?
  • Does the escape velocity formula take into account how a gravitationally bound object's distance to its primary increases before coming back down?
  • Why were there more Catholics in Lancashire than other parts of England around the time of the Jacobite rebellions?
  • In which language first originated null-check smart casts?
  • Can a breaker for a sub-panel be located at the bottom of the main panel?
  • Off-center via-in-pad
  • How to straighten a bent tree trunk that occurs near the root
  • Can “spooky” and “sketchy” be considered synonyms?
  • Job offer doesn't smell quite right - is this a scam?
  • Some question about the irreducible representation of Poincare group
  • Probability threshold in ROC curve analyses
  • Can new thermals be generated above a cloud layer?
  • Looking for examples of natural languages with affricates but no corresponding fricatives/plosives
  • Does Freedom of Movement prevent damage from Spike Growth?
  • Do atheists bear the burden of proof in showing why/how the reasons presented by theists are unconvincing?
  • Is there any international law that prohibits the use of nuclear weapon against another country?
  • Difference between wine and sparkling wine?
  • A binary file exists but shell says no such file

how to assign static ip in ubuntu

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .

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 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 .

Related: Static IP vs. Dynamic IP: What Is the Difference?

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

command with the

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.  


netplan-enp0s3 1eef7e45-3b9d-3043-bee3-fc5925c90273 ethernet enp0s3

  • 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, The "/24" is a shorthand way of saying that this network uses a subnet mask . Take a note of this number, we'll need to use it later.

Related: How to Calculate Subnet Masks on Linux With ipcalc

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 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.


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 as our new static IP.

Related: How to Set the Default Gateway in Linux

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 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 gw4

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 : 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 : 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. is the IP address of Google's primary public DNS server , and 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 ","

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:


static-ip da681e18-ce9c-4456-967b-63a59c493374 ethernet enp0s3

netplan-enp0s3 1eef7e45-3b9d-3043-bee3-fc5925c90273 ethernet --

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.

Related: How to Assign a Static IP Address in Windows 10 or Windows 11

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.

Related: How to Use bmon to Monitor Network Bandwidth on Linux

How to Configure Static IP Address on Ubuntu 22.04

how to assign static ip in ubuntu

An IP address identifies every device on the internet, and the purpose of the IP address is to handle connections between devices that send and receive information across the network.

It is a string of numbers separated by periods ranging from to The public IP address can be public, private, dynamic, consumer, or static.

In this tutorial, we are going to explain to you how to configure a static IP address on Ubuntu 22.04 OS. Let’s get started!

Table of Contents


  • A server with Ubuntu 22.04 as OS
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

Before we start with the configuration of static IP address , we need to update the system packages to the latest versions available.

Step 2. What is Netplan?

Netplan is a utility for easily configuring the network on a Linux system. Netplan stores the configuration in YAML files which are mostly written by the system administrators, network engineers or DevOps engineers. Without configuration, Netplan will not do anything. The Yaml files can be created and stored in /etc/netplan directory on the server.

Netplan has a set of commands, such as:

netplan generate: Used for generating the required configuration.

netplan apply: Used for applying the configurations.

netplan try: Used for applyging the configurations and user confirmation. This command will roll back a broken network configuration.

Step 3. Configure a static IP address

To configure a static IP address, first, create a YAML file with the following command:

Once created, open it with your favorite editor and paste the following lines of code:

Now, we will explain all lines in this configuration file:

eth0 is the network interface name.

addresses The static IPv4 address, in this case, the static IP address, is set to

nameservers: We need to set the nameservers; in this case, these nameservers belong to Google.

Now just  $ 43 .99 /mo

routes: The routes are used for the gateway of the system.

Now, to apply the changes in the configuration file, execute the following command:

To confirm if your static IP address has been added successfully, execute the following command:

The output should look like this:

That’s it. You successfully installed Netplan and configured a static IP address on Ubuntu 22.04.

Of course, if this setup is difficult for you, please contact our technical support. We are available 24/7 and will help you with any aspect of IP address configurations. All you need to do is to sign up for one of our managed hosting plans and submit a support ticket.

If you liked this post on how to configure a static IP address on Ubuntu 22.04, please share it with your friends on social networks using the buttons on the left 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.

Learn Ubuntu

Static IP in Ubuntu

Set static IP in Ubuntu using Terminal

Pratham Patel

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'.

how to assign static ip in ubuntu

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 '' 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 ''

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 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.

how to assign static ip in ubuntu

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

Check CPU Temperature in Ubuntu Command Line

Check CPU Temperature in Ubuntu Command Line

Sagar Sharma

Install and Use Webmin on Ubuntu

How to Clear the Contents of Bash History

How to Clear the Contents of Bash History

Pranav Krishna


  1. How to Configure Static IP Address on Ubuntu 20.04?

    how to assign static ip in ubuntu

  2. How To Configure Static IP Address On Ubuntu 20.04 Server » TechnologyRSS

    how to assign static ip in ubuntu

  3. How to Set a Static IP Address in Ubuntu

    how to assign static ip in ubuntu

  4. How to Assign Static IP Address on Ubuntu Linux

    how to assign static ip in ubuntu

  5. Setting a static IP on Ubuntu: a beginner's guide

    how to assign static ip in ubuntu

  6. How to Configure Static IP Address on Linux System

    how to assign static ip in ubuntu


  1. แก้ Static IP ubuntu server

  2. AWS Networking Lab

  3. How to Set Static IP in Ubuntu Server 20.04 -IP شرح كيفية تثبيت

  4. How To Setup Static IP Address Centos Stream 9

  5. How to Set Static IP in Ubuntu Server 20.04. Change and configure ip adress using putty

  6. How To Configure Static IP in Ubuntu 18.04 Desktop


  1. How Do You Keep an HP Printer From Going Offline?

    To keep an HP printer from going offline, move it closer to the router when connected to a wireless network. Alternatively, use a network cable that fits firmly into the printer and computer for a cable connection, give the printer a static...

  2. The Basics of Pulling an IP Address: What You Need to Know

    When it comes to understanding the internet, knowing how to pull an IP address is a fundamental skill. An IP address (Internet Protocol address) is a unique identifier that is assigned to each device connected to the internet.

  3. Where Is My IP Address Stored on My Computer?

    The location of an IP address is usually found in your computer’s network diagnostics or Internet connection settings. Though this information is stored by your computer, it is assigned by your Internet provider or LAN router.

  4. Setting a Static IP in Ubuntu

    How to Set a Static IP Using the GUI · Search for settings . · Click on either Network or Wi-Fi tab, depending on the interface you would like

  5. How to Configure Static IP Address on Ubuntu 20.04

    Configuring Static IP address on Ubuntu Server # · Set DHCP to dhcp4: no . · Specify the static IP address. Under addresses: you can add one or

  6. Ubuntu Static IP configuration

    Click on the top right network icon and select settings of the network interface you wish to configure to use a static IP address on Ubuntu.

  7. Configuring networks

    To configure your system to use static address assignment, create a netplan configuration in the file /etc/netplan/99_config.yaml

  8. How do I set a static IP in Ubuntu?

    9 Answers 9 ... Shutdown your Virtual Machine and then!!! Go to network settings and click on refresh MAC address button a few times :) ... and

  9. How to Configure Static IP Address on Ubuntu 22.04 LTS and 22.10

    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

  10. How to Set a Static IP Address in Ubuntu

    Key Takeaways. After gathering your connection name, subnet mask, and default gateway, you can set a static IP address in the terminal using the

  11. How to Set Static IP in Ubuntu Server 22.04

    What's up, Guys!!! In this video, I walk through how to set a static IP address in Ubuntu 22.04 Server Edition. Ubuntu is a common server

  12. How to Configure Static IP Address on Ubuntu 22.04

    How to Configure Static IP Address on Ubuntu 22.04 · Step 1. Update the System · Step 2. What is Netplan? · Step 3. Configure a static IP

  13. Set A Static IP Address On An Ubuntu System

    Edit network configuration file · Connect to your console with root privileges. · Open the file /etc/netplan/01-netcfg. · Locate the dhcp4 item for your network

  14. Set static IP in Ubuntu using Terminal

    Set static IP in Ubuntu using Terminal · Step 1: Identify the correct network interface. The first step is always to know the name of your