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.

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 set static ip linux 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 '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.

how to set static ip linux 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

Install and setup FTP server on Ubuntu

Install and setup FTP server on Ubuntu

Sagar Sharma

How to Change Java Version in Ubuntu

How to Open and Edit bashrc file in Ubuntu

How to Open and Edit bashrc file in Ubuntu

Setting a Static IP in Ubuntu – Linux IP Address Tutorial

Zaira Hira

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

Before You Begin

Networkmanager gui, nmcli interactive editor, how to set a static ip address on ubuntu.

ubuntu set static ip

Dynamic IP assignment generally works fine on Ubuntu, but if you plan to configure the system as a server, setting a Static IP address is a good idea. Setting a new static IP is also an effective fix for IP-related networking issues.

Ubuntu systems typically use the NetworkManager or networkd daemons for managing network connection settings. We’ll cover multiple ways to set a static IP through these backends.

We’ll deal with Class C IPv4 addresses (e.g, 192.168.10.77) in this tutorial as that’s the norm. This means the subnet prefix is 24, and you should only change the last octet (77 in the above example) when setting the static IP address. 

The rest of the address (192.168.10) should match your default gateway. For instance, the new IP address could be something like 192.168.10.215.  

Aside from this, the new static IP shouldn’t already be assigned to another device. You should also consider setting the IP outside of the DHCP range to minimize the chance of IP conflict.

If you’re new to Ubuntu, you’ll likely find NetworkManager’s graphical interface to be the most intuitive.

ubuntu network settings

