Set static IP in Ubuntu using Terminal

Everything you need to know about setting static IP on an Ubuntu machine using the command line.

Dec 5, 2022 — Pratham Patel

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.

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

set static ip ubuntu command line 18 04

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.

set static ip ubuntu command line 18 04

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.

Pratham Patel

Fell in love with Ubuntu the first time I tried it. Been distro-hopping since 2016.

On this page

It's FOSS

How to Assign Static IP Address on Ubuntu Linux

Dimitrios

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

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

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

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

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

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

Method 1: Assign static IP in Ubuntu using command line

Static IP set up Ubuntu

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

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

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

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

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

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

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

Step 2: Locate Netplan configuration

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

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

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

You need to edit this file for using static IP.

Step 3: Edit Netplan configuration for assigning static IP

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

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

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

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

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

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

Save the file and apply the changes with this command:

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

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

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

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

Method 2: Switch to static IP address in Ubuntu graphically

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

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

Assign Static IP address in Ubuntu Linux

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

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

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

Assigning static IP in Ubuntu Linux

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

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

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

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

Meet DebianDog - Puppy sized Debian Linux

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

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

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Your link has expired.

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

Success! Your billing info has been updated.

Your billing was not updated.

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.

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

TechRepublic

Account information.

set static ip ubuntu command line 18 04

Share with Your Friends

How to configure a static IP address in Ubuntu Server 18.04

Your email has been sent

Image of Jack Wallen

From the office of, “If it’s not broken don’t fix it” comes this: In Ubuntu Server , there’s a brand new method of setting IP addresses. Gone are the days of manually editing the flat text /etc/network/interfaces file. In its place is netplan. That’s right, Ubuntu fans, the method you’ve known for years is now a thing of the past. Instead of a very simple text file, Ubuntu Server requires editing a .yaml file (complete with proper adherence to correct code indent for each line of the block), in order to configure your IP addressing.

Before you panic, it’s not all that challenging. In fact, it’s really just a matter of understanding the layout of these .yaml files and how networking is now restarted. I’m going to show you just that, such that you can configure a static IP address in Ubuntu Server 18.04 as easily as you could in 16.04.

The new method

Open up a terminal window on your Ubuntu 18.04 server (or log in via secure shell). Change into the /etc/netplan directory with the command cd /etc/netplan . Issue the command ls and you should see a file named 50-cloud-init.yaml . If you don’t also see a file named 01-netcfg.yaml , create it with the command sudo touch 01-netcfg.yaml . Before we edit that file, we need to know the name of our networking interface. Issue the command ip a and you should see your system network interface listed by name ( Figure A ).

set static ip ubuntu command line 18 04

Now we’re going to create a new netplan configuration file. If you don’t see the 01-netcfg.yaml file, create one with the command sudo nano 01-netcfg.yaml . Our file is going to look like that which you see in Figure B .

set static ip ubuntu command line 18 04

What’s crucial about the layout of this file is not using the exact same spacing as my example, but that you’re consistent. If you’re not consistent with your indents, the file will not work. What you see in that sample file is all you need to configure that static IP address. Do notice, you aren’t setting the address is the same fashion as you did with Ubuntu 16.04. With the old method, you set IP address and netmask like so:

address = 192.168.1.206 netmask = 255.255.255.0

With netplan, these are set with a single line:

addresses : [192.168.1.206/24]

Restarting/testing networking

With the new method, you must restart networking using netplan. So once you’ve configured your interface, issue the command:

sudo netplan apply

The above command will restart networking and apply the new configuration. You shouldn’t see any output. If networking fails to function properly, you can issue the command:

sudo netplan --debug apply

The output of the command ( Figure C ) should give you some indication as to what’s going wrong.

set static ip ubuntu command line 18 04

That’s all there is to it

There ya go. That’s all there is to configuring a static IP address in Ubuntu Server 18.04. Remember, you’ll have to do this for each interface you have on your server. Make sure to name the files something like 01-netcfg.yaml and 02-netcfg-yaml. It’s not terribly difficult, once you’re used to not working with that old-school interfaces file.

Subscribe to the Developer Insider Newsletter

From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays

  • How to install Ubuntu Server 18.04
  • How to enable remote desktop connections in Ubuntu 18.04
  • How to enable an automatic purge of temp files in Ubuntu 18.04
  • How to connect Ubuntu 18.04 to your Google account
  • Ubuntu 18.04 LTS: The Linux for AI, clouds, and containers

Image of Jack Wallen

Create a TechRepublic Account

Get the web's best business technology news, tutorials, reviews, trends, and analysis—in your inbox. Let's start with the basics.

* - indicates required fields

Sign in to TechRepublic

Lost your password? Request a new password

Reset Password

Please enter your email adress. You will receive an email message with instructions on how to reset your password.

Check your email for a password reset link. If you didn't receive an email don't forgot to check your spam folder, otherwise contact support .

Welcome. Tell us a little bit about you.

This will help us provide you with customized content.

Want to receive more TechRepublic news?

