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

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.

MORE FROM ASK.COM

assign static ip ubuntu terminal

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:

image-14

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.

image-15

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.

image-17

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.

image-16

  • Verify by using the command ip a

image-18

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

It's FOSS

How to Assign Static IP Address on Ubuntu Linux

Dimitrios

Brief: In this tutorial, you’ll learn how to assign static IP address on Ubuntu and other Linux distributions. Both command line and GUI methods have been discussed.

IP addresses on Linux Systems in most cases are assigned by Dynamic Host Configuration Protocol (DHCP) servers. IP addresses assigned this way are dynamic which means that the IP address might change when you restart your Ubuntu system . It’s not necessary but it may happen.

Dynamic IP is not an issue for normal desktop Linux users in most cases . It could become an issue if you have employed some special kind of networking between your computers.

For example, you can share your keyboard and mouse between Ubuntu and Raspberry Pi . The configuration uses IP addresses of both system. If the IP address changes dynamically, then your setup won’t work.

Another use case is with servers or remotely administered desktops. It is easier to set static addresses on those systems for connection stability and consistency between the users and applications.

In this tutorial, I’ll show you how to set up static IP address on Ubuntu based Linux distributions. Let me show you the command line way first and then I’ll show the graphical way of doing it on desktop.

Method 1: Assign static IP in Ubuntu using command line

Static IP set up Ubuntu

Note for desktop users : Use static IP only when you need it. Automatic IP saves you a lot of headache in handling network configuration.

Step 1: Get the name of network interface and the default gateway

The first thing you need to know is the name of the network interface for which you have to set up the static IP.

You can either use ip command or the network manager CLI like this:

In my case, it shows my Ethernet (wired) network is called enp0s25:

Next, you should note the default gateway IP using the Linux command ip route :

As you can guess, the default gateway is 192.168.31.1 for me.

Step 2: Locate Netplan configuration

Ubuntu 18.04 LTS and later versions use Netplan for managing the network configuration. Netplan configuration are driven by .yaml files located in /etc/netplan directory.

By default, you should see a .yaml file named something like 01-network-manager-all.yaml, 50-cloud-init.yaml, 01-netcfg.yaml.

Whatever maybe the name, its content should look like this:

You need to edit this file for using static IP.

Step 3: Edit Netplan configuration for assigning static IP

Just for the sake of it, make a backup of your yaml file.

Please make sure to use the correct yaml file name in the commands from here onward.

Use nano editor with sudo to open the yaml file like this:

Please note that yaml files use spaces for indentation . If you use tab or incorrect indention, your changes won’t be saved.

You should edit the file and make it look like this by providing the actual details of your IP address, gateway, interface name etc.

In the above file, I have set the static IP to 192.168.31.16.

Save the file and apply the changes with this command:

You can verify it by displaying your ip address in the terminal with ‘ip a’ command.

If you don’t want to use the static IP address anymore, you can revert easily.

If you have backed up the original yaml file, you can delete the new one and use the backup one.

Otherwise, you can change the yaml file again and make it look like this:

Method 2: Switch to static IP address in Ubuntu graphically

If you are on desktop, using the graphical method is easier and faster.

Go to the settings and look for network settings. Click the gear symbol adjacent to your network connection.

Assign Static IP address in Ubuntu Linux

Next, you should go to the IPv4 tab. Under the IPv4 Method section, click on Manual.

In the Addresses section, enter the IP static IP address you want, netmask is usually 24 and you already know your gateway IP with the ip route command.

You may also change the DNS server if you want. You can keep Routes section to Automatic.

Assigning static IP in Ubuntu Linux

Once everything is done, click on Apply button. See, how easy it is to set a static IP address graphically.

If you haven’t read my previous article on how to change MAC Address , you may want to read in conjunction with this one.

More networking related articles will be rolling out, let me know your thoughts at the comments below and stay connected to our social media.