Netplan is the standard method for configuring networking on Ubuntu. It reads the network configurations at boot from /{lib,etc,run}/netplan/*.yaml and writes this configuration to /run . Then, it hands off device control to the chosen daemon (networkd or NetworkManager).

You’ll find the default netplan config file named 01-network-manager-all.yaml or 50-cloud-init.yaml in the /etc/netplan directory. Let’s see what config changes you need to make to set the static IP. 

Start by checking the interface’s device name.

Use a text editor like nano to edit the config file.

Copy the following configuration.

This configuration tells Netplan to use the NetworkManager daemon. This part is included in the default config too, but after that, we’re using our own configuration to set the static IP.

  • We specified that we’re modifying the enp42s0 interface, which we know is our Ethernet connection from earlier. 
  • We set DHCP to disabled and set the interface’s IP address with the subnet prefix (192.168.10.77/24). 
  • Next, we defined routing via the default gateway and set the DNS servers. 

You can change these values while keeping the number of prefix spaces the same as above. Test if your own configuration will work with

If the config is ok, you’ll see a configuration accepted message. You can confirm that the static IP has been set with

In the first method, we used the NetworkManager GUI from the Ubuntu control center to set a static IP. This time, we’ll show how you can use the command-line version (nmcli) to do the same thing.

Start by checking the connection name.

Now, use nmcli to modify your connection and set the static IP like so

  • We’re specifying that we’re modifying ‘Wired connection 1’, which we know is our Ethernet connection from earlier. 
  • We set the IPv4 method to manual. 
  • We set the IP address with the subnet prefix.
  • We set the default gateway.
  • Finally, we set the DNS servers.

You can set your own values in place of these and start the connection with the new parameters like so

Finally, you can confirm that the static IP was set with

If setting the Static IP as done above feels confusing, or you want to learn to make further connection changes, the interactive editor is a good alternative. To start, edit the connection with it like so

Use the following commands to set the Static IP. As done earlier, we’re setting the IP assignment method to manual, then entering the IP address, default gateway, and DNS server parameters.

If you want to learn to use the editor further, enter help inside the editor to display the usable commands. Then, use the print and describe commands to learn about the configurable settings (e.g., print ipv4 , describe ipv4.gateway , etc.).

Once you’re satisfied with your new configuration, apply the changes with

Exit nmcli and verify the static IP change with

If you’re using the systemd-networkd daemon to manage your network configurations, you can also directly edit the config file to set a static IP address.  

Use a text editor to edit the config file. We’ll use nano.

Use the format provided below for your configuration.

You can change the interface name, IP address, gateway, and DNS parameters as appropriate.

Once you’re satisfied, press Ctrl + O to save the new config. Then, apply the changes by restarting the networkd service.

If you only need a static IP address for your current session, you can use the ip command to temporarily change your IP address .

Note the device’s logical name using

Now, note the current IP address with

Add a new IP address to the device like so.

Here, we added 192.168.10.77 with netmask 24 to the enp42s0 interface, which is our Ethernet connection. Now, remove the previous IP address like so

Finally, verify that the static IP was successfully set with

Do keep in mind that this IP change will revert back after the connection resets. This can mean a loss of connection, network daemon restart, or system restart.

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.

You are using an outdated browser. Please upgrade your browser or activate Google Chrome Frame to improve your experience.

Begin typing your search above and press return to search. Press Esc to cancel.

Linux Genie

how to set static ip linux ubuntu

How to set Static IP on Ubuntu

Static IP is essentially used to configure the system as a web server, or file sharing. On Linux, the IP assignment is typically done by DHCP, which stands for Dynamic Host Configuration Protocol. However, dynamic IP is prone to change and may not be suitable for services like web and media sharing. In such a situation, the system administrator configures the static IP.

In this guide, I will walk you through the process of getting a usable IP address and setting a static IP on Ubuntu.

Set Static IP on Ubuntu

To set the static IP on Ubuntu, there are a few steps that are listed below:

  • Finding the Usable IP address
  • Modifying Configuration Files

Applying the Changes and Testing

Let’s proceed with each step mentioned above.

Finding the Usable IP Address

First, check the IP address of the server using ip command.

Note the IP address, which is in my case 192,168.178.190/24. Here, 24 is the subnet mask in CIDR notation. The 24 means the first 24 bits are used for the network address , while the remaining 8 are for the host address .

The network address indicates the network to which the host is connected, and the host could be a computer or a network device. The host address is the address that indicates the host’s identity within the network.

how to set static ip linux ubuntu

To get a clear interface name, use the ip command with the show link option.

how to set static ip linux ubuntu

You may get the following interface names.

  • eth0 or enp0

Another command to list interface names is tcpdump .

how to set static ip linux ubuntu

In my case, it is enp0s1 which is the same as eth0 , it varies depending on how distribution represents them.

how to set static ip linux ubuntu

Now, note the IP address and interface name.

To proceed further, we must find the subnet mask; which is required to configure the network settings accurately.

The subnet mask can be displayed using the ifconfig -a command.

how to set static ip linux ubuntu

Here the netmask is 255.255.255.0.

To get the number of the usable number of IP, the formula is 2 (32-n) . In our case, the n is 24, 32-24=8, which we have 256 IP addresses out of which 254 will be usable.

Let’s get the first IP address and the last IP address.

To get the first usable IP address, perform an AND operation between the binaries of the IP address and the subnet mask.

And to get the last IP address, the OR operation will be performed between the inverse of the subnet mask (0.0.0.255) and the first IP address (192.168.64.0).

So now we have the first IP 192.168.64.0 and the last IP 192.168.64.255. The first and the last IP addresses of the usable addresses are generally not used, so we have a range of 192.168.64.1 to 192.168.64.254 of IP addresses to be used for static IP.

Finally, find the gateway4 address using the ip route command.

how to set static ip linux ubuntu

Now, we have all the information to set the static IP, let’s proceed to the next step.

Modifying the Configuration Files

To set a static IP on the Ubuntu server, Netplan file needs to be modified. The Netplan is a utility by Canonical that lets you easily change the network settings. It is an abstraction over two background processes, networkd, and NetworkManager. The Netplan files are located in the /etc/netplan directory and written in YAML.

how to set static ip linux ubuntu

If you do not see such a file in the directory, you can create it by following a specific naming convention. The file’s name should begin with 01-[name] and have the .yaml extension.

I suggest creating a backup of the configuration file before modifying it.

Now, open the configuration file in the nano editor.

First, type the network with a colon at the end, on the next line add an indentation and mention the renderer as networkd .

There are two renderers, NetworkManager and networkd , if you are accessing the Ubuntu server through GUI then use the NetworkManager otherwise use networkd as renderer.

In my case, I am accessing Ubuntu through the CLI interface so, I will use networkd .

Now, we will add the ethernets with a colon and on the next line, type the interface name, which is, in my case, enp0s1 . To stop the dynamic allocation of the IP address, set dhcp4 to no .

Underneath it, we will add addresses where we will insert the static IP address and then gateway4 which is 192.168.64.1 . To access your gateway4 address, use the ip route command.

Lastly, we need to set the DNS using the nameserver option in the file. The primary and secondary DNS can be changed depending on the requirement, in my case, I am setting the primary DNS as 8.8.8.8 and the secondary as 8.8.4.4 which are Google’s DNS addresses.

how to set static ip linux ubuntu

Note: Be careful with the indentations while editing the Netplan yaml file. The file will throw an error in case of bad indentation.

The Netplan file is properly modified, in the next step, we will verify and apply the changes.

Now, apply the changes using the netplan command with the try option.

If there are any errors, then it will show up, otherwise you will be asked to press the ENTER key to accept the changes.

To check whether the static IP has been configured, use the ip a command.

how to set static ip linux ubuntu

Set Static IP on Ubuntu through GUI

The process of setting the static IP on the Ubuntu server with a graphical user interface becomes easier.

Open the settings, then go to the Network or Wi-Fi settings.

Next, click on the gear icon.

how to set static ip linux ubuntu

A window will appear, open the IPv4 tab, check Manual, and set the static IP address information in the following fields.

how to set static ip linux ubuntu

Click on the Apply button to apply the changes. Next, toggle off and on the connection.

how to set static ip linux ubuntu

Go to the Details tab to find out the IP address.

how to set static ip linux ubuntu

The static IP is useful when you want to create a web server or a server through which you want to share files. To set the static IP on Ubuntu, first identify the network interface name, usable IP address, and gateway address. Then make modifications to the Netplan file.

The static IP can also be set using the graphical user interface. Open the Settings, then go to Wi-Fi or Network; click on the IPv4 tab and insert the static IP details.

Print Friendly, PDF & Email

How to set a static internal IP in Ubuntu

Setting a static internal IP in Ubuntu is easy. We suggest doing it through the settings app and the graphical user interface, to avoid the terminal.

Quick Links

How to set static internal ip in ubuntu using the gui, how to set static internal ip in ubuntu using the terminal and text editor.

There comes a time when you might have to configure Ubuntu or any other Linux distribution with a static IP address. While you can't change your external static IP address, since it's the one your internet service provider provides, you can change your internal one. This is the IP address used on your network inside your home or office.

Though many tasks on Ubuntu usually require you to visit the terminal app and deal with lines of text, changing your internal IP is easy. You can do this through the settings app and the Graphical User Interface (GUI). Of course, if you want, you can also swap things out by going through the terminal. Here's how.

Without any technical know-how or knowledge, you can set a static IP in Ubuntu through the settings app. Just note, you will have to use the terminal once to find a range of IP addresses that you can assign. Once you do that, you just tap the Windows Key or the Superkey on your device and search for Settings . Once the app is open, proceed with the steps below.

  • If you're connected to the internet via Wi-Fi, choose Wi-Fi . If you're connected via Ethernet, select Network.
  • From the list of tabs at the top, choose IPv4.
  • Under Addresses, enter the IP address, the Netmask, and the Gateway you want to use. For finding IP addresses that'll work on your network, you can proceed with the steps below.
  • When you've calculated the usable range of addresses, choose a valid IP address that falls within this range. Then, you can click Apply at the top.

Any changes you apply will automatically go into effect. If you want, you can also use the terminal to confirm your IP address. Launch it with Ctrl, Alt, and T on your keyboard. Once launched, enter the command ip addr or ip a . You should see an interface IP address listed.

If you're a bit more technical and want to set a static IP in Ubuntu using the terminal, that is possible. You'll have to edit some lines of text and go through a few extra steps, but here's how:

Setting complete

That's all you need to set up a static IP in Ubuntu. It doesn't take much effort. Remember, we're always writing about Linux, so you can check out our guide to the best Linux laptops should you need one.

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?

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
  • How do mixture-of-experts layers affect transformer models?
  • What a year building AI has taught Stack Overflow
  • Featured on Meta
  • New Focus Styles & Updated Styling for Button Groups
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network
  • AI-generated content is not permitted on Ask Ubuntu
  • Let's organize some chat workshops

Hot Network Questions

  • All my windows and UI disappeared
  • Can every spanning tree result from a depth-first search?
  • Can "sit" mean "receive no attention"?
  • Nothingness: What philosophical concept relates to how the empty set is a subset of every set?
  • When providing examples, why they switch from "to Verb" to "Verbing" in this sentence?
  • Draw a Fibonacci Swoosh
  • What are examples of "Official Observations" in a passport?
  • ESTA unnecessary anxiety
  • Academic view of graduates who go to US national labs?
  • Serge Lang's Definition of a Free Group
  • Taxicab Geometry
  • I think I downloaded spyware! I used a curl command in terminal given by a fake support user to download a .sh file
  • What's a word that would describe "Technical Aptitude" as an "attribute"
  • Any practical use for the underscore variable?
  • Can anyone explain this sacrifice?
  • Can religions die?
  • Can definitions in the Oxford Dictionary of the English Language be considered definitive in informal philosophical presentations?
  • Combining duplicate elements in a list
  • How do I deal with crying in front of my supervisor?
  • Steering wheel rotation
  • How to partially terraform Venus?
  • Hydrogen bonding autocorrelations
  • What can semigroup theory do better in the study of PDEs compared to alternative methods?
  • How do I express a negative premise in Coq?

how to set static ip linux ubuntu

Tecmint: Linux Howtos, Tutorials & Guides

How to Set Static IP Address and Configure Network in Linux

If you are a Linux system administrator, time will come when you will need to configure networking on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to setup a static IP address (at least in most cases).

Read Also: How to Set or Change System Hostname in Linux </p

This article is meant to show you how to configure static IP address on most frequently used Linux distributions.

For the purpose of this tutorial, we will use the following Internet Protocol version 4 (IPv4) details:

Configure Static IP Address in RHEL/CentOS/Fedora:

To configure static IP address in  RHEL / CentOS / Fedora , you will need to edit:

Where in the above "ifcfg-eth0" answers to your network interface eth0 . If your interface is named “ eth1" then the file that you will need to edit is "ifcfg-eth1" .

Let’s start with the first file:

Open that file and set:

Note : Make sure to open the file corresponding to your network interface. You can find your network interface name with ifconfig -a command .

In that file make the following changes:

You will only need to edit the settings for:

  • DNS1 and DNS2

Other settings should have already been predefined.

Next edit resolve.conf file by opening it with a text editor such as nano or vi :

Once you have made your changes restart the networking with:

Set Static IP Address in Debian / Ubuntu

To setup static IP address in Debian / Ubuntu , open the following file:

You may see a line looking like this:

Change it so it looks like this:

Save the file and then edit /etc/resolv.conf like this:

Restart the networking on your system with:

Your static IP address has been configured.

Conclusion:

You now know how to configure a static IP address on a Linux distro. If you have any questions or comments, please do not hesitate to submit them in the comment section below.

Previous article:

Next article:

Photo of author

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Related Posts

Set GRUB Password

How to Set GRUB2 Password in RHEL-based Systems

Add Multiple IP Addresses to NIC

How to Assign Multiple IPs to a Single Network Interface in Linux

Find Last Executed Commands in Linux

The Power of Linux “History Command” in Bash Shell

Ncdu - Disk Usage Analyzer

Ncdu – A Powerful NCurses-Based Disk Usage Analyzer for Linux

Append Text To File in Linux

How to Add Text to Existing Files in Linux

Check Running Process Time in Linux

How to Check How Long a Process Has Been Running in Linux

32 thoughts on “How to Set Static IP Address and Configure Network in Linux”

The time will come when you will need to configure networking on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to set up a static IP address (at least in most cases).

Terrible – and my ‘ linux distro ‘ isn’t the same as yours, there’s no ‘ /etc/sysconfig/ ‘ folder.

In Ubuntu 20.04 there is no interfaces file they switch to netplan . If you can update this article to include the new change it will help a lot.

thanks Raouf

Well, this isn’t correct. Just trashed my Linux mint distro

Is it public Static IP? or can I use to access data from other networks?

Failed to restart network.service: Unit network.service not found.

I’m asking a question on a fairly old thread, but just in case, is it possible to do this on a WIFI network?

For example, when using the first command (# nano /etc/network/interfaces ) in Ubuntu, the result I see is:

There isn’t an “ eth0 ” on my server because it is connected by WIFI only. Will it still work using another option?

Yes it will work I think so, just change the settings in the interfaces file as explained in this article.

I set the static IP in ifcfg-eth0, added HWADDR and UUID, but on reboot system does not associate the IP to eth0.

This is VM. Any idea why its happening and steps to troubleshoot.

I think you need to make sure that you select “ manual ” and the correct IP address, subnet mask, and gateway and save the configuration as explained in the article. Also, I personally would select a new and different IP address, so that you can really check if it has been saved by opening the terminal and typing:

after a restart.

If i set ip address as static am not able to ping google.com why and also packages are not installed.

Please give me reply as soon as possible.

@Rajeshkar,

Please add the DNS Name servers in your /etc/resolv.conf file..

@Ravi Saive thanks for your reply , yes i did /etc.resolv.conf also but getting the same problem

@Rajesekar,

The file is /etc/resolv.conf , in this file add your DNS name servers for example.

When I enter the /etc/resolv.conf file, what is it supposed to look like? And when you say “edit” do you mean delete what’s there and write what you’ve provided, or just add new lines?

Hello Marin, Thank you very much for this article. It was a major help in my class project. This is my first time using a vm and it is an awesome learning experience. I’m really glad I ran into this article, it was well written and easy to follow.

Just wanted to say a million thank you’s for this well-written, comprehensive and easily-understood article! Awesome stuff! A real lifesaver too, as I had to quickly configure a static IP for myself to get access to remote computing. Thank you! :-D

A question from a linux newbie. Does this instruction apply for both ubuntu running on my desktop PC as well as debian linux on an embedded board?

Yes, the instructions will works on any Debian/Ubuntu based distribution without any issues..have you tried on your embedded board? does these instructions worked? let us know.

Hi Ravi, thanks for your reply.

Default the folder /etc/sysconfig does not exist on my embedded system. Of Course i could create it as well as the files mentioned, but it would be out of the context of this instructions.

Thanks, Rob

I found here very good stuff! You are doing an excellent job and I like your site! Thanks!

Thanks for finding this site very useful and thanks for appreciating our work, Keep visiting for more such useful articles…

Great job, I was I actually looking for an article like this one. So thank you so very much. Keep up the good work.

Thanks for appreciating and finding this article useful, keep connected to Tecmint for such wonderful articles…:)

What if I have 2 NICs on my server one for LAN & one for WAN and I want to set one of them (WAN) as default gateway? How to configure this server as gateway and as a router.

The easiest way to add default gateway using route command as shown:

Don’t forget to replace the gateway IP address and interface-name in the above command.

One can also use following command to setup static IP on eth0 interface for example. # ifconfig eth0 192.168.1.1 netmask 255.255.255.0 up # route add default gw 192.168.0.1 # service network restart

Thanks for the tip, but I think setting IP address directly from the commandline using ifconfig and route will only allow you to set temporarily, once you reboot, these settings disappears. So, the best option to set static IP address permanently in network configuration files only….

wipe on reboot, so that best option is to set permannetly

Hello Ravi, What is difference between the service “NetworkManager” and “network”

@Augustine,

This article will help you to understand the difference between and NetworkManager and Network: http://askubuntu.com/questions/1786/what-is-the-difference-between-network-manager-and-ifconfig-ifup-etc

Why do we need to specify DNS in both ifcfg-eth0 and resolvlf.conf?

Hello Augustine,

Actually if you have added the DNS servers in the ifcfig-eth0 file the DNS servers will be automatically added to /etc/resolv.conf. You can skip defining the DNS servers in the ifcfig-eth0 file, but then you will need to have them set in /etc/resolv.conf manually. It’s a good practice to make sure that the DNS servers are specified correctly in both files, this is why the article says to set them in both files.

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.

UbuntuMint – Everything About Ubuntu Linux

How to Set Static IP Address on Ubuntu Linux

On Ubuntu 18.04 and later versions, there is a new way to set an IP address i.e., Netplan . This tutorial describes how to set an IP address from the command line on Ubuntu Linux by using the Netplan utility.

Set an IP Address with Netplan on Ubuntu

Netplan is the new way to set an IP address on newer versions of Ubuntu ( Ubuntu 18.04 and later.) With netplan , network configurations are consolidated and saved under /etc/netplan with a .yaml extension.

Firstly, run the command below to change into the netplan directory and then list the contents of the netplan directory as follows.

You should see the default Netplan configuration file. Mine is named 01-network-manager-all.yaml on my Ubuntu 20.04 machine. Yours might be named something slightly different, depending on your Ubuntu version.

Netplan Configuration Files

It is advisable to create a backup of the default netplan configuration file as follows.

Next, run the command below to confirm the name of the network interface for which you want to set an IP address.

Check Network Interface Name

In this example, I am working with network interface eth0 .

Configure IP Address in Ubuntu

Now, open the default Netplan configuration file for editing with the command below.

You would need to make changes to the file so that it looks similar to what you see in the image below. In my case, the new additions are marked with a red border.

Configure IP Address in Ubuntu

Note : Proper indentation is important when working with YAML configurations. You do not have to use the exact same spacing in my example above. You may choose to use a fixed number of spaces for each level of indentation.

Save and close the configuration file.

Next, run the following command to check for syntax errors in the Netplan configurations.

Test Netplan Configurations

When prompted, press enter to accept the configuration. If the configuration is accepted, you are on course. Otherwise, review your configuration and test again.

Apply Netplan and Verify IP Address

Finally, apply your Netplan configurations with the command below.

You may now verify your updated network settings as follows.

Check IP Address in Ubuntu

In this tutorial, we described the steps to set an IP address on Ubuntu by using the Netplan utility. We hope that you find this very helpful.

How to Batch Convert PNG Images to JPG Format in Linux

How to Add a New Device to BTRFS File System in Linux

Photo of author

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

RECOMMENDED ARTICLES

How to Find Network MAC Address in Linux System

How to Change Network MAC Address in Linux

How to Set a Static IP Address in CentOS Linux

How to Check Linux Network Statistics from Command Line

How to Check a Port is Open on a Remote Linux System

Got something to say? Join the discussion. Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Save my name, email, and website in this browser for the next time I comment.

How to Configure Static IP Address on Ubuntu

admin

In this article, we are going to learn how to configure a static IP address on Ubuntu 22.04. Typically, in most network configurations, the IP address is assigned dynamically by the router’s DHCP server. Setting a static IP address may be required in different situations, such as configuring port forwarding or running a media server or other service which is needed a static IP address.

Prerequisites

  • Ubuntu system
  • User with Sudo privileges

In this tutorial you will learn how to:

  • Set the static IP address on Ubuntu Desktop using a NetworkManager
  • Configure the static IP address on the Ubuntu server via the network daemon

Static IP Address on Ubuntu

There are two ways to configure static IP addresses on Ubuntu.

GUI Interface Mode

Command linux interface mode.

The simplest approach how to configure a static IP address on Ubuntu Desktop is via GNOME graphical user interface:

Go to Settings > Network > Click on the Setting icon.  Click on IPv4 > Select the manual option. And then enter your static IP address.

IP Address on Ubuntu

To configure a static IP address on your Ubuntu server you need to modify a relevant netplan network configuration file within the /etc/netplan/ directory .

Command Linux Interface Mode

To set your network interface enp0s3 to static IP address 192.168.1.233 with gateway 192.168.1.1 and DNS server as 8.8.8.8 and 8.8.4.4 replace the above configuration with the one below.

Ubuntu Server IP Configuration

Ubuntu server configured with the static IP address. Now you can deploy any service over here.

Once ready apply changes with:

In case you run into some issues execute:

That is all! In this article, you have learned about static IP addresses on the Ubuntu system. Now you can easily change your IP address if you do not want the DHCP server IP address.  All the commands and procedures described in this article are also valid for Debian, Mint, and previous Ubuntu releases.

Related Linux Tutorials:

  • How to Install Cisco Packet Tracer on Ubuntu.
  • How to install Tweak Tool on Ubuntu 21.04.
  • ZSH to BASH | How to Install ZSH on Ubuntu.
  • How to Install Ubuntu.
  • How to Install PuTTY on Ubuntu

How to Install Ubuntu Server 22.04 LTS

How to install ubuntu 22.10 | ubuntu for desktop.

Linuxips is a Linux blog that publishes articles and tutorials about server operations, installations, new techniques and Linux security.

Related Posts

How To Use AppImage in Linux

How To Use AppImage in Linux [Complete Guide]

How To Install uGet Download Manager On Ubuntu

How To Install uGet Download Manager On Ubuntu

How to Install ZSH on Ubuntu 22.10

How to Install ZSH on Ubuntu 22.10

How to Install Terminator on Ubuntu

How to Install Terminator on Ubuntu, a Linux Terminal Emulator

How to Install Tweak Tool on Ubuntu

How to install Tweak Tool on Ubuntu 22.04

How to Install Ubuntu 22.10 (Kinetic Kudu)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

You might also like

Install ZSH on Arch Linux

How to Install ZSH on Arch Linux

How to Install ZSH on Kali Linux 2024.1

How to Install ZSH on Kali Linux

How To Use AppImage in Linux

Linux Files and Directories

© 2024 Linuxips.com - Linux Tips, Tricks and Tutorials.

  • Web Stories
  • Privacy 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 Set Static IP Address on Ubuntu Server 22.04

In this post, we will cover how to set static ip address on Ubuntu server 22.04.

It is highly recommended to have a static ip on linux server because it would be persistent across the reboot. Static IP plays an important role for servers like Mail Server, Web Server and File server etc.

Prerequisites

  • Minimal Installed Ubuntu Server 22.04
  • Regular User with sudo admin rights

In Ubuntu server 22.04, networking is controlled by netplan utility , so we will use netplan to configure static ip address on Ubuntu server.

Note: we cannot use nmcli utiltity as it is not the part of default installation on Ubuntu server.

Setting up Static IP address on Ubuntu Server 22.04

Login to your Ubuntu server 22.04, look for the netplan configuration file. It is located under /etc/netplan directory.

Run below cat command to view the contents of ‘00-installer-config.yaml’

Note: Name of configuration file may differ as your per setup. As it is an yaml file, so make sure to maintain the indentation and syntax while editing.

Default-Content-netplan-ubuntu-server

As per above output, it says that we have ens33 interface and it is getting ip from dhcp server. Alternate way to view interface name is via ip command.

Now, to configure static ip in place of dhcp, edit netplan configuration file using vi or nano editor and add the following content.

save and close the file.

Updated-Netplan-Config-File-Content-Ubuntu-Server

In the above file we have used following,

  • ens33 is the interface name
  • addresses are used to set the static ip
  • nameservers used to specify the DNS server ips
  • routes used to specify the default gateway

Note: Change the IP details and interface name as per your environment.

To make above changes into the effect the apply these changes using following netplan command,

Run following ip command to view the ip address on interface,

To view the default route, run

Output of above commands,

ip-addr-route-command-output-ubuntu-server

Perfect, above commands’ output confirms that static ip and route has been configured successfully.

That’s all from this post. Kindly do post your queries and feedback in below comments section.

11 thoughts on “How to Set Static IP Address on Ubuntu Server 22.04”

How do I use Netplan to set up a static IP address on WIFI?

change the network device “ens33” to something else, it will be listed when you run “ip a”; it;s probably wlan0 but that’s not guaranteed.

there will be a config file for the wifi interface. look for something like 00-installer-config-wifi.yaml

Hey! thanks I had problems before setting up the DNS and none config would work! This one did and you made this post really simple to follow!

Your text for configuring a static IP address does not work in my Ubuntu 20.04.5 server’s NIC. No matter how I space or tab the indentations, I get “Ivalid YAML: inconsistent indentation: addresses:

I’ve been at the problem for a couple of weeks, with no fix in site; no spacing or tabbing change I make fixes it. Can anyone please advise me? Thanks.

try paste the YAML into here ‘https://www.yamllint.com/’

Copy paste not work here, you should try typing instead or if you paste, try to delete all the space before each line and tab key until the same format

The spacing must be done with the space key. If you try to make spaces in a yaml file with the tab key it will not work. Also you should let yamllint.com correct the file for you

Your article is quite nice and clear! but after followed, following error occurred when ping google.com: “temporary failure in name resolution”, meanwhile localhost can be visited. Is anyone facing this issue as well? I’ll quite appreciate it if can get some advise.

can we use default DHCP ip configuration along with another static ip in ubuntu 22.04 ? i already have ens33 then i added eth0 as static ip , netplan apply did not thrown any errors but unable to see my static ip , when i do ifconfig 🙁 even after reboot its not applying, any suggestions..

i successfully set up my static ip but I cant ping to 192.168.1.1 why

Leave a Comment Cancel reply

  • Español – América Latina
  • Português – Brasil
  • Compute Engine
  • Documentation

Configure static external IP addresses

You can assign static external IP addresses to your virtual machine (VM) instances. You can also change, list, and release static IP addresses for your VMs. To reserve a static external IP address, see Reserve a static external IP address .

External IP addresses can be static or ephemeral . If a VM requires a fixed external IP address that does not change, do the following:

  • Obtain a static external IP address. You can reserve new external IP addresses or promote existing ephemeral external IP addresses.
  • Assign the reserved IP address to an existing VM, or assign it when creating a new VM.

If you require a static IP address on your internal Compute Engine network, see Reserve a static internal IP address instead.

Before you begin

  • Read about IP addresses .
  • Read about quotas and limits for static external IP addresses .
  • Read about external IP address pricing .

Select the tab for how you plan to use the samples on this page:

When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

Install the Google Cloud CLI, then initialize it by running the following command:

  • Set a default region and zone .

To use the Terraform samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.

  • Install the Google Cloud CLI.

To initialize the gcloud CLI, run the following command:

Create local authentication credentials for your Google Account:

For more information, see Set up authentication for a local development environment .

To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

Required roles

To get the permissions that you need to configure and manage static IP addresses, ask your administrator to grant you the following IAM roles on your project:

  • To create and update VMs: Compute Instance Admin (v1) ( roles/compute.instanceAdmin.v1 )

For more information about granting roles, see Manage access .

These predefined roles contain the permissions required to configure and manage static IP addresses. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to configure and manage static IP addresses:

  • compute.instances.update on the VM instance
  • compute.instances.updateNetworkInterface on the VM instance
  • compute.instances.addAccessConfig on the VM instance
  • compute.instances.deleteAccessConfig on the VM instance
  • compute.networks.list on the network
  • compute.subnetworks.use on the subnet
  • compute.subnetworks.list on the subnet
  • compute.instances.create on the project
  • To use a custom image to create the VM: compute.images.useReadOnly on the image
  • To use a snapshot to create the VM: compute.snapshots.useReadOnly on the snapshot
  • To use an instance template to create the VM: compute.instanceTemplates.useReadOnly on the instance template
  • To assign a legacy network to the VM: compute.networks.use on the project
  • To specify a static IP address for the VM: compute.addresses.use on the project
  • To assign an external IP address to the VM when using a legacy network: compute.networks.useExternalIp on the project
  • To specify a subnet for the VM: compute.subnetworks.use on the project or on the chosen subnet
  • To assign an external IP address to the VM when using a VPC network: compute.subnetworks.useExternalIp on the project or on the chosen subnet
  • To set VM instance metadata for the VM: compute.instances.setMetadata on the project
  • To set tags for the VM: compute.instances.setTags on the VM
  • To set labels for the VM: compute.instances.setLabels on the VM
  • To set a service account for the VM to use: compute.instances.setServiceAccount on the VM
  • To create a new disk for the VM: compute.disks.create on the project
  • To attach an existing disk in read-only or read-write mode: compute.disks.use on the disk
  • To attach an existing disk in read-only mode: compute.disks.useReadOnly on the disk

You might also be able to get these permissions with custom roles or other predefined roles .

Limitations

Only one resource at a time can use a static external IP address.

There is no way to check whether an IP address is static or ephemeral after it has been assigned to a resource. You can compare the IP address against the list of static external IP addresses reserved to that project. Use the gcloud compute addresses list sub-command to see a list of static external IP addresses available to the project.

Each VM can have multiple network interfaces , and each interface can have the following IP addresses assigned:

  • An internal IPv4 address (required)
  • An external IPv4 address
  • An IPv6 address range, either internal or external, but not both

You cannot change the name of a static IP address.

Assigned external IP addresses exist on the same physical host as the VM and exist in the same region as the VM for all purposes, including routing, latency, and pricing. This is true regardless of internet geolocation lookup information.

Note: Network interfaces can receive traffic from multiple forwarding rules , which might serve other external IP addresses. Any number of external IP addresses can reference a network interface through these forwarding rules, but each network interface can be assigned only one external IPv4 address and one external IPv6 address range.

For more information about load balancing and forwarding rules, read the load balancing documentation.

View available static external IP addresses

To list static external IP addresses that you have reserved for your project, follow these steps.

In the Google Cloud console, go to the IP addresses page.

Go to IP addresses

Click External IP addresses .

Use the gcloud compute addresses list command :

To list all IP addresses, use the following command:

To list all global IP addresses, use the following command:

To list all regional IP addresses in a given region, use the following command:

Replace REGION with the region that you want to list addresses for. You can list addresses of multiple regions by specifying comma-separated region names:

To list regional IPv4 or IPv6 addresses, call the addresses.list method :

Replace the following:

  • PROJECT_ID : the project ID for this request
  • REGION : the name of the region for this request

To list all addresses in all regions, call the addresses.aggregatedList method :

To list global IPv4 or IPv6 addresses, call the globalAddresses.list method :

The following sections describe how to configure static external IP addresses for your VMs.

Create a VM that uses a static external IP address

After you have reserved a static external IP address , you can assign it to a VM.

In the Google Cloud console, go to the Create an instance page.

Go to Create an instance

Specify the VM details.

Expand the Advanced options section.

Expand the Networking section.

In the Network interfaces section, expand a network interface to edit it.

To assign an IPv4 address, do the following:

  • Select a network.
  • Select the IP address from the External IPv4 address list.

To assign an IPv6 address, do the following:

  • Select a network that contains an IPv6 subnet.
  • Select a dual-stack subnet from the Subnetwork list.
  • For IP stack type , select IPv4 and IPv6 (dual-stack) .
  • Select the newly reserved external IPv6 address from the External IPv6 address list. Alternatively, select CREATE IP ADDRESS and reserve a new static external IPv6 address.
  • For Network Service Tier , select Premium .

To finish modifying the default network interface, click Done .

Continue with the VM creation process.

You can create a VM and assign a static regional external IP address that you have already reserved.

To assign a static external IPv4 address, do the following:

  • VM_NAME : the name of the VM.
  • IP_ADDRESS : the IP address to assign to the VM. Use the reserved static external IP address, not the address name.

To assign a static external IPv6 address, do the following:

You can use the google_compute_instance resource to assign an external IP address.

To assign a static external IPv4 address to a new VM, do the following:

In your request to create a new VM , explicitly provide the networkInterfaces[].accessConfigs[].natIP property and the external IPv4 address that you want to use. For example:

To assign a static external IPv6 address to a new VM, do the following:

In your request to create a new VM , explicitly provide the networkInterfaces[].ipv6AccessConfigs[].externalIpv6 property and the external IPv6 address that you want to use. For example:

Change or assign an external IP address to an existing VM

You can change or assign an external IP address, either ephemeral or static, to an existing VM.

A VM can have multiple interfaces and each interface can have an external IP address. If the VM already has an external IP address, you must remove that address first. Then, you can assign a new external IP address to the existing VM.

Go to VM instances

  • Click the name of the VM that you want to assign an external IP to. The Instance details page displays.

From the Instance details page, complete the following steps:

  • Click Edit .
  • Expand Network interfaces .
  • For External IPv4 address , select either Ephemeral or a static external IPv4 address.
  • For External IPv6 address , select either Ephemeral or a static external IPv6 address.
  • Click Done .

Click Save .

Optional: Reserve a static external IP address.

If you want to assign a static external IP address, you must reserve an address and make sure that the address is not in use by another resource. If necessary, follow the instructions to reserve a new static external IP address or to unassign a static external IP address .

If you intend to use an ephemeral external IP address, you can skip this step, and Compute Engine randomly assigns an ephemeral external IP address.

Remove any existing IP address assignment, as described in Unassign a static external IP address .

Assign the new external IP address.

To assign an IPv4 address, use the instances add-access-config sub-command :

  • ACCESS_CONFIG_NAME : the name to call this access config. Make sure to include the full name between quotes.
  • IP_ADDRESS : the IP address to add.

If you want Compute Engine to assign an ephemeral external IP address rather than using a static external IP address, omit the --address IP_ADDRESS property:

To assign an IPv6 address range, use the instance network-interfaces update sub-command :

  • NIC : the name of the network interface.
  • IPV6_ADDRESS : the IPv6 address to assign to the VM. Specify the first IPv6 address in the /96 range.
  • ZONE : the zone of the VM.

You can change the external IPv4 or IPv6 address of a VM by adding a new access configuration for that VM.

Delete the existing access configuration by making a POST request to the instances.deleteAccessConfig method .

Add a new access configuration to the network interface of the VM by making a POST request to the instances.addAccessConfig method .

For IPv4 addresses, make the following request:

For IPv6 addresses, update the networkInterfaces[].ipv6AccessConfigs[].externalIpv6 property and the external IPv6 address that you want to use.

See Assign a static external IP address to a new VM

Restrict external IP addresses to specific VMs

For certain workloads, you might have essential requirements that include security and network restrictions. For example, you might want to restrict external IP addresses so that only specific VMs can use them. This option can help to prevent data exfiltration or maintain network isolation. Using an Organization Policy , you can restrict external IP addresses to specific VMs with constraints to control use of external IP addresses for your VMs within an organization or a project.

The constraint for controlling external IP address on VMs is:

To use the constraint, you specify a policy with an allowedList of VMs that can have external IP addresses. If you don't specify a policy, all external IP addresses are allowed for all VMs. When the policy is in place, only the VMs that are listed in the allowedValues list can be assigned an external IP address, either ephemeral or static, and other Compute Engine VMs in the organization or project that are not explicitly defined in the policy are prohibited from using external IP addresses.

VMs are identified in the allow and deny lists using the VM's URI:

Specifications for restricting external IP addresses

  • You can apply this list constraint only to VMs.
  • You cannot apply the constraint retroactively. All VMs that have external IP addresses before you enable the policy retain their external IP addresses.
  • This constraint accepts either an allowedList or a deniedList but not both in the same policy.
  • It is up to you or an administrator with the required permissions to manage and maintain the VM lifecycle and integrity. The constraint only verifies the VM's URI, and it does not prevent the VMs in the allowlist from being altered, deleted, or recreated.

Permissions needed for restricting external IP addresses

To set a constraint on either the project or the organization level, you must have been granted the orgpolicy.policyAdmin role on the organization.

Set the policy constraint at the organization level

Go to Organizational Policies

  • If necessary, select the required organization from the project drop-down menu.
  • Click Define allowed external IPs for VM instances .
  • Click Edit to edit the external IP policy. If you can't access the Edit tool, you don't have the correct permissions .

Select Customize to set the org policy for specific VMs.

Customize option on the edit organization policy page.

Select the required Policy enforcement and Policy type .

For Policy values , select Custom .

Enter a URI for a VM and press enter. The URI must be in the following format:

Click New policy value and enter URIs for VMs as needed.

Click Save to apply the constraint.

To set a constraint for external IP access, you first need your organization ID. You can find the organization ID by running the organizations list command and looking for the numeric ID in the response:

The gcloud CLI returns a list of organizations in the following format:

Use the gcloud resource-manager org-policies set-policy command to set the policy. You need to provide your policy as a JSON file. Create a JSON file in the following format:

  • PROJECT_ID : the project ID for this request, such as example-project . Note that this is different than setting up organization policies, which require the organization numeric ID.
  • ZONE : the zone of the VM
  • VM_NAME : the name of the VM

Alternatively, you can specify a deniedValues list to indicate VMs that you explicitly want to prohibit from having an external IP address. Any VM not on the list would implicitly be allowed to have an external IP address. You can only specify either allowedValues or deniedValues but not both.

Then, pass in the file with your request:

Replace ORGANIZATION_ID with the numeric ID of the organization.

If you don't want any VMs to have external IP access, you can set a policy with allValues set to DENY :

Use the setOrgPolicy() API to define your constraint. The VMs in the allowedValue list you specify are allowed to have external IP addresses. Alternatively, you can specify a deniedValues list to express VMs that you explicitly want to prohibit from having an external IP address. Any VM not on the list would implicitly be allowed to have an external IP address. You can only specify either allowedValues or deniedValues but not both.

For example, the following is a request to apply the compute.vmExternalIpAccess constraint to an organization where VMs from certain projects within the organization are allowed to have external IP addresses:

where ORGANIZATION_ID is the numeric ID of the organization.

Now, in your request body, provide the policy for this constraint:

Set the policy at the project level

Setting a policy at the project level overrides the policy at the organization level. For example, if the organization level has example-vm-1 on the allowedValues list but the policy at the project level has the same VM on the deniedValues list, the VM wouldn't be allowed to have an external IP address.

Follow the same process documented under Set a policy constraint at the organization level but choose your project from the project selector instead of the organization.

Project selector.

Alternatively, you can specify a deniedValues list of VMs that you explicitly want to prohibit from having an external IP address. Any VM not on the list would implicitly be allowed to have an external IP address. You can only specify either allowedValues or deniedValues but not both.

Use the setOrgPolicy API to define your constraint. The VMs in the allowedValue list you specify are allowed to have external IP addresses. Alternatively, you can specify a deniedValues list to express VMs that you explicitly want to prohibit from having an external IP address. Any VM not on the list is implicitly allowed to have an external IP address. You can only specify either allowedValues or deniedValues but not both.

For example, the following is a request to set the compute.vmExternalIpAccess constraint on a project to allow specific VMs to have external IP addresses:

Replace PROJECT_ID with the project ID for this request.

The request body contains the policy for this constraint:

Best practices for restricting external IP addresses

Avoid using the deniedValues list with this constraint. If you define values in the deniedValues list, it means that only the VMs in the deniedValues list are restricted from using external IP addresses. This could be a security concern if you want control over exactly which VMs can have external IP addresses. If you want to remove certain VMs from the allowedValues list, update the existing policy to remove the VMs from the allowedList rather than putting the VMs into the deniedValues list at a lower hierarchy.

If you want to set a policy over a large part of the resource hierarchy but exempt certain projects, restore the default policy by using the setOrgPolicy method by specifying the restoreDefault object to allow all VMs in the projects to be associated with external IP addresses. The current policies for projects are not affected by the default setting.

Use the org policy together with IAM roles to better control your environment. This policy applies to only VMs but if you want to better control and restrict external IP addresses on network devices, you can grant the compute.networkAdmin role to the appropriate parties.

Any services and products that are running on Compute Engine within the organization or project with the policy enabled are subject to this org policy. Specifically, services such as Google Kubernetes Engine, Dataflow, Dataproc, and Cloud SQL are affected by this policy. If this is an issue, Google recommends that you set up other services and products in a different project that does not have the organization policy applied, and use Shared VPC , if needed.

Manage static external IP addresses

The following sections describe how to manage static external IP addresses for your VMs.

Determine if an internal IP address is ephemeral or static

Static and ephemeral internal IP addresses behave and appear the same in most contexts. However, with static internal IP addresses, you can use the same IP address for the same resource even if you delete and re-create the resource. In general, an ephemeral IP address is released if you stop or delete the resource.

To determine if an address is static or ephemeral, do the following:

Find the address in the list and check the Type column for the type of IP address.

Unassign a static external IP address

Unassigning an IP address removes it from the resource but keeps the IP address reserved. After the IP address is unassigned, you can reassign the IP address to another resource.

You can also unassign the IPv4 or IPv6 address by deleting the VM .

Select the static IP address that you want to unassign.

Click Change to open the Attach IP address dialog.

From the Attach to drop-down list, select None .

Check if a static IP address is in use by using the gcloud compute addresses list command :

The output is similar to the following:

  • If the IP address is not in use, the status is RESERVED .
  • If the IP address is in use, the status is IN_USE .

Retrieve the name of the VM that is using the IP address:

  • ADDRESS_NAME : the name of the IPv6 address resource.
  • REGION : the region of the IPv6 address resource.

The users field displays the name of the VM that is using the IP address.

Unassign the IP address from the VM.

To unassign an IPv4 address, delete the VM's access config file:

Get the name of the access config to delete. To get the name, use the gcloud compute instances describe command . Replace VM_NAME with the name of the VM.

The access config appears in the following format:

Delete the access config by using the gcloud compute instances delete-access-config command :

  • ACCESS_CONFIG_NAME : the name of the access config to delete. Be sure to include the full name between quotes.

To unassign an IPv6 address range, use the instance network-interfaces update command :

  • VM_NAME : the name of the VM that is using the IP address.

Check that your static external IP address is now available and marked as RESERVED instead of IN_USE .

  • ADDRESS_NAME : the name of the IP address resource.
  • REGION : the region of the IP address resource.

Now that your static external IP address is available, you can choose to assign it to another VM .

To unassign a static external IPv4 or IPv6 address, perform the following steps:

For IPv4 addresses, delete the access configuration attached to the VM that's using the address.

To check the access configuration details of a VM, make a GET request to the instances.get method .

  • ZONE : the zone where the VM is located

For IPv6 addresses, update the stack type of the network interface for the VM where the IPv6 address is attached.

Make a PATCH request to the instances.updateNetworkInterface method .

In the request body, update the value of the stackType field to IPV4_ONLY .

For example:

Release a static external IP address

If you no longer need a static external IPv4 or IPv6 address, you can release the IP address by deleting the IP address resource. Deleting a VM does not automatically release a static external IP address. You must manually release static external IP addresses when you no longer require them.

To release a static external IP address, see Release a static external IP address in the VPC documentation.

What's next

  • Learn more about IP addresses .
  • Learn more about networks and firewalls .
  • Learn how to address VMs using internal DNS .
  • Review VPC pricing .

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-04-05 UTC.

  • Shell Scripting
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Bash Pathname Expansion in Linux
  • TryHackMe - Passive Reconnaissance Solution
  • Linux Loadable Kernel Module
  • Micro - Lightweight terminal based text editor
  • Features of Unix
  • How to Append Text to End of File in Linux?
  • How to Customize Linux Terminal Using powerlevel10k?
  • HISTTIMEFORMAT variable in Linux with Example
  • How to Convert .rpm package to .deb using alien Package Converter?
  • Getting into Android OS remotely using Kali Linux
  • Basics of Batch Scripting
  • Input Output Redirection in Linux
  • Process Management in Linux
  • Anonymity and Privacy For Linux User
  • How to Generate a Self-Signed Certificate with OpenSSL in Linux?
  • What is Linux Operating System
  • How to run Linux Commands on Windows 10?
  • How To Setup Proxychains In Linux Without Any Errors?

How to Install and Use Telnet on Ubuntu 22.04 LTS

In Ubuntu, client-server communication involves using Telnet, a network protocol that allows you to connect to remote servers and devices over a TCP/IP network. Telnet on Ubuntu 22.04 LTS enables you to establish text-based communication with servers for various purposes such as remote administration, troubleshooting, and testing network services. In this article, we will explore the installation and usage of Telenet on Ubuntu 22.04.

What is Telnet?

Telnet is a network protocol used for remote terminal access and communication over a TCP/IP network . It allows a user to log in to a remote computer or device and execute commands as if they were directly connected to that system. Telnet operates on port 23 by default and provides a text-based interface, making it suitable for tasks such as remote administration, debugging, and accessing network services. However, it’s important to note that Telnet sends data, including login credentials, in plain text, which can pose security risks, leading to its decreased usage in favor of more secure protocols like SSH (Secure Shell) .

Installation of Telnet on Ubuntu 22.04

In this section, we will see the process to install Telnet on Ubuntu 22.04. Execute the below-stated commands to install Telnet without encountering any errors.

Step 1: First open the terminal in your Ubuntu machine.

Step 2: Run the below command to check Telnet’s availability in the Ubuntu repository. It shows version 0.17 .

Check Telnet's Availability

Check Telnet’s Availability

Step 3: Now install the Telnet using apt manager . Execute the below command in the terminal.

Installing telnet

Installing telnet

Step 4: Once the installation is completed, check the status of the Telnet, it should be active.

Telnet's Status

Telnet’s Status

Note: As Telnet uses default port 23, so if your computer will block this port then you will not be able to establish the connection between your computer and the remote server. So for that we need to configure the firewall.

Step 5: Now check if the firewall is active or not by using the below command to check its status (in our case it’s inactive ).

Firewall Status

Firewall Status

Step 6: If your firewall is not active then enter the below command to enable the firewall otherwise skip this step.

Enabling firewall

Enabling firewall

Step 7: Now allow port 23 as all communication will be done through that port, by using the below command.

Allow port 23 in firewall

Allow port 23 in the firewall

Step 8: Now we have to connect to the other computer by using its IP address by using the below command.

If you don’t have any other computer to test then you can test by filling in your own computer’s loopback address by using 127.0.0.1 or localhost .

Connecting Using Telnet

Connecting Using Telnet

Now we are connected to the remote server and you can access it fully, we can use it for whatever reasons you want to install telnet.

Step 9: To exit Telnet, type Ctrl+] , then type quit , and press Enter .

Usage of Telnet

Telnet serves numerous purposes, exemplified through practical scenarios. Let’s explore its usage through an example.

Example 1: Verifying Accessibility of an HTTP Server

Step 1: We can check the availability of any HTTP server by using the below command.

This uses default port 80 to connect to Google’s Web Server:

Connect to Web Server

Connect to Web Server

Step 2: Now send an HTTP request by typing the below code in the terminal.

Send HTTP request

Send HTTP request

Step 3: We will get the response back from the Server if the connection is successful and it will include the Date, Cache-Control, Accept-Ranges, Response code, etc, and possibly the content also of the webpage.

Here we got the Status Code of 200 and the content of the homepage of www.google.com.

Response from Google's Server

Response from Google’s Server

Example 2: Telnet to Test Open Ports

We can test for the open ports on a remote server using telnet. We’ll check for port 80 on a remote server

Step 1: To test the open port you have to use the IP address or hostname with the port that you want to test.

Port 80 is open

Port 80 is open

And if the Port is not open then you will get a connection refused response.

Port 74 is not open

Port 74 is not open

Example 3: Telnet to test a Mail Server

Step 1: Use the below syntax to use telnet to connect to the mail server.

Connecting to mail server

Connecting to the mail server

Step 2: Now that the connection is successful, send the ehlo command . This command begins the SMTP session and introduces the client (you) to the server as example.com and gives back a list of supported features lists in response

ehlo command

ehlo command

Step 3: Now you can interact with the mail server by sending an email, checking the email queue, checking server status, troubleshoot issues, etc.

Step 4: When work is done you can exit it using the quit command.

Quit mail server

Quit mail server

FAQs on Install and Use Telnet on Ubuntu 22.04 LTS

Is telnet secure.

No, Telnet is not secure at all. It sends data in plain text instead of encrypted one making it vulnerable to cyber attacks and data being stolen.

How to exit in Telnet?

First press Ctrl+], then type quit or type exit.

How to start telnet?

You need to type Telnet followed by IP Address of the remote machine. Like Telnet 192.168.1.10

How to check the status of Telnet?

To check the status of Telnet type in CLI: sudo systemctl status inetd

What are alternatives to Telnet?

Some alternatives of telnet are SSH, Netcat, PuTTY, SecureCRT etc.

In conclusion, telnet is used to connect to a remote computer server to access it. But the disadvantage is that the communication channel is not encrypted so anyone who can access the communication channel can see all the passwords, usernames, and other important information. But still, Telnet is used in older computers. Whereas it’s still being used for Network Troubleshooting, education purposes, etc. But it’s better to look and learn its other secure alternatives like SSH.

Please Login to comment...

Similar reads.

author

  • How to Use ChatGPT with Bing for Free?
  • 7 Best Movavi Video Editor Alternatives in 2024
  • How to Edit Comment on Instagram
  • 10 Best AI Grammar Checkers and Rewording Tools
  • 30 OOPs Interview Questions and Answers (2024)

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

It's FOSS

Set Static IP Address on Raspberry Pi

Abhishek Prakash

Recently, I set up Jellyfin media server on my Raspberry Pi. My Pi is wirelessly connected to the router and one problem I faced with this setup is accessing the media server on the TV or other devices.

Why? Because the Pi got assigned a random IP address at times between reboots. And since I was trying to access the media server running on Raspberry Pi though the IP address, it became an issue.

I had to manually enter the IP address on the TV every time the IP address changed. Finding the IP address of the Raspberry Pi was another challenge.

This is where static IP comes into play. If you Pi uses static IP, the IP address remains the same between the reboots.

This is one of the many scenarios where you are better off with a static IP assigned to your Pi. And in this tutorial, I'll discuss how you can achieve that.

Assigning static IP on Pi device vs on the router

Yes! There are two approaches for your Pi to have a static IP.

  • You can set static IP on the Raspberry Pi itself
  • You can have your router assign a static IP to the Pi

Both methods have their pros and cons.

Let's say you set the static IP on the Raspberry Pi . Your Pi will always seek the same IP address from the router (let's say 192.168.1.51). That's fine as long as the router remains the same. If you change your router and the new router insists on using a different subnet (let's say in the 172.16.12.0/32 range), then your PI won't be connected to WiFi like before. You'll have to manually update the network settings on the Pi again to use the new IP range. This could work when you just a couple of Pi devices and you can directly login to them (instead of SSH) or connect to them via Ethernet cable. For a fleet of Pis in random locations in the house.

Let's say you want to assign the Pi a static IP from the router . This way, you are changing nothing on the Pi. If you change the router, the Pi will get an IP address assigned automatically through the DHCP server. The problem is that it's not easy to assign static IP to devices on all the routers. Some internet companies provide routers with very little scope of configuration changes.

I cannot show how to assign static IP to different devices on the router, as it depends on what kind of router you have. So, I'll discuss how you can set static IP on the Raspebrry Pi itself.

Setting static IP on Raspberry Pi

The procedure comprises the following four steps:

  • Get the current IP address of the Pi (if you want to use this one as static IP)
  • Get the gateway IP (router's IP)
  • Get the DNS server address (optional)
  • Use the above information to change network configuration

The first three steps can be easily done in the command line. The third step can be done easily in both the command line and GUI.

Step 1: Get the IP address of Pi

If you want to use the current IP address as the static IP,

This is very simple. In the terminal, type the following command:

You may also use this command:

Both will give you the current IP address of the Raspberry Pi.

Get IP address of Raspberry Pi

As you can see in the screenshot above, my Raspberry Pi's IP address is 192.168.1.34.

Step 2: Get the gateway IP

This is also quite simple. To get the gateway IP address (your router's IP address), use this command:

As you can see in the screenshot below, the gateway IP in my case is 192.168.1.1.

Get gateway IP address

Step 3: Get the DNS server details (optional)

Some people like to keep the same DNS server which is currently being used on the system. I think you can do without that as well. Most home users have the DHCP server handle it automatically anyway.

Still, if you want, you can get the DNS server address with:

DNS server IP address

Step 4 (Terminal Method): Change network configuration to set static IP

If you are accessing Raspberry Pi via SSH or if you prefer the command line, you can use the nmtui (network manager in terminal) tool.

Run this command:

You'll see an interface like this. Here, select Edit a connection and press Enter.

Edit network connection in Network Manager

It will show the connections you have had in the past on your Pi. I believe you want to set the static IP for the currently connected network. Move down to the appropriate network. Now press tab a couple of times to select the Edit option and press enter.

Edit network connection in nmtui

Use the arrow key to scroll down to the IPv4 CONFIGURATION option. Change it from Automatic to Manual .

Change IPv4 configuration

Next, select the Show option of IPv4 CONFIGURATION line.

Setting static IP in Raspberry Pi by changing IPv4 configuration

Use the arrow keys to move down again and reach the IPv4 CONFIGURATION section again. This time you'll see option to add Address, Gateway and DNS servers.

IPv4 configuration change

Go to the Addresses line and click enter key. It may take you to the beginning. Scroll down back again.

Static IP set in Raspberry Pi

Fill all the details such as IP address with mask, Gateway IP and DNS.

Changing IPv4 config to set static IP on Raspberry Pi

If you notice above, I used the gateway IP in DNS too. I also added 1.1.1.1, DNS of Cloudflare as an alternative.

After filling all the details, scroll down to the bottom, select OK and press enter.

Your changes are saved. You can exit the nmtui interface the same way (press Back and then Quit options).

Restart your Pi for the changes to take effect. You have successfully set up static IP on Raspberry Pi.

Step 4 (GUI Method): Change network configuration to set static IP

The same can be achieved from the graphical interface of Raspberry Pi OS.

First, click on the network icon and then go to the Advanced options and click Edit connections.

Edit connections in Raspberry Pi

Here you go to IPv4 Settings, set it to manual and then add all the details such as IP address, mask, gateway IP, DNS server etc. You have all the details.

Set static IP on Raspberry Pi

Restart your system and you can see that the static IP is now set on your Pi.

Going back to non static IP

If you don't want to use static IP anymore on Raspberry Pi, you can easily revert the steps and go back to dynamic IP.

How? Simply edit the network connection in question again. This time, change the IPv4 configuration to 'automatic' and save your changes. And that's it. You don't have to provide IP address, gateway IP etc anymore.

As I mentioned at the beginning of this tutorial, you should use a static IP from the router end specially if your Pi won't be easily accessed physically.

But if your device is in your hands all the time, you have the liberty of accessing and changing its configuration.

I hope you find this tutorial on setting a static IP on Raspberry Pi helpful. Please let me know if you have any questions.

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

How to Install Ubuntu Desktop on Raspberry Pi 4

How to install raspberry pi's raspbian os with pixel desktop on any computer, behold here is a $89 open source laptop running linux, run llms locally on raspberry pi using ollama ai, raspberry pi 3 vs 4: which one should you get, 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.

IMAGES

  1. How to Configure Static IP Address on Ubuntu 20.04

    how to set static ip linux ubuntu

  2. How to Configure Static IP Address on Ubuntu 20.04

    how to set static ip linux ubuntu

  3. How to Set Static IP Address on Ubuntu 22.04

    how to set static ip linux ubuntu

  4. How to Set a Static IP Address in Ubuntu

    how to set static ip linux ubuntu

  5. Set a Static IP on Ubuntu

    how to set static ip linux ubuntu

  6. How To Configure Static IP Address On Ubuntu 20.04 Server

    how to set static ip linux ubuntu

VIDEO

  1. How to assign Static IP Address in Ubuntu 17.04

  2. How to Set Static IP in Ubuntu Server 20.04 & Create New User |Hindi|

  3. Статический IP адрес на Ubuntu

  4. Setting a Netplan in Ubuntu Server 22.04

  5. 08.Static IP Linux server

  6. How To Setup Static IP Address On Ubuntu 23.04

COMMENTS

  1. How to Set a Static IP Address in Ubuntu

    Set a Static IP in Ubuntu with the GUI. 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.

  2. How to Configure Static IP Address on Ubuntu 20.04

    Depending on the interface you want to modify, click either on the Network or Wi-Fi tab. To open the interface settings, click on the cog icon next to the interface name. In "IPV4" Method" tab, select "Manual" and enter your static IP address, Netmask and Gateway. Once done, click on the "Apply" button.

  3. Set static IP in Ubuntu using Command Line

    gateway4: 192.168.122.1. nameservers: addresses: [1.1.1.1, 1.0.0.1] version: 2. To apply the settings, run the following command: sudo netplan apply. 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. $ hostname -I.

  4. Setting a Static IP in Ubuntu

    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. Manually setting a static IP using Ubuntu Desktop. Verify by using the command ip a.

  5. How to Assign Static IP Address on Ubuntu Linux

    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. Next, you should go to the IPv4 tab.

  6. Manual Network Configuration in Linux and How to Set a Static IP

    a specific IP address; full control over the address assignment; Since the Dynamic Host Configuration Protocol (DHCP) can take the Media Access Control (MAC) address into account when assigning the network-layer address, we might still automatically receive the same IP on each connection with that protocol.

  7. Ubuntu Static IP configuration

    Open network settings Ubuntu Desktop. Click on the settings icon to start IP address configuration. Start network configuration to set static IP address. Select IPv4 tab. Static IPv4 IP address Ubuntu Desktop. Select manual and enter your desired IP address, netmask, gateway and DNS settings. Once ready click Apply button.

  8. How To Set A Static IP Address On Ubuntu

    Click on the Settings button and switch to the IPv4 tab. Select Manual and provide the IP Address, Netmask, and Gateway. You can optionally fill in the DNS server as well if you'd like. Then, click on Apply and restart the network to apply the changes. You can click on the Settings cog again to verify the change.

  9. How to Configure Static IP Address on Ubuntu 18.04

    In the Activities screen, search for "network" and click on the Network icon. This will open the GNOME Network configuration settings. Click on the cog icon. In "IPV4" Method" section, select "Manual" and enter your static IP address, Netmask and Gateway. Once done, click on the "Apply" button.

  10. How to set Static IP on Ubuntu

    The process of setting the static IP on the Ubuntu server with a graphical user interface becomes easier. Open the settings, then go to the Network or Wi-Fi settings. Next, click on the gear icon. A window will appear, open the IPv4 tab, check Manual, and set the static IP address information in the following fields.

  11. How to set a static internal IP in Ubuntu

    These are the IP address you want to change your machine to and the current default gateway, respectively. sudo nmcli con add con-name "static" ifname enp0s3 type ethernet ip4 10..2.13/24 gw4 10 ...

  12. networking

    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: sudo ip addr flush enp0s25. sudo systemctl restart networking.service. Then verify it is correct: ip add.

  13. How to Set Static IP Address and Configure Network in Linux

    Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to setup a static IP address (at least in most cases). Read Also: How to Set or Change System Hostname in Linux</p. This article is meant to show you how to configure static IP address on most frequently used Linux distributions.

  14. How to Set Static IP Address on Ubuntu Linux

    Configure IP Address in Ubuntu. Now, open the default Netplan configuration file for editing with the command below. $ sudo nano 01-network-manager-all.yaml. You would need to make changes to the file so that it looks similar to what you see in the image below. In my case, the new additions are marked with a red border.

  15. How to Configure Static IP Address on Ubuntu

    To configure a static IP address on your Ubuntu server you need to modify a relevant netplan network configuration file within the /etc/netplan/ directory. To set your network interface enp0s3 to static IP address 192.168.1.233 with gateway 192.168.1.1 and DNS server as 8.8.8.8 and 8.8.4.4 replace the above configuration with the one below.

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

    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.

  17. How to configure static IP address on Ubuntu 20.04 ...

    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.88.8.4.4192.168.1.1. ... Related Linux Tutorials: Set static IP on Raspberry Pi; Ubuntu 22.04 Network Setup; Set up Raspberry Pi as Router;

  18. How to Configure Static IP Address on Ubuntu 20.04

    Firstly, to set up a static IP address we need to identify the name of the interface that we want to configure. For this we will use " ip_link ". $ ip link. This will print out all the available network interfaces such as " enp0s3 " that we'll configure. Netplan is used as a default network management tool by Ubuntu and its files are ...

  19. Ubuntu Linux Static IP Configuration

    How do I verify a static IP configuration on Ubuntu? To see new IP address, enter: $ sudo ip a show To see new routing table, enter: $ sudo ip r Try to ping a network IP or domain name: $ ping 8.8.8.8 $ ping cyberciti.biz Verify dns too: $ host cyberciti.biz $ dig google.com. A note about enabling an IPv6 static address on Ubuntu

  20. How to Set Static IP Address on Ubuntu Server 22.04

    Setting up Static IP address on Ubuntu Server 22.04. Login to your Ubuntu server 22.04, look for the netplan configuration file. It is located under /etc/netplan directory. Run below cat command to view the contents of '00-installer-config.yaml'. Note: Name of configuration file may differ as your per setup.

  21. Configure static external IP addresses

    You can assign static external IP addresses to your virtual machine (VM) instances. You can also change, list, and release static IP addresses for your VMs. To reserve a static external IP address, see Reserve a static external IP address. External IP addresses can be static or ephemeral. If a VM requires a fixed external IP address that does ...

  22. How to Install and Use Telnet on Ubuntu 22.04 LTS

    Step 1: First open the terminal in your Ubuntu machine. Unmute. Step 2: Run the below command to check Telnet's availability in the Ubuntu repository. It shows version 0.17. apt show telnetd. Check Telnet's Availability. Step 3: Now install the Telnet using apt manager. Execute the below command in the terminal.

  23. How to Set Static IP Address on Raspberry Pi

    Step 1: Get the IP address of Pi. If you want to use the current IP address as the static IP, This is very simple. In the terminal, type the following command: hostname -I. You may also use this command: ip a. Both will give you the current IP address of the Raspberry Pi.

  24. How to install and use OpenVPN

    The OpenVPN server always uses the first usable IP address in the client network and only that IP is pingable. E.g. if you configured a /24 for the client network mask, the .1 address will be used. The P-t-P address you see in the ip addr output above is usually not answering ping requests. Check out your routes:

  25. Set up Raspberry Pi as Router

    Configuring static IP address for the wlan0 interface Save your changes and exit the DHCP daemon configuration file when done. Next, we will need to change the net.ipv4.ip_forward kernel parameter for the Raspberry Pi.

  26. How to configure static IP address on Ubuntu 22.04 Jammy Jellyfish

    The purpose of this tutorial is to configure a static IP address on Ubuntu 22.04 Jammy Jellyfish Linux. When it comes to IP addresses on Ubuntu 22.04, you have two main options for how you configure your network interfaces.You can either obtain an IP address automatically with DHCP, or configure the system to use a static IP address, which never changes.