You're all set.

Thanks for signing up! Keep an eye out for a confirmation email from our team. To ensure any newsletters you subscribed to hit your inbox, make sure to add [email protected] to your contacts list.

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
  • Spreading the gospel of Python
  • OverflowAI and the holy grail of search
  • Featured on Meta
  • Our Partnership with OpenAI
  • What deliverables would you like to see out of a working group?

Hot Network Questions

  • Potential PhD advisor may lack qualifications
  • Negative pressure projectile propellants (Alternatives to gunpowder)
  • Is a creature spell already a permanent?
  • How effective are statues and other monuments in changing people's political beliefs?
  • Is this a school badge?
  • dir command: force output to one filename per line, full path included, but nothing else
  • Arguments for vs against filtering Internet Access to legal Websites on University Campus
  • Creating tangential lines at points along shoreline in QGIS
  • Was the purported 1968 standard for encoding ASCII on punched cards ever used?
  • How does a snake climb the wall?
  • How to track ride data for a shared bicycle?
  • Little Lost Robot gamma ray?
  • How does a guitar string produce sound?
  • How to protect a country with no army, no police, no guards, no military authority?
  • How should one decide the author order
  • About a formula 07.27.03.0002.01 found here https://functions.wolfram.com/PDF/Hypergeometric3F2.pdf
  • `exit` man page
  • Does it matter where a prenuptial agreements is signed?
  • Can there be a perfect linear operator for square matrices?
  • How will hitting the gym trigger the effect of the drug?
  • Can you switch your "Replicate Magic Item" Infusion after a long rest?
  • Isn't it possible to display text over a video?
  • Did ROM chips jump from 8K to 32K?
  • Where is the location of fdupes cache database?

set static ip ubuntu command line 18 04

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

TecAdmin

How to Configure Static IP Address on Ubuntu 24.04

The Ubuntu team has once again kept their promise and released a new long-term support version, Ubuntu 24.04 (Noble Numbat), which comes with many great features. After installing it, setting up the network interface is an important first step for users. Usually, the system automatically gets an IP address from DHCP, but sometimes you might need to set up a static IP address. A static IP address does not change even when the system restarts, which is very helpful for managing networks and running servers.

This guide will show you how to set up a static IP address on Ubuntu 24.04, whether you are using the desktop environment or managing servers using the command line.

Introduction

A static IP address is set up manually on a computer to make sure it stays the same, unlike dynamic IP addresses that a DHCP server assigns and can change. Static IPs are commonly used for servers, network printers, and other devices that need to be consistently reachable over the network.

Requirements

  • A machine running Ubuntu 24.04 (Noble Numbat).
  • Basic familiarity with the system’s terminal and network configuration files.
  • Administrative (sudo) privileges.

Setting Up a Static IP in Ubuntu 24.04 Desktop Environment

Ubuntu 24.04 continues to use GNOME as its default desktop environment, which provides an intuitive interface for managing network settings. Follow the below steps to configure static IP address on your Ubuntu desktop system.

Step 1: Access Network Settings

  • Click on the icons at the top right corner of the screen.

Setting Up IP Address on Ubuntu 24.04

Step 2: Configure IP address

  • In the settings menu, go to the IPv4 tab.
  • Toggle the IPv4 Method to Manual.
  • Enter your desired IP address, netmask (often 255.255.255.0), and gateway.
  • Add DNS servers if necessary.

Setting Up IP Address on Ubuntu 24.04

Step 3: Apply Configuration

Click Apply button to save your settings. This will automatically update your system ip address. Wait for a to apply the changes. Then you can check updated IP address in details tab.

Setting Up a Static IP in Ubuntu 24.04 using Command Line Interface

If you like using the command line or need to set up a server without a graphical interface, the command line method is easy and effective.

Step 1: Open Terminal

You can open the terminal by pressing Ctrl + Alt + T or by looking for ‘Terminal’ in the applications menu.

Step 2: Identify Your Network Interface

Type the command ip link to see all network interfaces.

Find the interface you want to set up, like eth0 for a wired connection or wlan0 for wireless.

Step 3: Edit Netplan Configuration

Ubuntu 24.04 uses Netplan to manage network settings. Find the Netplan configuration files in /etc/netplan/. Open a file with a text editor, for example, type:

Step 4: Configure Static IP

Change the file to add your static IP details. For instance:

Switch eth0 with your network interface and adjust the IP settings as needed.

Step 5: Apply Changes

Save the file and update the changes with sudo netplan apply.

Check the new settings with ip addr show or by pinging another device.

Whether you like a graphical interface or the command line, setting up a static IP address in Ubuntu 24.04 (Noble Numbat) is easy. This setup can make your network more reliable and easier to access. Always test your settings to make sure the network works as you expect.

Related Posts

How to clone git tags, how to resolve error 1040 (08004): too many connections in mysql.

Ubuntu 24.10 (Oracular Oriole)

Ubuntu 24.10 Codename and What It Means

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

Type above and press Enter to search. Press Esc to cancel.