Dimitrios is an MSc Mechanical Engineer but a Linux enthusiast in heart. His machines are powered by Arch Linux but curiosity drives him to constantly test other distros. Challenge is part of his per

Meet DebianDog - Puppy sized Debian Linux

Reduce computer eye strain with this nifty tool in linux, install open source dj software mixxx version 2.0 in ubuntu, install adobe lightroom alternative rawtherapee in ubuntu linux, complete guide to installing linux on chromebook, become a better linux user.

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Your link has expired.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.

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

assign static ip ubuntu terminal

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.

assign static ip ubuntu terminal

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 Stop Ubuntu Auto-Update (if you really want to)

How to Stop Ubuntu Auto-Update (if you really want to)

Sagar Sharma

How to Check Python Version in Ubuntu

How to Clear NPM Cache

How to Clear NPM Cache

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.

Log in or Sign up

Linux basics - set a static ip on ubuntu, on this page, configure a static ip address with netplan on ubuntu, configure a dhcp address with netplan, more netplan config options, step 1: configure the network interface, step 2: configure the dns servers, step 3: restart networking, configure the hostname.

This tutorial explains how to set up a static IP address on an Ubuntu system from the command line. It covers network configuration for all current versions of Ubuntu and includes instructions for configuring a static IP address, setting the hostname, and configuring name resolution.

Network configuration on Ubuntu 22.04, Ubuntu 20.04, and Ubuntu 18.04

The network configuration in Ubuntu is made with a tool called netplan. It replaced the traditional /etc/network/interfaces file.

Here are the steps to configure a static IP address with Netplan. The Netplan configuration files are in the directory /etc/netplan/ . The default configuration file is  /etc/netplan/01-netcfg.yaml .

Open the network config file with an editor. The netplan configuration filename differs depending on the Ubuntu version.

Ubuntu 22.04 and Ubuntu 20.04 :

Ubuntu 18.04 :

The configuration syntax is in Python programming language (.yaml format), so the indentation of the lines is important!

The content of the file is the same on Ubuntu 22.04 - 18.04.

Here is an example of a static IPv4 address 192.168.1.100 on the first network interface ens33 and gateway IP 192.168.1.1 . The server will use the free Google DNS servers 8.8.8.8 and 8.8.4.4 to for name resolving.

Or, as Screenshot from an Ubuntu server:

Ubuntu 22.04 Network Configuration File

An IPv6 address can be added in the addresses line, separated by a comma. Example:

You must wrap the IPv6 address into single quotes. You will get a syntax error otherwise.

To apply the changes, run the following:

Or use it with the --debug switch to get some useful output if parsing of the netplan config file was successful.

Here is the configuration to get the network configuration for IPv4 and IPv6 from a DHCP server.

To apply the changes, run:

Netplan is a complex new configuration system configuring network cards, virtual devices, VLANs and bridges in Ubuntu 18.04. See the man page for more examples and an in-depth explanation of the syntax.

Network configuration on  Ubuntu 12.04 - 17.04 (incl. Ubuntu 16.04 LTS)

In this step, you will manually configure your network interface by editing the following files using your preferred text editor(nano gedit vi). For this example, I'm using the "nano" editor. You can edit the appropriate file by entering the following command into the terminal:

You can copy and paste directly from this line.

Enter your root password, once your preferred editor opens the file you can see this on older Ubuntu versions:

Ubuntu Systems with systemd (like Ubuntu 16.04 and newer), the network interface is named ens33 instead of eth0 now and the word 'dynamic' has been replaced with 'dhcp'.

A configuration where the IP address get's assigned automatically by DHCP will look like this:

Statically configured network cards will have a section like this on older Ubuntu versions:

Here is an example for an older Ubuntu Release:

And here an example for Ubuntu 16.04 and newer:

And here the complete network configuration file from an Ubuntu 16.04 system.

Interfaces configuration file

If you use "nano" editor to edit the configuration file, type Ctrl+x to save changes.

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?

<---Type "y"

File Name to Write: interfaces

<---ENTER