Orcacore logo

Easily Set a Static IP Address on Ubuntu 24.04 Via GUI

  • Olivia Viera
  • May 17, 2024

Share your love

Easily Set a Static IP Address on Ubuntu 24.04 Via GUI

This guide will teach you to Set a Static IP Address on Ubuntu 24.04 Via GUI . As may know, there are two main types of IP Addresses: Dynamic and Static. The Dynamic IP is automatically assigned to a device by a DHCP server. However, if you don’t have a DHCP server, you can manually configure an IP address which is a Static IP address.

In this guide, you will learn how to configure a static IP on your Ubuntu 24.04 using the graphical user interface (GUI). Let’s the process of configuring a static IP address on your Ubuntu system.

Steps To Set a Static IP Address on Ubuntu 24.04 Via GUI

How to set a static ip in ubuntu gnome.

Before you start to configure static IP address, you must log in to your server as a root or non-root user with sudo privileges. Then, follow the steps below to manually configure ip address on Ubuntu 2404.

Manually Set an IP Address on Ubuntu 24.04

From your Ubuntu desktop, click on the Power icon in the left corner of the top screen. Then, click on wired .

Open Wired settings on Ubuntu 24.04

From the Wired Connections , you must click on Wired Settings on Ubuntu 22.04. Next, click on the Settings icon next to the wired option.

Ubuntu 24.04 Network - Wired settings

A new window will open for you. From there, navigate to the IPv4 tab and select the Manual option. Now you must enter your address, netmask, gateway , and DNS details. Finally, click on Apply .

Set a Static IP Address on Ubuntu 24.04 via GUI

That’s it, you are done. You should see that your wire is connected successfully. As you can see, you can manually set an ip address on Ubuntu 2204 in just a few simple steps.

The stability of Static IP is essential for services that require consistent access, such as web servers, email servers, and network printers. With a static IP, you can be sure about reliable access to these services without worrying about IP address changes that interrupt your communications.

Configuring a static IP address using the graphical user interface (GUI) is a straightforward process on Ubuntu 24.04. By setting a static IP, you can increase the reliability and accessibility of network services, such as web servers, printers, and other essential things.

By following these guide steps, you can ensure that your Ubuntu 24.04 system has a stable and consistent IP address. It provides reliable network communication and service delivery. Whether you are an advanced user or a beginner user, understanding how to set a static IP using the GUI method is a useful skill that can increase your network management capabilities.

Note : If you are looking for a command line option instead of a GUI, you can easily use the nmcli and Netplan command line tools. For this purpose, you can check this guide and see the guide steps for configuring your IP from the command line.

In the Ubuntu Gnome desktop, you can simply use the above steps to set static IP. You just need to open network settings, navigate to the IPv4 tab, and enter the details including Address, Netmask, Gateway, and DNS. You can also add multiple DNS servers by separating them with commas.

Then, click the Apply or Save button to apply the new settings. You may need to restart the network interface or your computer for the changes to take effect.

By doing these steps, you can easily set your static IP. Hope you enjoy using it.

Also, you may like to read the following articles:

4 Linux Commands to Get Public IP Address

Install ionCube Loader on Ubuntu 22.04

How To Install and Configure XAMPP on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Related Posts

A Comprehensive Guide for Ubuntu 24.04 LTS Desktop Installation

Ubuntu 24.04 LTS Desktop Installation Made Easy

  • May 16, 2024

Upgrading from Ubuntu 22.04 to Ubuntu 24.04 - Level up your Ubuntu

Upgrading from Ubuntu 22.04 to Ubuntu 24.04 – Full & Easy Steps

  • May 14, 2024

Best practices to install Apache Guacamole on Ubuntu 22.04 - orcacore.com

Best practices to install Apache Guacamole on Ubuntu 22.04

  • April 6, 2024

Stay informed and not overwhelmed, subscribe now!

Tecmint: Linux Howtos, Tutorials & Guides

How to Upgrade Ubuntu 22.04 LTS to 24.04 LTS

The stable version of Ubuntu 24.04 LTS (code-named Noble Numbat ) is released on April 25th 2024, if you are curious to know what is in it, you can now upgrade to the version of it from lower version for testing purposes.

Just like every new Ubuntu release, Ubuntu 24.04 ships with new features including the latest and greatest software such as the Linux kernel, GNOME 46 and refreshed state-of-the-art toolchain. You can find more information about the new changes from the release notes .

Importantly, Ubuntu 24.04 LTS will be supported for 5 years until April 2029 , for Ubuntu Desktop, Ubuntu Server, and Ubuntu Core.

This guide will walk you through the process of upgrading your current Ubuntu 22.04 system to the latest Ubuntu 24.04 LTS .

Step 1: Back Up Ubuntu Data

To back up your data on Ubuntu 22.04 to an external drive before upgrading to Ubuntu 24.04 , you can follow these commands:

To get started, plug in your external storage device like a USB drive or an external hard drive, and make sure your computer can see it.

Open the terminal and type “ lsblk ” to find your external drive in the list, which might look something like “/ dev/sdb1 “.

After identifying your external drive, you can find its mount point by running the df command and looking for an entry corresponding to your external drive’s identifier (e.g., /dev/sdb1 ) in the output.

The mount point will be listed in the second column of that entry, which typically looks like “ /mnt/external ” or “ /media/username/external “. This mount point is where your external drive is currently connected and accessible in your system.

Using the rsync command to back up your Home directory to an external drive:

Using the tar command create a compressed archive of your Home directory and save it to the external drive:

Replace /path/to/external/drive with the path to your external drive and /home/username with the path to your Home directory.

You can also use graphical backup tools like Deja Dup or Timeshift to back up your data to an external drive.

Step 2: Preparing Ubuntu System for Upgrade

Before you start upgrading your system, it’s important to make sure there are any updates needed. After that, update and upgrade your current packages. Once the upgrade is finished, restart your system so all the changes can work properly.

Upgrade Ubuntu Packages

Step 3: Upgrade Ubuntu 22.04 LTS to 24.04 LTS

If upgrading via SSH , make sure to open port TCP port 1022 on ufw firewall for a stable connection during the upgrade process.

If you have physical access to your Ubuntu desktop and are upgrading locally, you don’t need to open any port. Simply install the Update Manager Core tool, which will ensure that all necessary tools for the upgrade are installed.

Install Update Manager Core

Once the Update Manager Core is installed, initiate the upgrade process by entering the following command.

no development version of an LTS available

If the system doesn’t find a new release, and you get the following error?

The error message you received indicates that you’re trying to upgrade to a non-existent development version of an LTS release.

Here’s what’s happening and how to address it:

  • Ubuntu releases come in two main types: LTS (Long Term Support) and non-LTS (development releases).
  • You can’t directly upgrade from an LTS version (like 22.04 LTS ) to a development version (which isn’t even available).
  • The system is correctly informing you that there’s no development version of the current LTS ( 24.04 LTS ) yet.

Since you want to upgrade from Ubuntu 22.04 LTS to the latest LTS release ( 24.04 LTS ), here’s what you need to do:

Open the /etc/update-manager/release-upgrades upgrade configuration file and change the value of “ Prompt ” to “ normal “, which ensures you’ll be notified about the upgrade and have the option to choose whether to proceed.

Ubuntu Upgrade Configuration File

Now, use the following command to initiate the upgrade process again:

This will take you to the Ubuntu 23.10 release, right now, you can’t upgrade directly from Ubuntu 22.04 LTS to 24.04 LTS using the do-release-upgrade command because the official upgrade path isn’t available yet.

To upgrade to Ubuntu 24.04 , you have to update to Ubuntu 23.10 first. Then, from there, you can upgrade to Ubuntu 24.04 .

Run Release Upgrade Again

Now follow on-screen instructions to upgrade to Ubuntu 23.10 release and reboot the system.

Again open the /etc/update-manager/release-upgrades upgrade configuration file and change the value of “ Prompt ” to “ lts “.

Ubuntu Upgrade Configuration File

Lastly, enter the command below and then continue following the rest of the guide to upgrade from version 23.10 to 24.04 LTS .

Upgrading to Ubuntu 24.04

Step 4: Remove Obsolete Packages

To remove obsolete packages after upgrading Ubuntu to ensure system cleanliness, you can use the following command:

Running the above command will remove any obsolete packages that are no longer needed on your system after the upgrade, which helps in freeing up disk space and keeping your system tidy and efficient.

Step 5: Enable Third-Party Repositories on Ubuntu

To enable third-party repositories, you need to to find third-party repositories under /etc/apt/sources.list.d/ directory that may have been disabled during the upgrade process.

Next, uncomment and remove the # sign at the beginning of each line for each repository in the respective files.

Confirm that the third-party repositories are enabled by running the following command to ensure the necessary repositories are active.

By following these steps, you can successfully enable third-party repositories on Ubuntu 24.04 after upgrading from Ubuntu 22.04 .

There you go! We hope you have successfully upgraded your Ubuntu version from 22.04 to 24.04 . If you encountered any issues along the way or have thoughts to share, use the feedback form below to reach us.

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

Tasksel Install Group Software in Ubuntu and Debian

Tasksel – Quickly Install Software Groups in Debian and Ubuntu

Install KDE Plasma in Ubuntu

How to Install KDE Plasma in Ubuntu, Debian and Mint

Install ImageMagick 7 on Debian and Ubuntu

How to Install ImageMagick 7 on Debian and Ubuntu

Install Apt-Cacher-NG in Ubuntu

Ubuntu 22.04: Set Up a Local Package Cache with Apt-Cacher-NG

Install Linux on USB Drive

How to Install Linux OS on USB Drive and Run it On Any PC

Setup Mail Server in Ubuntu

How to Install Postfix with Roundcube Webmail on Ubuntu and Debian

Hi, I’m facing an error in ubuntu 18.04.

Could not calculate the upgrade