Changes in /etc/resolv.conf are required only on Systems with Ubuntu < 14.04, for newer Ubuntu versions the nameservers get configured in the /etc/network/interfaces file or the netplan config file.

a) Ubuntu 20.04

Open the netplan configuration file with an Editor. I will use the nano editor in this example:

I've marked the DNS server IP addresses bold:

b) Ubuntu 18.04

Open the netplan configuration file with the nano editor:

c) Ubuntu versions 14.04 and 16.04

Open the /etc/network/interfaces file again and add a line dns-nameservers 8.8.8.8 right after the gateway line.

The nameservers 8.8.8.8 and 8.8.4.4 are provided by Google for public use, so you can use them in your network configuration.

If you use "nano" editor, type Ctrl+x to save changes.

d) Ubuntu versions < 14.04

In this step, you will manually configure your dns configuration file.

Once your editor opens the file you want to enter the following information...

File Name to Write: resolv.conf

Here is an example:

Manually restart your network interface with the new settings.

For Ubuntu 20.04 and 18.04 , use the netplan command to apply changes and restart the network. The command is:

For Ubuntu versions 14.04 and 16.04 we use systemctl instead:

At this point you can check if the settings are correct:

If everything is correct you will get this result.

For Ubuntu < 14.04 use the networking init script:

This should return a result that looks like the following:

The hostname of an Ubuntu Server or Desktop is being configured in the files /etc/hostname and /etc/hosts . The /etc/hostname file sets the actual system hostname while /etc/hosts is used for the local name resolution.

In this example, I will change the hostname of my system to obelix.example.com.

First, edit the /etc/hostname file

The hostname file contains the local part of the hostname only. The local part here is "obelix". Change the content of the /etc/hostname file to:

and save the file. The hostname file as it looks in nano after editing:

Configure Ubuntu Hostname

Then open the /etc/hosts file with an editor:

and change the line that starts with the IP address of the system like this:

Here a screenshot of the /etc/hosts file.

Ubuntu hosts file

The format is like this:

[IP Addesss] [full hostname incl. domain] [local part of the hostname]

Finally, restart the system to apply the hostname change.

assign static ip ubuntu terminal

36 Comment(s)

  • Log in with Facebook
  • Log in with Twitter
  • Log in with Google
  • No, create an account now.
  • Yes, my password is:
  • Forgot your password?

This feature is only available to subscribers. Get your subscription here .

How to Set Static IP in Ubuntu Using Command Line?

The use of a static IP address in Ubuntu is essential when you need to maintain a consistent IP address for a server, network device, or any other system on your network. This will also boost network security as it is hard to access by unauthorized users. While it is possible to set a static IP address using the GUI, using the command line interface (CLI) provides more control and flexibility over your network settings. 

In this article, two different methods will be discussed to set static ID using the command line in Ubuntu:

  • Using the Netplan Configuration File
  • Using the Network Manager Command Line Interface (NMCLI)

Method 1: Using the Netplan Configuration File

A user can set a static IP Address by modifying the netplan configuration file. For this, follow the below-mentioned steps:

Step 1: Locate Network Interface Name

The first a user needs to do is to locate the network interface name, which can be done by typing the below command:

assign static ip ubuntu terminal

It can be seen from the output that “ens33” is the name of the network interface. A user can also find the network interface name by executing another command which is mentioned below:

assign static ip ubuntu terminal

Step 2: Modify the Netplan Configuration File

A user can do network modification using the netplan configuration file that can be accessed by executing the below command:

It opens a file using a nano text editor where a user needs to provide the information like static and default gateway IP address as shown below:

assign static ip ubuntu terminal

Save and exit the editor.

Note: A user needs to take care of the alignment and indentation just like shown in the above image or else they can face errors.

Step 3: Apply Configuration Changes

A user can apply the newly made changes to the netplan configuration file by executing the below command:

assign static ip ubuntu terminal

Step 4: Verify the Configuration Changes

These new configurations changes can be verified by executing the below command:

assign static ip ubuntu terminal

It can be seen in the output that the IPv4 address has now been changed to the provided address. 

Similarly, a user can also verify the default gateway address by executing the below command:

assign static ip ubuntu terminal

In the output the default gateway address has now also been changed.

Method 2: Using the Network Manager Command Line Interface (NMCLI)

The nmcli can be used to modify your network connection by following the steps mentioned below: 

Step 1: Create a Static Connection

A user can create a new static connection by executing the command mentioned below:

In this code ‘static-ip’ is the name of the new static connection, and then the information regarding the network interface name, IPv4, and gateway address has also been provided.

assign static ip ubuntu terminal

T his command will provide a new static IP address to the interface ‘ens33’, which will be 192.168.1.10/24 with the gateway IP address of 192.168.1.1 .

Step 2: Set the DNS Server for the Static IP

To set the DNS for the already provided IPv4, the below command is used:

assign static ip ubuntu terminal

This means that any network traffic that goes through this connection will use the specified DNS server to resolve domain names into IP addresses.

Step 3: Activate the Static Connection

A user can activate the static connection by executing the command mentioned below:

assign static ip ubuntu terminal

Step 4: Static IP Verification:

The below command can be executed if the new changes have been applied or not by typing:

assign static ip ubuntu terminal

Similarly, default gateway address can also be verified using the below command:

assign static ip ubuntu terminal

The newly made changes to set the static IP have been applied and activated.

Setting a static IP address in Ubuntu using the command line is a powerful way to ensure that your devices are reliably and consistently connected. A user can set the static ip address in Ubuntu either by modifying the netplan configuration file or by using the nmcli command. Both methods have been discussed in detail with step-by-step guides for better understanding. 

Tim Root

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.

IMAGES

  1. How to Assign Static IP Address on Ubuntu Linux

    assign static ip ubuntu terminal

  2. Assign static ip ubuntu. How to Configure Static IP on Ubuntu 18.04 (Desktop). 2019-02-20

    assign static ip ubuntu terminal

  3. How to Assign Static IP Address on Ubuntu 20.04 LTS

    assign static ip ubuntu terminal

  4. How to Assign Static IP Address on Ubuntu 20.04 LTS

    assign static ip ubuntu terminal

  5. How to install Ubuntu Server and set up static IP (WiFi) on Raspberry Pi 3

    assign static ip ubuntu terminal

  6. 👍 Assign static ip ubuntu. How to Configure static IP address in Ubuntu Server 18.04 LTS. 2019-02-19

    assign static ip ubuntu terminal

VIDEO

  1. How to assign Static IP Address in Ubuntu 17.04

  2. how to assign static ip address in kali linux

  3. AWS Networking Lab

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

  5. How to assign Static IP Address in CentOS 7.3

  6. How To Configure Static IP in Ubuntu 18.04 Desktop

COMMENTS

  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 to

  5. How to Assign Static IP Address on Ubuntu Linux

    Method 1: Assign static IP in Ubuntu using command line · Step 1: Get the name of network interface and the default gateway · Step 2: Locate Netplan configuration.

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

  7. Set static IP in Ubuntu using Command Line

    Set static IP in Ubuntu using Terminal · Step 1: Identify the correct network interface · Step 2: See current IP address · Step 3: See the

  8. Configuring networks

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

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

  10. How to Set a Static IP Address in Ubuntu

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

  11. Linux Basics

    Here are the steps to configure a static IP address with Netplan. The Netplan configuration files are in the directory /etc/netplan/. The

  12. How to Set Static IP in Ubuntu Using Command Line?

    Method 2: Using the Network Manager Command Line Interface (NMCLI) · Step 1: Create a Static Connection · Step 2: Set the DNS Server for the Static IP · Step 3:

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

  14. How To Configure Static IP Address In Ubuntu (Easy Guide)

    In Ubuntu 22.04 LTS, you can set a static IP address via the command line by editing the Netplan configuration files. Let us see how to assign