An unresolvable problem occurred while calculating the upgrade.

This was likely caused by: * Unofficial software packages not provided by Ubuntu Please use the tool ‘ppa-purge’ from the ppa-purge package to remove the software from a Launchpad PPA and try the upgrade again.

If none of this applies, then please report this bug using the command ‘ubuntu-bug ubuntu-release-upgrader-core’ in a terminal. If you want to investigate this yourself the log files in ‘/var/log/dist-upgrade’ will contain details about the upgrade. Specifically, look at ‘main.log’ and ‘apt.log’.

Restoring the original system state

Aborting Reading package lists… Done Building dependency tree Reading state information… Done

I got this exact same problem too. I found a workaround for this. We need to use an app called Synaptic to remove all packages that are considered unofficial.

  • Install synaptic with “ sudo apt-get install synaptic “.
  • Open synaptic app and find the list of obsolete packages by clicking on the “ Status ” button and selecting “ Installed (local or obsolete) ”.
  • Select all of the obsolete packages and mark them for removal, then click on the Apply button. ( Note : Your important apps may listed as obsolete packages, so make sure to back up the app data if possible. You may also need to keep the list by using a screenshot, so you can install them back later after upgrade).
  • Do the upgrade process again by pressing Alt+F2 type “ update-manager -c -d ” then click enter .

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.

kifarunix.com

Install and Setup Kubernetes Cluster on Ubuntu 24.04

Setup Kubernetes Cluster on Ubuntu

This tutorial provides a step by step guide on how to install and setup Kubernetes Cluster on Ubuntu 24.04. Kubernetes, according to kubernetes.io , is an open-source production-grade container orchestration platform. It facilitates automated deployment, scaling and management of containerized applications.

Table of Contents

Kubernetes cluster architecture.

In this tutorial, we are going install and setup a four node (one control plane and three worker nodes) Kubernetes cluster.

A Kubernetes cluster is composed a Master node which hosts the control plane and a Worker node which hosts Pods.

Check our guide on a high-level overview of Kubernetes cluster to understand more on this.

Kubernetes Architecture: A High-level Overview of Kubernetes Cluster Components

Below are our node details.

Run System Update on Cluster Nodes

To begin with, update system package cache on all the nodes;

Disable Swap on Cluster Nodes

Running Kubernetes requires that you disable swap.

Check if swap is enabled.

If there is no output, then swap is not enabled. If it is enabled as shown in the output above, run the command below to disable it.

To permanently disable swap, comment out or remove the swap line on /etc/fstab file.

or Simply remove it;

Enable Kernel IP forwarding on Cluster Nodes

In order to permit the communication between Pods across different networks, the system should able to route traffic between them. This can be achieved by enabling IP forwarding. Without IP forwarding, containers won’t be able to communicate with resources outside of their network namespace, which would limit their functionality and utility.

To enable IP forwarding, set the value of net.ipv4.ip_forward to 1 .

Apply the changes;

Load Some Required Kernel Modules on Cluster Nodes

overlay module provides support for the overlay filesystem. OverlayFS is type of union filesystem used by container runtimes to layer the container’s root filesystem over the host filesystem.

br_netfilter module provides support for packet filtering in Linux bridge networks based on various criteria, such as source and destination IP address, port numbers, and protocol type.

Check if these modules are enabled/loaded;

If not loaded, just load them as follows;

Similarly, enable Linux kernel’s bridge netfilter to pass bridge traffic to iptables for filtering. This means that the packets that are bridged between network interfaces can be filtered using iptables/ip6tables, just as if they were routed packets.

Install Container Runtime on Ubuntu 24.04

Kubernetes uses container runtime to run containers in Pods. It supports multiple container runtimes including Docker Engine, containerd, CRI-O, Mirantis Container Runtime.

Install Containerd Runtime on all Cluster Nodes

In this demo, we will use containerd runtime. Therefore, on all nodes, master and workers, you need to install containerd runtime.

You can install containerd using official binaries or from the Docker Engine APT repos. We will use the later in this guide, thus;

Install containerd;

The kubelet automatically detects the container runtime present on the node and uses it to run the containers.

Configure Cgroup Driver for ContainerD

Cgroup (control groups) is a Linux kernel feature that allows for the isolation, prioritization, and monitoring of system resources like CPU, memory, and disk I/O for a group of processes. Kubernetes (kubelet and container runtime such as containerd ) uses cgroup drivers to interface with control groups in order to manage and set limit for the resources allocated to the containers.

Kubernetes support three types of Cgroup drivers;

  • cgroupfs (control groups filesystem): This is the default cgroup driver used by Kubernetes kubelet to manage resources for containers.
  • systemd : This is the default initialization system and service manager in some Linux systems. it offers functions such as starting of daemons, keeping track of processes using Linux cgroups etc.

For systems that use Systemd as their default Init system, it is recommended to use systemd cgroup driver for Kubernetes instead of cgroupfs.

The default configuration file for containerd is /etc/containerd/config.toml . When containerd is installed from Docker APT repos, this file is created with little configs. If installed from the official binaries, the containerd confguration file is not created.

Either way, update the containerd configuration file by executing the command below;

Sample configuration.

Once you generate the default config, you need to enable systemd cgroup for the containerd low-level container runtime, runc by changing the value of SystemdCgroup from false to true .

Also, as of this writing, it is recommended to use “ registry.k8s.io/pause:3.9 ” as the CRI sandbox image. pause container image is a minimalistic container image that enables containerd to provide network isolation for pods in Kubernetes. Containerd uses pause:3.8 .

To change this to pause:3.8;

Start and enable containerd to run on system boot;

Confirm the status;

Install Kubernetes on Ubuntu 24.04

There are a number of node components required to provide Kubernetes runtime environment that needs to be installed on each node. These include:

  • kubelet : runs as an agent on each worker node and ensures that containers are running in a Pod.
  • kubeadm : Bootstraps Kubernetes cluster
  • kubectl : Used to run commands against Kubernetes clusters. 

These components are not available on the default Ubuntu repos. Thus, you need to install Kubernetes repos to install them.

Install Kubernetes Repository GPG Signing Key

Run the command below to install Kubernetes repo GPG key.

Replace the value of the VER variable below with the release number of Kubernetes you need to run! In this guide, I will be using the current latest minor release version, v1.30.

Install Kubernetes Repository on Ubuntu 24.04

Next install the Kubernetes repository of the version matching the GPG key installed above;

Install Kubernetes components on all the nodes

Initialize kubernetes cluster on control plane using kubeadm.

Once the above steps are completed, initialize the Kubernetes cluster on the master node. The Kubernetes master is responsible for maintaining the desired state for your cluster.

We will be using kubeadm tool to deploy our K8S cluster.

The cluster can be initiated using the kubeadm tool by passing the init command argument;

Some of the common arguments/options include;

  • –apiserver-advertise-address : Defines the IP address the API Server will listen on. If not set the default network interface will be used. An example usage is --apiserver-advertise-address=192.168.122.60 .
  • –pod-network-cidr : Specify range of IP addresses for the pod network. If set, the control plane will automatically allocate CIDRs for every node. You use this to define your preferred network range if there is a chance for collision between your network plugin’s preferred Pod network addon and some of your host networks to happen e.g --pod-network-cidr=10.100.0.0/16 .
  • –control-plane-endpoint : Specifies the hostname and port that the API server will listen on. This is recommended over the use of --apiserver-advertise-address because it enables you to define a shared endpoint such as load balance DNS name or an IP address that can be used when you upgrade single master node to highly available node. For example, --control-plane-endpoint=cluster.kifarunix-demo.com:6443 .

Since we are just running a single master node Kubernetes cluster in this guide (for demo purposes), with no plans to upgrade to highly available cluster, then we will specify just the IP address of the control plane while bootstrapping our cluster.

Thus, run the command below on the master node to bootstrap the Kubernetes control-plane node.

The command will start by pre-pulling ( kubeadm config images pull ) the required container images for a Kubernetes cluster before initializing the cluster.

Once the initialization is done, you should be able to see an output similar to the one below;

As suggested on the output above, you need to run the commands provided on the master node to start using your cluster.

Be sure to run the commands as regular user ( recommended ), with sudo rights.

Thus, if you are root, then switch to regular user with sudo rights (kifarunix is our regular, it could be a different user for you)

Next, create a Kubernetes cluster directory.

Copy Kubernetes admin configuration file to the cluster directory created above.

Set the proper ownership for the cluster configuration file.

Verify the status of the Kubernetes cluster;

As you can see, the cluster is not ready yet.

You can also get the address of the control plane and cluster services;

Install Pod Network Addon on Master Node

A Pod is a group of one or more related containers in a Kubernetes cluster. They share the same lifecycle, storage/network. For Pods to communicate with one another, you must deploy a Container Network Interface  (CNI) based Pod network add-on.

There are multiple Pod network addons that you can choose from. Refer to Addons page for more information.

To deploy a CNI Pod network, run the command below on the master node;

Where [podnetwork].yaml is the path to your preferred CNI YAML file. In this demo, we will use Calico network plugin .

Install Calico Pod network addon Operator by running the command below. Execute the command as the user with which you created the Kubernetes cluster .

Next, download the custom resources necessary to configure Calico. The default network for Calico plugin is 192.168.0.0/16. If you used custom  pod CIDR  as defined above ( –pod-network-cidr=10.100.0.0/16 ), download the custom resource file and modify the network to match your custom one.

Get the current release version fro releases page and replace the value of CNI_VER below.

The network section of the custom resource file will now look like below by default;

Update the network subnet to match your subnet.

Apply the changes

Sample output;

Get Running Pods in the Kubernetes cluster

Once the command completes, you can list the Pods in the namespaces by running the command below;

You can list Pods on specific namespaces;

As can be seen, all Pods on calico-system namespace are running .

Open Kubernetes Cluster Ports on Firewall

If firewall is running on the nodes, then there are some ports that needs to be opened on the firewall;

Control Plane ports;

So the ports that should be open and accessible from outside the node are:

  • 6443 – Kubernetes API Server (secure port)
  • 2379-2380 – etcd server client API
  • 10250 – Kubelet API
  • 10251 – kube-scheduler
  • 10252 – kube-controller-manager

In my setup, I am using UFW. Hence, you only need to open the ports below on Master/Control Plane;

You can restrict access to the API from specific networks/IPS.

Worker Nodes;

On each Woker node, open the Kubelete API port;

You can restrict access to the API from specific networks/IPs.

Add Worker Nodes to Kubernetes Cluster

You can now add Worker nodes to the Kubernetes cluster using the kubeadm join command as follows.

Before that, ensure that container runtime is installed, configured and running. We are using containerd CRI;

Sample output from worker01 node;

Once you have confirmed that, get the cluster join command that was output during cluster boot strapping and execute on each node.

Note that this command is displayed after initializing the control plane above and it should be executed as root user.

If you didn’t save the Kubernetes Cluster joining command, you can at any given time print using the command below on the Master or control plane;

Once the command runs, you will get an output similar to below;

On the Kubernetes control plane (master, as the regular user with which you created the cluster as ), run the command below to verify that the nodes have joined the cluster.

There are different node stati;

  • NotReady : The node has been added to the cluster but is not yet ready to accept workloads.
  • SchedulingDisabled : The node is not able to receive new workloads because it is marked as unschedulable.
  • Ready : The node is ready to accept workloads.
  • OutOfDisk : Indicates that the node is running out of disk space.
  • MemoryPressure : Indicates that the node is running out of memory.
  • PIDPressure : indicates that there are too many processes on the node
  • DiskPressure : Indicates that the node is running out of disk space.
  • NetworkUnavailable : Indicates that the node is not reachable via the network.
  • Unschedulable : Indicates that the node is not schedulable for new workloads.
  • ConditionUnknown : Indicates that the node status is unknown due to an error.

Role of the Worker nodes may show up as <none> . This is okay. No role is assigned to the node by default. It is only until the control plane assign a workload on the node then it shows up the correct role.

You can however update this ROLE using the command;

Get Kubernetes Cluster Information

As you can see, we now have a cluster. Run the command below to get cluster information.

List Kubernetes Cluster API Resources

You can list all Kubernetes cluster resources using the command below;

You are now ready to deploy an application on Kubernetes cluster.

Remove Worker Nodes from Cluster

You can gracefully remove a node from Kubernetes cluster as described in the guide below;

Gracefully Remove Worker Node from Kubernetes Cluster

Install Kubernetes Dashboard

You can manage your cluster from the dashboard using Kubernetes. See the guide below;

How to Install Kubernetes Dashboard

Further Reading

Getting Started with Kubernetes

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

set static ip ubuntu command line 18 04

Related Posts

Tips for recruiting top it talent in a competitive job market, upgrade a single package on ubuntu, how to configure snmp version 3 on debian 9, install mariadb 11 on ubuntu 22.04/ubuntu 20.04, easily install and setup powerdns on debian 11/debian 10, install and setup dvwa on debian 10, leave a comment cancel reply.

© 2024 kifarunix.com

IMAGES

  1. How to Configure Network Static IP Address in Ubuntu 18.04

    set static ip ubuntu command line 18 04

  2. Assign Static Ip Ubuntu How To Configure On 18 04 Network Address In

    set static ip ubuntu command line 18 04

  3. How to Configure Network Static IP Address in Ubuntu 18.04

    set static ip ubuntu command line 18 04

  4. How to Configure Network Static IP Address in Ubuntu 18.04

    set static ip ubuntu command line 18 04

  5. Cómo configurar la dirección IP estática en Ubuntu 18.04

    set static ip ubuntu command line 18 04

  6. Configure static IP address on Ubuntu 20.04 LTS, Ubuntu 18.04 LTS

    set static ip ubuntu command line 18 04

VIDEO

  1. Howto Setting IP in UBUNTU 18

  2. แก้ Static IP ubuntu server

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

  4. How to assign Static IP Address in Ubuntu 17.04

  5. How To Setup Static IP Address On Ubuntu 23.04

  6. Set static IP by user for Windows VPN

COMMENTS

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

  2. Set static IP in Ubuntu using Command Line

    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 192.168 .122.128. Perfect! The IP address has now changed successfully.

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

  4. Setting a Static IP Address in Ubuntu 18.04

    To set a static IP address on Ubuntu server 18.04, we will need this network interface name. Using Netplan to Define a Static IP Address. Ubuntu Server 18.04 makes use of a network management tool called Netplan. We will need to modify settings for Netplan so that it attempts to utilize the IP we set when it connects to the router. 1.

  5. How to Configure Network Static IP Address in Ubuntu 18.04

    Netplan is a new command-line network configuration utility introduced in Ubuntu 17.10 to manage and configure network settings easily in Ubuntu systems. ... Set Static IP Address in Ubuntu 18.04. In this example, we will configure a static IP for the enp0s8 ethernet network interface. Open the netplan configuration file using your text editor ...

  6. Netplan static IP on Ubuntu configuration

    Select IPv4 from the top menu. Select IPv4 to start configuring a new IP address. Choose Manual for the IPv4 settings, enter your desired configuration and hit Apply . Set your desired static IP address. Restart your network by ON/OFF switch. Restart to apply new network settings.

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

  8. Linux Basics

    Ubuntu 12.04 - 17.04 (incl. Ubuntu 16.04 LTS) Step 1: Configure the network interface. Step 2: Configure the DNS servers. Step 3: Restart networking. Configure the Hostname. This tutorial explains how to set up a static IP address on an Ubuntu system from the command line. It covers network configuration for all current versions of Ubuntu and ...

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

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

  11. How to configure a static IP address in Ubuntu Server 18.04

    The new method. Open up a terminal window on your Ubuntu 18.04 server (or log in via secure shell). Change into the /etc/netplan directory with the command cd /etc/netplan. Issue the command ls ...

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

    64. 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. Configuring networks

    To configure a default gateway, you can use the ip command in the following manner. Modify the default gateway address to match your network requirements. sudo ip route add default via 10.102.66.1. You can also use the ip command to verify your default gateway configuration, as follows: ip route show.

  14. How To Configure IP Address In Ubuntu 18.04 LTS

    The method of configuring IP address on Ubuntu 18.04 LTS is significantly different than the older methods. Unlike the previous versions, the Ubuntu 18.04 uses Netplan utility. It is a new command line network configuration utility, to configure IP address. Netplan has been introduced by Ubuntu developers in Ubuntu 17.10.

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

    20.7K. Setting up a static IP address in Ubuntu Linux is a common task for system administrators and advanced users. This guide will explore various ways to configure a static IP address in Ubuntu 22.04 LTS operating system.. Assigning a static IP in Ubuntu and its derivatives can be done using both graphical and command-line tools such as netplan, nmcli, and nmtui etc.

  16. Setting a Static IP Address in Ubuntu 24.04 via the Command Line

    Setting a Static IP Address in Ubuntu 24.04 via the Command Line Configuring a Static IP Address. Before diving into the configuration steps, ensure you have sudo or root access to the Ubuntu system. This access is necessary for editing network configuration files and applying changes. Identify Your Network Interface: To set a static IP address ...

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

  18. How To Set Up and Use LXD on Ubuntu 18.04

    To do so, first use the lxc launch command to create and start an Ubuntu 18.04 container named webserver. Create the webserver container. The 18.04 in ubuntu:18.04 is a shortcut for Ubuntu 18.04. ubuntu: is the identifier for the preconfigured repository of LXD images. You could also use ubuntu:bionic for the image name:

  19. How to Configure Static IP Address on Ubuntu 24.04

    Setting Up a Static IP in Ubuntu 24.04 using Command Line Interface. If you like using the command line or need to set up a server without a graphical interface, the command line method is easy and effective. Step 1: Open Terminal. You can open the terminal by pressing Ctrl + Alt + T or by looking for 'Terminal' in the applications menu.

  20. How to configure static IP address on Ubuntu 20.04 Focal Fossa Desktop

    How to configure static IP address on Ubuntu 20.04 step by step instructions Configure Static IP address on Desktop Click on the top right network icon and select settings corresponding to the network interface you wish to assign with the static IP address.

  21. Easily Set a Static IP Address on Ubuntu 24.04 Via GUI

    Steps To Set a Static IP Address on Ubuntu 24.04 Via GUI. Before you start to configure static IP address, you must log in to your server as a root or non-root user with sudo privileges. Then, follow the steps below to manually configure ip address on Ubuntu 2404. Manually Set an IP Address on Ubuntu 24.04

  22. How to Upgrade Ubuntu 22.04 LTS to 24.04 LTS

    The stable version of Ubuntu 24.04 LTS (code-named Noble Numbat) is released on April 25th 2024, if you are curious to know what is in it, you can now upgrade to the version of it from lower version for testing purposes.. Just like every new Ubuntu release, Ubuntu 24.04 ships with new features including the latest and greatest software such as the Linux kernel, GNOME 46 and refreshed state-of ...

  23. Install and Setup Kubernetes Cluster on Ubuntu 24.04

    To enable IP forwarding, set the value of net.ipv4.ip_forward to 1. echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf. Apply the changes; sudo sysctl -p Load Some Required Kernel Modules on Cluster Nodes. overlay module provides support for the overlay filesystem. OverlayFS is type of union filesystem used by container runtimes to ...

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

    Check your new static IP address configuration by clicking on the cog wheel. Verify your new static IP address configuration; Configure Static IP address on Server. In this example we will set a static IP address on the Ubuntu 22.04 server to 192.168.1.202/24 with default gateway to 192.168.1.1 and DNS servers 8.8.8.8, 8.8.4.4, and 192.168.1.1.