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

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

assign static ip in ubuntu server

Step 2: See current IP address

Now that you know which interface needs to be addressed, let us edit a file .

Before I change my IP address/set a static one, let us first see what my current IP address is .

Nice! But let's change it to '192.168.122.128' for demonstration purposes.

Step 3: See the gateway

A gateway is a device that connects different networks (basically what your all-in-one router is). To know the address of your gateway, run the following command:

The gateway address will be on the line that begins with "default via".

Below is the output of running the ip command on my computer:

On the line that starts with "default via", I can see that my gateway address '192.168.122.1'

Make a note of your gateway address.

Step 4: Set static IP address

Now that you have detail like interface name and gateway address, it is time to edit a config file.

Step 4-A: Disable cloud-init if present

The easiest way to know if cloud-init is present or not is to check if there is a package with that name.

Run the following command to check:

If you get an outupt, you have 'cloud-init' installed.

Now, to disable could-init, create a new file inside the /etc/cloud/cloud.cfg.d directory. The name does not matter, so I will call it '99-disable-cloud-init.cfg'.

Add the following line to it:

Please reboot your Ubuntu system now so that cloud-init does not interfere when we set our static IP address in the next step. :)

Back to Step 4

Once the 'cloud-init' related configuration is complete, we must now edit the netplan configuration to add our static IP address.

Go to the /etc/netplan directory. It is better if there is one file (easier to know which one to edit), but in some cases, there might also be more than one file with the extension '.yml' or '.yaml'.

When in doubt, grep for the name of your network interface. Use the following command if you are not comfortable with grep:

Since the name of network interface for my ethernet is 'enp1s0', I will run the following command:

running this command shows that the file I am looking for is '00-installer-config.yaml'. So let us take a look at it.

You might have noticed a line that says 'ethernet' and our network interface name under that. Under this is where we configure our 'enp1s0' network interface.

Since we do not want DHCP assigned IP address, let us change that field from true to no .

Add a field called addresses . Write the IP address you wish to assign your computer along with the network prefix. So I will write 192.168.122.128/24 in the addresses field.

Finally, we also need to specify DNS nameservers. For that, create a new field called nameservers and under that, create a field called addresses which contains the IP address for your DNS servers . I used Cloudflare's DNS servers but you can use whatever you want.

This is what my '00-installer-config.yaml' file looks like after editing it to my liking.

To apply the settings, run the following command:

This will take only a few seconds, and the IP address will be updated once it is done.

You can check the IP address using the hostname -I command.

Perfect! The IP address has now changed successfully.

assign static ip in ubuntu server

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

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.

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.

RaspberryTips

How to Set Static IP Address on Ubuntu Server (Step-by-step)

Most networks automatically assign IP addresses, which is quite convenient for desktop computers. But for a server, it’s recommended to configure it with a static IP, often outside the DHCP range, so it’s always available at the same address. How do you configure this without a GUI ? Let’s find out.

On Ubuntu Server, the network configuration is managed by the netplan utility, with the configuration file located in /etc/netplan. It’s possible to set a static IP by editing this file.

Before making any changes, make sure you understand your network configuration and find a free IP address for your server (I will explain how to do this). Only then you can edit the netplan configuration file to assign a static IP address to your server.

Prerequisites: Understand the network configuration

I guess if you’re installing a server on your network, you already know your network pretty well. However, I want to make sure what we are doing is clear for everyone, so I’ll take a few minutes to explain what you need before changing anything.

Feel free to skip this section if you already know the exact network configuration you want to apply to your server.

Get your current IP configuration

On Ubuntu Server, you can use the following command to get your current IP address: ip a

assign static ip in ubuntu server

You’ll get a list of all the network interfaces, with their names, IP addresses and subnet mask.

In my example, I have:

  • Interface name : eth0
  • IP address : 192.168.0.33/24 (assigned by the DHCP)

To find the router or default gateway on your network, you can then use: ip r

assign static ip in ubuntu server

I now have a better sense of my network configuration.

assign static ip in ubuntu server

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

(Optional) Find the DHCP range

If you have a DHCP server enabled on the network, it’s a good idea to access the router configuration and check the current DHCP range. If possible, you don’t want to set a static IP inside that range.

All router interfaces are different, so I won’t explain everything in detail here, but you should easily find a section with the start and end IP address for the DHCP range. Try to pick an IP on the same subnet but outside that range for your server.

In my example, the router is 192.168.0.254, the DHCP range is from 192.168.0.10 to 192.168.0.50. I can safely set my server to 192.168.0.150 if it’s not already used by another server.

Note : You can use a network scanner if you don’t have a list of all IP addresses already used on your network (most routers will list them). You can use the ‘nmap’ command on Linux or Advanced IP Scanner from a Windows computer on the same network.

assign static ip in ubuntu server

Join Our Community!

Connect, learn, and grow with other Raspberry Pi enthusiasts. Support RaspberryTips and enjoy an ad-free reading experience. Get exclusive monthly video tutorials and many other benefits.

Set the static IP to your Ubuntu Server

At this point, you must know which IP address you’ll use for your server, the network gateway, and probably the DNS server if one is required (on small networks, it’s often the same as the gateway).

In my case, I’ll use the following configuration:

  • IP address : 192.168.0.150
  • Gateway : 192.168.0.254
  • DNS : 8.8.8.8

Make sure to change these values with yours in the following sections.

Open the network configuration file

As mentioned in the introduction, the network configuration file on a fresh Ubuntu Server installation is now located under /etc/netplan .

I think the file name can be slightly different depending on your setup, so it’s probably best to go inside this folder and check what’s available. You can do it with: cd /etc/netplan ls -l

assign static ip in ubuntu server

In my case, the file name is “50-cloud-init.yaml” because I’m testing this on a virtual machine, but adapt the following commands to yours if it’s different.

You can see the current configuration with: sudo cat 50-cloud-init.yaml

assign static ip in ubuntu server

And it’s probably a good idea to create a backup of this file just in case something goes wrong. sudo cp 50-cloud-init.yaml ~/50-cloud-init.yaml.default

You can now open the file in edit mode with: sudo nano 50-cloud-init.yaml

Set your static IP address

To set the static IP address, we’ll slightly edit this file to add the IP address, gateway and DNS server information.

Once the file opens with Nano, or your favorite text editor, make the changes to make it look more like this:

Warning : this file is in YAML format. It’s essential to keep the file structure and indentation, or it won’t work. Make sure only to use spaces (no TAB).

Save your changes and exit Nano (CTRL+X).

You can test your configuration file without rebooting with: sudo netplan try

If it works, your IP address will change directly. But if there is any issue, it will give you the error message, without losing the connection (as with the next command).

Apply the changes

To apply the new network configuration persistently, you must run this command: sudo netplan apply

After doing this, your new network configuration will be applied automatically on boot, and you should always get the same IP address, gateway and DNS server used on this server.

Verify the new configuration

You can verify the new configuration with the same commands used at the beginning of the article: ip a ip r

In my example, I now have:

assign static ip in ubuntu server

Related questions

How to set up a secondary dns server in netplan.

In the Netplan configuration, a secondary DNS server can be set by appending the server’s IP address to the addresses list under the nameservers section.

I recommend always having a backup DNS server in your configuration to make sure everything keeps working even if the main DNS server is unreachable.

To add this in Netplan, you just need to edit your YAML file and include the second DNS server’s IP address right after your primary one, separated by a comma.

Is it better to set a static IP on the router instead?

Setting a static IP on the router, often referred to as DHCP reservation, is considered more manageable and flexible compared to configuring a static IP on individual devices.

If you can, I recommend setting this static IP directly on the router, especially if you’re managing multiple devices. This way, your router automatically assigns the same IP to your server each time it connects.

It’s easier to configure, you keep track of all your servers in one place, and you avoid conflicts. The only requirement is that you have a router that handles this properly (and that the Ubuntu server you’re setting up now is not your DHCP server).

Can we use “nmcli” instead of editing the Netplan configuration manually?

nmcli, a command-line tool for Network Manager, presents an alternative to Netplan for network configuration on Ubuntu, offering a more interactive and user-friendly approach.

If you’re not a fan of editing YAML files for network settings, nmcli is your friend. It’s straightforward and interactive, making network configuration less intimidating. You can view, modify, and manage all your network connections just with simple commands.

Just keep in mind that on Ubuntu Server, nmcli is not included by default as it is part of the Network Manager package, that must be installed manually. This installation introduces a different network management tool that may override existing network configurations managed by Netplan.

To install NetworkManager, you just need to run: sudo apt install network-manager After installation, you can start using nmcli to change your network configuration in a more user-friendly way: sudo nmcli

How do you restore the original network configuration?

If you followed this tutorial, but something didn’t work as expected, or you want to get back the DHCP configuration (maybe to try to configure everything from the router instead), you can restore the backup configuration file we created.

  • Restore the original file with: sudo cp ~/50-cloud-init.yaml.default /etc/netplan/50-cloud-init.yaml Make sure to change the file name if it was something else on your system.
  • Apply the configuration with: sudo netplan apply

That’s it, you are now back to the default configuration, with the DHCP assigned IP address.

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

  • Master Linux Commands (eBook)
  • The 5 fastest ways to find a file on Linux
  • Snap vs APT: what's the difference?

Additional Resources

Overwhelmed with Linux commands? My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side . Grab your copy now . VIP Community If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads. More details here. Need help building something with Python? Python is a great language to get started with programming on any Linux computer. Learn the essentials, step-by-step, without losing time understanding useless concepts. Get the e-book now.

' src=

I'm the lead author and owner of RaspberryTips.com. My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with web developer experience.

Similar Posts

How To Sync The Ubuntu System Clock? (GUI, TimeDateCtl & NTP)

How To Sync The Ubuntu System Clock? (GUI, TimeDateCtl & NTP)

Time synchronization is an important topic on large networks, especially on Linux computers. A lot of effort has been put into recent system updates to make it work by default, but it doesn’t mean that it does exactly what you want. I will answer all of your questions about time settings in this article. Ubuntu’s…

3 Best Ways to Access a Website in a Linux Terminal

3 Best Ways to Access a Website in a Linux Terminal

Sometimes, you don’t have other options. You must access a website from the Linux terminal. I know I did this a few times when I worked as a sysadmin, and I’m going to share a few tips with you in this article. Overall, Lynx is one of the best options to access a website in…

How To Install RetroPie On Ubuntu: A Step-by-step Guide

How To Install RetroPie On Ubuntu: A Step-by-step Guide

RetroPie is a free solution to play classic games on a computer. It’s often used to promote Raspberry Pi, but it can also be installed on any computer, such as Ubuntu. This is exactly what I will show you today: a complete guide to installing RetroPie on Ubuntu, from start to finish. Ubuntu is officially…

How To Easily Map A Network Drive On Ubuntu (GUI & commands)

How To Easily Map A Network Drive On Ubuntu (GUI & commands)

Whether you use Ubuntu Desktop or Server, it’s possible to access files shared on the network, from a file server, a NAS or another computer. In fact, even if you use another Linux distribution , you’ll follow the same steps. In this tutorial, I’ll explain 3 methods to access a file share on Linux: Pick the…

How To Use Kill: The Complete Linux Command Guide

How To Use Kill: The Complete Linux Command Guide

The “kill” command on Linux is a powerful tool that terminates processes running on your system. You’ll generally use it to stop a misbehaving application or to manage system resources efficiently. I’ve summarized the main options in this article. The “kill” command allows users to terminate, interrupt, pause, or resume processes by specifying the process…

How to Log in as Another User in Linux Terminal (3 Ways)

How to Log in as Another User in Linux Terminal (3 Ways)

Linux can handle many users on the same system but when you only have a black screen to do everything, it’s not necessarily clear how you can switch from one user to another. In this article, I will mention 3 ways to do this. The traditional way to log in as another user on Linux…

Level Up Your Linux Skills: Free PDF with Must-Know Linux Commands!

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

How to Configure static IP address in Ubuntu Server 18.04 LTS

When you install Ubuntu Server 18.04, it will grab a dynamically assigned IP address from your DHCP server, But you cannot run a server with dynamic IP addresses. So it's important to assign a permanent static IP address in place right away.

When it comes to Ubuntu network interface configuration, the way in which you set a static IP has completely changed. The previous LTS version Ubuntu 16.04 used /etc/network/interfaces file to configure static IP addresses, but Ubuntu 18.04 use new method known as netplan.

In this tutorial we will learn how to configure network interfaces in Ubuntu server 18.04 Bionic Beaver with netplan. We will look at how to set static IP addresses, default gateway and DNS name servers.

  • Identify  available network interface with ip command.
  • Netplan and YAML format interface configuration file.
  • Assigning static IP addresses (IPv4).
  • Configure static IPv6 Addresses on Ubuntu Server.
  • Assign multiple IP addresses to a single network interface.
  • Configure Multiple network interfaces.

Identify  available network interface with ip command

Before configure static IP address, you need to identify the available network interfaces on your Ubuntu server 18.04 and what is the device ID assigned to a particular network interface.

If you run ip link show command it will list all available network interfaces on your server.

Identify  available network interface with ip command

To view current IP configuration, run the ip addr command:

The output will display the currently assign IP configuration for all network interfaces.

ubuntu network interfaces

Netplan and YAML format interface configuration file

the way in which you set a static IP has completely changed. Ubuntu 18.04 uses a new method called netplan. In netplan the interface configuration file resides in the /etc/netplan directory and configuration file have .yaml extension. YAML syntax is very easy to understand and you don't need to be an expert on yaml format to edit the interface file. You only need to know what is needed for the network configuration.

If you list the content of the   /etc/netplan directory, you will see the interface configuration file with yaml extension.

In netplan the interface configuration file resides in the /etc/netplan directory and configuration file have .yaml extension

In my Ubuntu server name of the file is 50-cloud-init.yaml, but it could be saved with a different name depends on the Install Type.

On my Ubuntu server content of the file looks like following:

By just looking at the last line: "dhcp4: yes", we can say that the  ethernet interface enp0s3 has been configured to lease IP address from the DHCP Server. So this the configuration you need to have if you are planning to assign dynamic IP addresses from a DHCP server.

Assigning static IP addresses (IPv4)

Here is the sample netplan configuration file with static IP  Assignment (IPV4), In this configuration, interface enp0s3 has been configured with IP 192.168.1.100 and the default gateway of 192.168.1.1.

In order to apply the configuration, run the netplan command:

Then, run the ip add command to make sure that the changes being applied:

How it works..

In the above example, we configured enp0s3 ethernet interface to use static the IP address 192.168.1.100.

The first line:"version: 2" indicate this configuration block use netplan version 2 format.

The next line: "renderer: networkd" tells that this interface is managed by the systemd-networkd service.

An alternative option to networkd is NetworkManager, if the interface is managed by the NetworkManager. If you looked at the netplan config file of the Ubuntu 18.04 desktop, the renderer option is set to NetworkManager, because in a graphical desktop environment interfaces are managed by the NetworkManager.

Next, we start the interface configuration:

Here, enp0s3 is the name of the interface, you can run ip link show command to list network interfaces on your Ubuntu server.

Next, we set the static IP to 192.168.1.100 with the netmask of 24:

The address option can be also defined in following format:

Next, we set the default gateway to 192.168.1.1:

We used the option gateway4 because this is IPv4 gateway, For IPv6 gateway we need to use gateway6 option.

Next, we set the DNS servers to 8.8.8.8 and 4.4.4.4.

To apply new interface configurations, we run the netplan command :

The command will Apply current netplan config to running system. We no longer need to do network restart to apply changes.

Configure static IPv6 Addresses on Ubuntu Server

The same netplan format use to assign IPv6 address, only difference is , we need to use the gateway6 option instead of gateway4 .

Assign multiple IP addresses to a single network interface

It is very common to have a single network interface configured with more that one IP address. Following is the sample Ubuntu netplan config file with two IPv4 address assigned to one network interface.

The address option can be also written in following format:

A single network interface can be configured with both IPv4 and IPv6 addresses as shown in the following netplan file:

Configure Multiple network interfaces

It is very common to install more that one network interface on a single server. Here's an example netplan file, configured with  static addresses for two network cards:

Note that only the primary interface has been configured with a default gateway, In this case it is enp0s3. It is not practical to have more than one default gateway,  the default gateway is the address you send traffic when you have no other route for it.

Let's look at another netplan example where both static and DHCP addresses being used:

In the preceding example, the wifi interface  wlp3s0 has been configured to lease IP address from the DHCP server.

In this tutorial we learned how to configure static IP address on Ubuntu 18.04 Bionic Beaver, where the old /etc/network/interfaces file is no longer in used. Ubuntu 18 now uses the new method called netplan to manage networking.

With Netplan, configuration files for the network interfaces reside in the /etc/netplan directory, in YAML data format, while the netplan command uses to restart networking after configuration changes.

LinuxOPsys

Configure Static IP Address on Ubuntu 20.04 (Server CLI and Desktop)

assign static ip in ubuntu server

In your IT environment, sometimes you may be compelled to configure a static IP instead of relying on the DHCP protocol. A perfect example is when you are setting up a Ubuntu server to act as a file or a web server for your organization. A static IP, as the name suggests, ensures that the IP address of your system remains unchanged. With DHCP, the IP address changes once the lease time for the IP address expires and this is undesirable for servers.

In this guide, we will explore two ways of manually assigning a static IP on Ubuntu 20.04. We will demonstrate how you can configure a static IP on an instance of Ubuntu server and Ubuntu desktop.

Assign a static IP on Ubuntu server 20.04

From Ubuntu 17.10 and later versions, networking is controlled by the Netplan feature. The configuration files for Netplan are located in the /etc/netplan directory and are written in YAML. Inside this directory, you will find YAML configuration files labeled either 50-cloud-init.yaml , or 00-installer-config.yaml .

However, If you are running a cloud instance of Ubuntu, chances are that it is managed by cloud-init which auto-assigns it an IP address by leveraging the DHCP protocol. Before we proceed further, you need to disable cloud-init. To achieve this, open the subiquity-disable-cloudinit-networking.cfg cloud-init configuration file in the /etc/cloud/cloud.cfg.d/ directory

Set the ' network ' directive to ' disabled '.

Save the changes and quit. Next, head over to the Netplan configuration file. In my case, I have the 00-installer-config.yaml file.

assign static ip in ubuntu server

From the configuration file, we can see the ' network' directive that has 2 elements. The first one is the ' ethernets ' which specifies the network interface and the second one is the version of the renderer which is ' systemd-networkd ' for non-GUI instances and NetworkManager for Ubuntu desktop ( With GUI )

Default Netplan configuration file

We are going to set the ' dhcp4 ' value to ' no ' to disable the DHCP protocol and specify the interface's Static IP as follows.

To assign a static IP address to  ens3  interface, modify the file as follows:

  • Specify the static IP address of the server. in the   addresses : section, specify an IPv4 address to be assigned to the network interface.
  • Next, Specify the gateway.
  • Under  nameservers , specify the DNS or IP addresses of the nameservers. Here, we have specified Google's DNS which is 8.8.8.8 and the Router's IP.

Set Static IP on Ubuntu 20.04

Save the YAML file and exit. To apply the changes made, run the command:

You can use the ifconfig or ip command to verify that your network interface is set to use the static IP configured moments ago.

Netplan apply

Additionally, you can use the IP route show command to display the new routes on your system.

Show IP routes on a Linux system

Perfect! We have successfully configured a static IP on the Ubuntu server. Let's now switch gears and see how you can replicate the same on Ubuntu Desktop 20.04

Configure Static IP on Ubuntu 20.04 Desktop

If you are running a Desktop GUI, then configuring a static IP should be quite easy. Click on the ' Network icon ' at the top right corner of your screen and select the 'Wired Settings ' option.

Select Wired settings option

This opens the 'Network ' configuration page. In the 'Wired ' section, click on the gear wheel icon.

Network settings page

This displays a summary of your current IP configuration. By default, the system obtains its IP configuration via the DHCP protocol. We will change from using DHCP to Manual.

Ubuntu Desktop IP configuration

So, click on the ' IPv4 ' tab which directs you to this section. As anticipated, DHCP is turned on.

IPv4 configuration on Ubuntu 20.04

Switch from ' Automatic (DHCP) ' to ' Manual '. Then specify the static IPv4 address including the netmask, gateway, and DNS servers. To save the changes, click on the ' Apply ' button.

Configure static IP Ubuntu 20.04

Head back to the ' Network' section and restart the networking service by toggling off and on.

Restart NetworkManager on Ubuntu 20.04

Once again, click on the gear wheel icon and confirm that the static IP settings have reflected.

Confirm static IP settings

And it's as simple as that. We have successfully configured a static IP on Ubuntu Desktop.

Ubuntu, like most other systems, comes configured with DHCP to obtain an IP from the DHCP server, or router. In this guide, we have covered how you can apply static IP settings on command-line and using the GUI. Before setting a static IP, it's always recommended to reserve the IP that you want to assign to your server on the router. Equally important is to ensure that no other client system is using that IP address to avoid an IP conflict.

If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks

Like

Sorry about that.

About The Author

James kiarie.

James Kiarie

James Kiarie is a skilled and certified LPIC Linux administrator with a strong passion for technical writing, specializing in the Linux domain. With over four years of experience, he has crafted numerous technical guides, helping a wide audience navigate through various Linux distributions.

Nmap to Scan Open Ports – Examples + Screenshots

How to List Network Interfaces in Linux

How to Get IP address in Linux

How to Permanently add Static Route in Linux

Ping IPv6 Address from Windows and Linux CLI

How to Check Ports in Use in Linux (Listening Ports)

Tshark Examples with Cheat Sheet

Leave a Reply

Leave a comment cancel reply.

Logo

How to set a static ip address in Ubuntu Server 20.04

When you install Ubuntu server, its network setting defaults to dynamic IP addressing, that is, the network management daemon in Ubuntu searches for a DHCP server on the connected network and configures the network with the IP address assigned by DHCP. Even when you start an instance in the cloud, the network is configured with dynamic addressing using the DHCP server setup by the cloud service provider. In this chapter, you will learn how to configure the network interface with static IP assignment.

Follow these steps to connect to the network with a static IP:

Step 1 : Open /etc/netplan/50-cloud-init.yaml and find the following lines:

assign static ip in ubuntu server

Step 2 : Change the preceding lines to add an IP address, net mask, and default gateway (replace samples with the respective values):

assign static ip in ubuntu server

Step 3 : Then run sudo netplan apply

assign static ip in ubuntu server

Step 4 : Try to ping a remote host to test the network connection

Recommended

How to Install Nginx on CentOS 7

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How do I set a static IP in Ubuntu 20.04.3 LTS?

I'm trying to set up a lab computer as a ssh server following this guide . One of the steps is setting up a static IP address. So, I was glad to find this answer . Following it, I created /etc/netplan/50-cloud-init.yaml file, pasted

where my_ethernet_num == enp9s0 . Buuuut, after this ip a showed no ip address for the Ethernet:

and sudo lshw -C network yielded *-network DISABLED . Then I tried to use that guide (section 'Static IP Address Assignment'). I created /etc/netplan/99_config.yaml , pasted the necessary code, run sudo netplan apply . Nothing changed except that I STOPPED SEEING wired connections in network settings... I tried the answer from here , and the 'Wired' section returned. But I can't change anything (for example, I can't pick 'Manual' option).

Screenshot

So, the questions are: how can I return the ability of changing it (in order to follow one more guide ), or is there any other solution that will succeed in setting static ip address?...

--EDIT from 12/05/2021--

Here are all of my .yaml files showed by ls -al /etc/netplan :

01-network-manager-all.yaml:

50-cloud-init.yaml:

99_config.yaml:

  • network-manager

Serg's user avatar

  • 1 Probably you should delete/revert all changes that you have made, to get back to the original configuration. Then just use "Manual" option from the GUI. No need to mess with configuration files manually. –  raj Nov 29, 2021 at 12:44
  • @raj, thank you for your comment! If I only knew how to revert all the changes... By the way, after rebooting, I suddenly found out that I can make changes to the settings! So, I'll try the the GUI option and write about results :) –  TopCoder2000 Nov 29, 2021 at 13:31
  • Why does your .yaml use enp0s3, when your interface is enp9s0? Are you using a Server or Desktop installation? –  heynnema Nov 29, 2021 at 23:37
  • @heynnema, because it was in the answer for 'How do I set a static IP in Ubuntu?' . As we can see, enp0s25 is used in the question, but then enp0s3 is used in the answer, so I thought that it always must be enp0s25. > Are you using a Server or Desktop installation? I would like to use a Desktop installation, but I don't know concretely which one I was using... Is there any difference? I tried to follow Desktop installation but I could get confused. –  TopCoder2000 Dec 1, 2021 at 19:31
  • @TopCoder2000 Your network can't possibly be working with enp0s3 in the .yaml file. It needs to be enp9s0. But if you're using a Desktop installation, then your .yaml is all wrong anyway. A Desktop installation has a GUI, a Server installation is CLI only. Also, your self-accepted answer doesn't really make a lot of sense. –  heynnema Dec 1, 2021 at 19:37

Pick ONE of the following two configurations...

Server installation with static IP...

Delete /etc/netplan/01-network-manager-all.yaml

Delete /etc/netplan/50-cloud-init.yaml

Edit /etc/netplan/99_config.yaml to look EXACTLY like this...

Note : regarding 192.168.0.116, make sure this address is outside of the DHCP range set in your router, and is not already used elsewhere.

Note : For DNS nameservers, settle on servers from one source... Google, Cloudflare, OpenDNS, etc. (3 max).

sudo netplan generate

sudo netplan apply

Desktop installation with static IP...

Delete /etc/netplan/99_config.yaml

Edit /etc/netplan/01-network-manager-all.yaml to look EXACTLY like this...

Note : Use the NetworkManager GUI to setup your static IP for "Wired Connection".

Note : See https://netplan.io/examples/ for examples and design info about netplan.

heynnema's user avatar

  • Thank you for your answer and netplan examples! Now ip a shows correct output. But how do I setup a static IP with NetworkManager GUI? –  TopCoder2000 Dec 6, 2021 at 18:28
  • @TopCoder2000 Firstly, you can't use both parts of my answer at the same time. It's part 1 or part 2. If you're using part 2, then my answer says "Use the NetworkManager GUI to setup your static IP for "Wired Connection"" . See the IPv4 tab. Click on the manual button. Fill in the address, mask, gateway, and DNS servers, and turn off DNS Auto. –  heynnema Dec 6, 2021 at 18:44
  • yes, I remember! I'll accept it as soon as I don't have any questions :) Yes, I'm using the second option. But you also wrote yesterday that 'Static IPs should be set to be outside of the DHCP range set in the router'. But how do I know that set? For example, the second answer from here says that we have to check DHCP server configuration... –  TopCoder2000 Dec 7, 2021 at 6:51
  • @TopCoder2000 You must log into the admin page of your router and find the DHCP server settings. For your computer's static IP, you'll need to pick an address outside of the DHCP server's range of addresses. –  heynnema Dec 7, 2021 at 15:01
  • Ah, good! Thanks! –  TopCoder2000 Dec 9, 2021 at 7:07

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged networking 20.04 network-manager ethernet ..

  • The Overflow Blog
  • Why do only a small percentage of GenAI projects actually make it into...
  • Spreading the gospel of Python
  • Featured on Meta
  • Our Partnership with OpenAI
  • What deliverables would you like to see out of a working group?

Hot Network Questions

  • Discriminant formula - do the coefficients include their signs?
  • How to provide opportunities for role playing in a single player campaign focused on travelling and wilderness survival?
  • Embedding Riemannian manifold into Euclidean space with matching distances
  • Is there an easy way to store yogurt and have it maintain its consistency?
  • Negative pressure projectile propellants (Alternatives to gunpowder)
  • Why does Hindley claim to have crammed Kenneth head first into a bog?
  • Movie in which the couple figurine atop a wedding cake doubles as a voodoo doll
  • How do I randomize filenames recursively?
  • How should one decide the author order
  • Why is there little difference in glm fit using poisson and gaussian family for Poisson data?
  • How much does one American Airline frequent flier mile equal in US$?
  • How to define a command (or similar) that makes a conditional expression reusable?
  • Delta method vs actual expectation
  • Proverb for someone who mistakenly assumes he has found the right answer and is unwilling to accept his error?
  • What exactly does RootSum mean?
  • I lost the keys for a gate's lock. Where can I find a replacement cylinder or how can I get new keys?
  • I was denied entry in the UK - is my visa cancelled?
  • KOMA Script (scrlttr2) and tabularray - compatibility issues?
  • Why did the authors use the phrase "the quantity of people" in these examples?
  • How to protect a country with no army, no police, no guards, no military authority?
  • Why is Paul adamant about the second coming of Christ during his lifetime but it didn't happen?
  • Is this a school badge?
  • Is nitroglycerin synthesis within human digestive system from eating soap possible?
  • Automating wing flap animation for a bee

assign static ip in ubuntu server

TechRepublic

Account information.

assign static ip in ubuntu server

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

assign static ip in ubuntu server

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 .

assign static ip in ubuntu server

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.

assign static ip in ubuntu server

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.

Tecmint: Linux Howtos, Tutorials & Guides

How to Configure Static IP Address on Ubuntu 20.04

Usually, when a client system connects to a network via WiFi or an ethernet cable, it automatically picks an IP address from the router. This is made possible through the DHCP server which auto-assigns IP addresses to clients from a pool of addresses.

The drawback with DHCP is that once the DHCP lease time has lapsed, the IP address of a system changes to a different one, and this leads to a disconnection in case the system was used for a particular service such as a file server. For this reason, you may want to set a static IP address so that it never changes even when the lease time is up.

In this guide, you will learn how to configure a static IP address on Ubuntu 20.04 server and desktop.

Network Configuration

Ubuntu uses the NetworkManager daemon for managing network configuration. You can configure a static IP either graphically or on the command line.

For this guide, we will focus on setting a static IP address using both the GUI and on the command line, and here is the IP configuration:

This information will be different for you, so replace the values accordingly according to your subnet.

On this page

  • Set Static IP Address on Ubuntu 20.04 Desktop
  • Set Static IP Address on Ubuntu 20.04 Server

How to Set Static IP Address On Ubuntu Desktop

To get started, Launch ‘ Settings ’ from the application menu as shown.

Ubuntu Settings

On the window that appears, click on the ‘ Network ’ tab at the left sidebar and then hit the gear icon on the network interface that you wish to configure. In my case, I’m configuring my wired interface.

Ubuntu Network

In the new window that appears, your interface’s network settings will be displayed as shown. By default, the IP address is set to use DHCP to automatically pick an IP address from the Router or any other DHCP server.

In our case, the current IP address assigned is 192.168.2.104 .

Ubuntu Network Configuration

Now select the IPv4 tab to start setting the static IP address. As you can see, the IP addressing is set to Automatic (DHCP) by default.

Ubuntu Network Method

Click on the ‘ Manual ’ option and new address fields will be displayed. Fill out your preferred static IP address, netmask, and default gateway.

Set Manual Network

The DNS is also set to automatic. To manually configure the DNS, click on the toggle to turn off Automatic DNS. Then provide your preferred DNS entries separated by a comma as shown.

Set Network DNS

Once all is done, click on the ‘ Apply ’ button at the top right corner of the window. For the changes to apply, restart the network interface by clicking on the toggle to disable it and enable it again.

Enable Network Connection

Once again, click on the gear icon to reveal the new IP configuration as shown.

Verify Network Configuration

You can also confirm the IP address on the terminal by running the ifconfig or ip addr command .

Check IP Address

To confirm the DNS servers, run the command:

Check DNS Servers

How to Set Static IP Address on Ubuntu Server Using Netplan

We have seen how we can configure a static IP address graphically on Ubuntu 20.04 desktop. The other option is configuring a static IP address on the terminal using Netplan .

Developed by Canonical, Netplan is a command-line utility used to configure networking on modern Ubuntu distributions. Netplan makes use of YAML files to configure network interfaces. You can configure an interface to acquire an IP dynamically using DHCP protocol or set a static IP.

Open your terminal and head over to the /etc/netplan directory. You will find a YAML configuration file which you will use to configure the IP address.

In my case the YAML file is 01-network-manager-all.yaml with the default settings as shown.

Netplan YAML File

For the Ubuntu server, the YAML file is 00-installer-config.yaml and these are the default settings.

Default Network Settings

To configure a static IP, copy and paste the configuration below. Be mindful of the spacing in the YAML file.

Next, save the file and run the netplan command below to save the changes.

You can thereafter confirm the IP address of your network interface using the ifconfig command .

Check Ubuntu Server IP Address

This wraps up today’s article. We hope you are now in a position to configure a static IP address on your Ubuntu 20.04 desktop & server system.

Previous article:

Next article:

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

Configure Network Ethernet Connection Using nmcli Tool

How to Configure Network IP Connections Using ‘nmcli’ in Linux

Linux IP Address

A Beginner’s Guide to Configuring IPv4 and IPv6 Addresses in Linux

Differences Between IPv4 and IPv6

What’s Wrong with IPv4 and Why We Are Moving to IPv6

Linux Network Information Tool

What IP – A Network Information Tool for Linux

Configure Network Interface in CentOS 7

How to Configure Network Static IP Address on RHEL/CentOS 8/7

Create NIC Teaming in CentOS

How to Create NIC Teaming or Bonding in CentOS 8 / RHEL 8

21 Comments

DHCP is that once the DHCP lease time has lapsed, the IP address of a system changes to a different one, and this leads to a disconnection in case the system was used for a particular service such as a file server.

For this reason, you may want to set a static IP address so that it never changes even when the lease time is up.

Thanks for documenting this. However, after a reboot, I am left with the old IP address (DHCP). Guess there is another process that overrules the yaml file, but what??

Hey Pieter, that’s awkward. Ideally, the IP should not change since it’s a static IP. Did you try out both procedures. I’m just curious.

I had a static IP in the yaml file and this does not get an update if you adjust its IP via.

netplan ip a prior to gui adjustments gui DHCP => ip DHCP Gui static ip b => ip a It seems that netplan is not updated via GUI adjustments Enjoy the coffee ‘)

Could this lead to a clash of IP addresses between two computers on the same network? Another computer (computer B) which gets its IP address dynamically comes online when the computer with the static IP (computer A) is offline.

The dhcp server could assign the IP to computer B. Subsequently, when computer A comes online and tries to join the network there would be an IP conflict and both computers could end up not being able to connect to network resources or perform other network operations.

In some routers, this can be managed by restricting the range of IP addresses that the router can dynamically assign. Many routers don’t have that option.

To avoid the potential of such conflicts, I assign static IP addresses on the dhcp server to computers on the network based on the MAC addresses of their NICs.

I would appreciate your thoughts on how to prevent IP conflicts when the network is made of some devices that have static in and others have dynamic IP addresses assigned to them. This scenario is more common today where network devices like smart phones, tablets, smart TVs, and media streaming devices connecting to the network.

Managing IP addresses by MAC addresses is a pain and it would be very helpful if there is an easier way to prevent IP conflicts.

Your concern is very valid. To avoid a conflict in IP address assignment in a network, as you have just described, consider reserving the IP assigned to the server on the router. Say for example, if you want to assign Server A an IP of 172.16.0.100, simply login into your router and reserve the IP address. This prevents the IP from being made available to client PCs & other network devices via the DHCP protocol.

Ideally, before the static assignment, proper mapping of your network is advised so as to know which device is using which IP address. You can use nifty tools like Nmap to scan your network to get to know which IP addresses are in use to avoid assigning a duplicate IP statically on the server.

I hope this answers your question.

Wonderful post. Very simple and to the point. Thank you!!!! Keep it up!!!

Thank you very much Jaidev Shah. Keep it Tecmint.

Hi, why when we use the desktop method, the interfaces file does not get updated ? Where does the desktop tool write the information ?

That’s actually a very interesting question and I did not think about it before. I just configured a static IP on one of my Ubuntu boxes and used grep from /etc/ folder recursively to search for that IP. The IP address was written in:

/etc/NetworkManager/system-connections/Wired\ connection\ 1

So if you need to look where the desktop tool has written your settings, you can look at:

/etc/NetworkManager/system-connections/

Hey Marin, thanks for your contribution. I hadn’t actually seen it from that angle. Quite interesting I must say.

Great article just wondering about this part: “Remember to replace “enp0s3” with the name of your network adapter??? what do u mean by this? do you mean we should not change this name enp0s3 or changed with our network adapter? Cheers

Means, you should change “enp0s3” with your network adapter name for example, eth0 or eth1..

Sorry for my english, I would put a secondary IP in the same interface, like old versions (eth0 192.168.1.100… eth0:1 10.10.0.100) I know how to do it in the old versions, but in version 15.10, they have changed the commands. Can you help me?

Hello Nikon,

As the answer of this question is too long for the comment section, I would recommend you to submit your question to our Linuxsay discussion forum, where we will gladly provide more details:

http://linuxsay.com/

Where do the Nameserver numbers obtained? Elaborate on “Make sure to use your own settings depending on the network to which you are connected to.”

Can you please expand on this? IMPORTANT NOTE: For the purpose of this tutorial, I will be using the following settings:

IP Address: 192.168.0.100 Netmask: 255.255.255.0 Gateway: 192.168.0.1 Nameserver: 8.8.8.8 Nameserver: 8.8.4.4 Make sure to use your own settings depending on the network to which you are connected to. Where do you obtain the Nameserver numbers?

This depends on few things:

If your machine is connected to a router, you should see the settings in there.

If you are plugging your ISP’s internet cable directly to your computer (i.e no router, modem etc), you should use your ISP’s settings.

I want 1st IP by DHCP and 2nd static but, in Ubuntu 15.10 mi interface isn’t eth0 it is eno1 and if I put eno1:1 don’t works.

Actually the init script does exactly that – it calls systemctl. You can see it in the screenshot:

“restarting networking (via systemctl): networking service”

Both scripts do the same.

Why not use systemd to restart networking directly?

`systemctl restart network`

Got Something to Say? Join the Discussion... Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

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

How to Configure Static IP Address on Ubuntu 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.

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.

Tutorial: Install a LAMP server on AL2

The following procedures help you install an Apache web server with PHP and MariaDB (a community-developed fork of MySQL) support on your AL2 instance (sometimes called a LAMP web server or LAMP stack). You can use this server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.

If you are trying to set up a LAMP web server on a different distribution, such as Ubuntu or Red Hat Enterprise Linux, this tutorial will not work. For AL2023, see Install a LAMP server on AL2023 . For Ubuntu, see the following Ubuntu community documentation: ApacheMySQLPHP . For other distributions, see their specific documentation.

Option: Complete this tutorial using automation

To complete this tutorial using AWS Systems Manager Automation instead of the following tasks, run the AWSDocs-InstallALAMPServer-AL2 Automation document.

Step 1: Prepare the LAMP server

Step 2: test your lamp server, step 3: secure the database server, step 4: (optional) install phpmyadmin, troubleshoot, related topics, prerequisites.

This tutorial assumes that you have already launched a new instance using AL2, with a public DNS name that is reachable from the internet. For more information, see Launch an instance in the Amazon EC2 User Guide for Linux Instances . You must also have configured your security group to allow SSH (port 22), HTTP (port 80), and HTTPS (port 443) connections. For more information about these prerequisites, see Security group rules in the Amazon EC2 User Guide for Linux Instances .

The following procedure installs the latest PHP version available on AL2, currently php8.2 . If you plan to use PHP applications other than those described in this tutorial, you should check their compatibility with php8.2 .

To prepare the LAMP server

Connect to your instance.

To ensure that all of your software packages are up to date, perform a quick software update on your instance. This process may take a few minutes, but it is important to make sure that you have the latest security updates and bug fixes.

The -y option installs the updates without asking for confirmation. If you would like to examine the updates before installing, you can omit this option.

Install the mariadb10.5 Amazon Linux Extras repositories to get the latest version of the MariaDB package.

If you receive an error stating sudo: amazon-linux-extras: command not found , then your instance was not launched with an Amazon Linux 2 AMI (perhaps you are using the Amazon Linux AMI instead). You can view your version of Amazon Linux using the following command.

Install the php8.2 Amazon Linux Extras repositories to get the latest version of the PHP package for AL2.

Now that your instance is current, you can install the Apache web server, MariaDB, and PHP software packages. Use the yum install command to install multiple software packages and all related dependencies at the same time

You can view the current versions of these packages using the following command:

Start the Apache web server.

Use the systemctl command to configure the Apache web server to start at each system boot.

You can verify that httpd is on by running the following command:

Add a security rule to allow inbound HTTP (port 80) connections to your instance if you have not already done so. By default, a launch-wizard- N security group was set up for your instance during initialization. This group contains a single rule to allow SSH connections.

Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ .

Choose Instances and select your instance.

On the Security tab, view the inbound rules. You should see the following rule:

Using 0.0.0.0/0 allows all IPv4 addresses to access your instance using SSH. This is acceptable for a short time in a test environment, but it's unsafe for production environments. In production, you authorize only a specific IP address or range of addresses to access your instance.

Choose the link for the security group. Using the procedures in Add rules to a security group , add a new inbound security rule with the following values:

Type : HTTP

Protocol : TCP

Port Range : 80

Source : Custom

Test your web server. In a web browser, type the public DNS address (or the public IP address) of your instance. If there is no content in /var/www/html , you should see the Apache test page. You can get the public DNS for your instance using the Amazon EC2 console (check the Public DNS column; if this column is hidden, choose Show/Hide Columns (the gear-shaped icon) and choose Public DNS ).

Verify that the security group for the instance contains a rule to allow HTTP traffic on port 80. For more information, see Add rules to security group .

If you are not using Amazon Linux, you may also need to configure the firewall on your instance to allow these connections. For more information about how to configure the firewall, see the documentation for your specific distribution.

The test of the server shows the Apache test page.

Apache httpd serves files that are kept in a directory called the Apache document root. The Amazon Linux Apache document root is /var/www/html , which by default is owned by root.

To allow the ec2-user account to manipulate files in this directory, you must modify the ownership and permissions of the directory. There are many ways to accomplish this task. In this tutorial, you add ec2-user to the apache group, to give the apache group ownership of the /var/www directory and assign write permissions to the group.

To set file permissions

Add your user (in this case, ec2-user ) to the apache group.

Log out and then log back in again to pick up the new group, and then verify your membership.

Log out (use the exit command or close the terminal window):

To verify your membership in the apache group, reconnect to your instance, and then run the following command:

Change the group ownership of /var/www and its contents to the apache group.

To add group write permissions and to set the group ID on future subdirectories, change the directory permissions of /var/www and its subdirectories.

To add group write permissions, recursively change the file permissions of /var/www and its subdirectories:

Now, ec2-user (and any future members of the apache group) can add, delete, and edit files in the Apache document root, enabling you to add content, such as a static website or a PHP application.

To secure your web server (Optional)

A web server running the HTTP protocol provides no transport security for the data that it sends or receives. When you connect to an HTTP server using a web browser, the URLs that you visit, the content of webpages that you receive, and the contents (including passwords) of any HTML forms that you submit are all visible to eavesdroppers anywhere along the network pathway. The best practice for securing your web server is to install support for HTTPS (HTTP Secure), which protects your data with SSL/TLS encryption.

For information about enabling HTTPS on your server, see Tutorial: Configure SSL/TLS on AL2 .

If your server is installed and running, and your file permissions are set correctly, your ec2-user account should be able to create a PHP file in the /var/www/html directory that is available from the internet.

To test your LAMP server

Create a PHP file in the Apache document root.

If you get a "Permission denied" error when trying to run this command, try logging out and logging back in again to pick up the proper group permissions that you configured in To set file permissions .

In a web browser, type the URL of the file that you just created. This URL is the public DNS address of your instance followed by a forward slash and the file name. For example:

You should see the PHP information page:

Test of the LAMP server shows the PHP information page.

If you do not see this page, verify that the /var/www/html/phpinfo.php file was created properly in the previous step. You can also verify that all of the required packages were installed with the following command.

If any of the required packages are not listed in your output, install them with the sudo yum install package command. Also verify that the php7.2 and lamp-mariadb10.2-php7.2 extras are enabled in the output of the amazon-linux-extras command.

Delete the phpinfo.php file. Although this can be useful information, it should not be broadcast to the internet for security reasons.

You should now have a fully functional LAMP web server. If you add content to the Apache document root at /var/www/html , you should be able to view that content at the public DNS address for your instance.

The default installation of the MariaDB server has several features that are great for testing and development, but they should be disabled or removed for production servers. The mysql_secure_installation command walks you through the process of setting a root password and removing the insecure features from your installation. Even if you are not planning on using the MariaDB server, we recommend performing this procedure.

To secure the MariaDB server

Start the MariaDB server.

Run mysql_secure_installation .

When prompted, type a password for the root account.

Type the current root password. By default, the root account does not have a password set. Press Enter.

Type Y to set a password, and type a secure password twice. For more information about creating a secure password, see https://identitysafe.norton.com/password-generator/ . Make sure to store this password in a safe place.

Setting a root password for MariaDB is only the most basic measure for securing your database. When you build or install a database-driven application, you typically create a database service user for that application and avoid using the root account for anything but database administration.

Type Y to remove the anonymous user accounts.

Type Y to disable the remote root login.

Type Y to remove the test database.

Type Y to reload the privilege tables and save your changes.

(Optional) If you do not plan to use the MariaDB server right away, stop it. You can restart it when you need it again.

(Optional) If you want the MariaDB server to start at every boot, type the following command.

phpMyAdmin is a web-based database management tool that you can use to view and edit the MySQL databases on your EC2 instance. Follow the steps below to install and configure phpMyAdmin on your Amazon Linux instance.

We do not recommend using phpMyAdmin to access a LAMP server unless you have enabled SSL/TLS in Apache; otherwise, your database administrator password and other data are transmitted insecurely across the internet. For security recommendations from the developers, see Securing your phpMyAdmin installation . For general information about securing a web server on an EC2 instance, see Tutorial: Configure SSL/TLS on AL2 .

To install phpMyAdmin

Install the required dependencies.

Restart Apache.

Restart php-fpm .

Navigate to the Apache document root at /var/www/html .

Select a source package for the latest phpMyAdmin release from https://www.phpmyadmin.net/downloads . To download the file directly to your instance, copy the link and paste it into a wget command, as in this example:

Create a phpMyAdmin folder and extract the package into it with the following command.

Delete the phpMyAdmin-latest-all-languages.tar.gz tarball.

(Optional) If the MySQL server is not running, start it now.

In a web browser, type the URL of your phpMyAdmin installation. This URL is the public DNS address (or the public IP address) of your instance followed by a forward slash and the name of your installation directory. For example:

You should see the phpMyAdmin login page:

Result of typing the URL of your phpMyAdmin installation is the phpMyAdmin login screen.

Log in to your phpMyAdmin installation with the root user name and the MySQL root password you created earlier.

Your installation must still be configured before you put it into service. We suggest that you begin by manually creating the configuration file, as follows:

To start with a minimal configuration file, use your favorite text editor to create a new file, and then copy the contents of config.sample.inc.php into it.

Save the file as config.inc.php in the phpMyAdmin directory that contains index.php .

Refer to post-file creation instructions in the Using the Setup script section of the phpMyAdmin installation instructions for any additional setup.

For information about using phpMyAdmin, see the phpMyAdmin User Guide .

This section offers suggestions for resolving common problems you may encounter while setting up a new LAMP server.

I can't connect to my server using a web browser

Perform the following checks to see if your Apache web server is running and accessible.

Is the web server running?

If the httpd process is not running, repeat the steps described in To prepare the LAMP server .

Is the firewall correctly configured?

I can't connect to my server using HTTPS

Perform the following checks to see if your Apache web server is configured to support HTTPS.

Is the web server correctly configured?

After you install Apache, the server is configured for HTTP traffic. To support HTTPS, enable TLS on the server and install an SSL certificate. For information, see Tutorial: Configure SSL/TLS on AL2 .

Verify that the security group for the instance contains a rule to allow HTTPS traffic on port 443. For more information, see Add rules to a security group .

For more information about transferring files to your instance or installing a WordPress blog on your web server, see the following documentation:

Transfer files to your Linux instance using WinSCP .

Transfer files to Linux instances using an SCP client .

Tutorial: Host a WordPress blog on AL2

For more information about the commands and software used in this tutorial, see the following webpages:

Apache web server: http://httpd.apache.org/

MariaDB database server: https://mariadb.org/

PHP programming language: http://php.net/

The chmod command: https://en.wikipedia.org/wiki/Chmod

The chown command: https://en.wikipedia.org/wiki/Chown

For more information about registering a domain name for your web server, or transferring an existing domain name to this host, see Creating and Migrating Domains and Subdomains to Amazon Route 53 in the Amazon Route 53 Developer Guide .

Warning

To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.

Thanks for letting us know we're doing a good job!

If you've got a moment, please tell us what we did right so we can do more of it.

Thanks for letting us know this page needs work. We're sorry we let you down.

If you've got a moment, please tell us how we can make the documentation better.

IMAGES

  1. How to Set Static IP Address on Ubuntu 22.04

    assign static ip in ubuntu server

  2. How to Assign Static IP Address on Ubuntu Linux

    assign static ip in ubuntu server

  3. how to set a static ip address in ubuntu 20 04

    assign static ip in ubuntu server

  4. How to Configure Static IP Address on Ubuntu 20.04

    assign static ip in ubuntu server

  5. How To Assign Static Ip Address On Ubuntu 20 04 Lts

    assign static ip in ubuntu server

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

    assign static ip in ubuntu server

VIDEO

  1. How to Setting Static IP Ubuntu Server

  2. How to assign Static IP Address in Ubuntu 17.04

  3. Lab 03 Server Activate, VM tools Install, Assign Static IP and Rename Server Name

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

  5. How To Setup Static IP Address On Ubuntu 23.04

  6. How to configure static IP in Ubuntu 22

COMMENTS

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

  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

    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.

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

  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. How to Set Static IP Address on Ubuntu Server (Step-by-step)

    But for a server, it's recommended to configure it with a static IP, often outside the DHCP range, so it's always available at the same address. How do you configure this without a GUI? Let's find out. On Ubuntu Server, the network configuration is managed by the netplan utility, with the configuration file located in /etc/netplan.

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

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

    Configure Static IP address on Server. 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.

  9. Ubuntu Static IP configuration

    In this tutorial, you will learn all about Ubuntu static IP address configuration. We will provide the reader with a step by step procedure on how to set static IP address on Ubuntu Server via netplan and Ubuntu Desktop using NetworkManager.Static IP address is recommended for servers as the static address does not change as oppose to a dynamic IP address assignment via DHCP server.

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

  11. Netplan static IP on Ubuntu configuration

    To configure a static IP address on your Ubuntu server you need to find and modify a relevant netplan network configuration file. See the above section for all possible Netplan configuration file locations and forms.For example you might find there a default netplan configuration file called 50-cloud-init.yaml with a following content ...

  12. How to Configure static IP address in Ubuntu Server 18.04 LTS

    ethernets: enp0s3: Here, enp0s3 is the name of the interface, you can run ip link show command to list network interfaces on your Ubuntu server. Next, we set the static IP to 192.168.1.100 with the netmask of 24: addresses: - 192.168.1.100/24. The address option can be also defined in following format:

  13. Configure Static IP Address on Ubuntu 20.04 (Server CLI and Desktop)

    Configure Static IP on Ubuntu 20.04 Desktop. If you are running a Desktop GUI, then configuring a static IP should be quite easy. Click on the ' Network icon ' at the top right corner of your screen and select the 'Wired Settings ' option. This opens the 'Network ' configuration page. In the 'Wired ' section, click on the gear wheel icon.

  14. How to set a static ip address in Ubuntu Server 20.04

    Even when you start an instance in the cloud, the network is configured with dynamic addressing using the DHCP server setup by the cloud service provider. In this chapter, you will learn how to configure the network interface with static IP assignment. Follow these steps to connect to the network with a static IP:

  15. How do I set a static IP in Ubuntu 20.04.3 LTS?

    If you're using part 2, then my answer says "Use the NetworkManager GUI to setup your static IP for "Wired Connection"". See the IPv4 tab. Click on the manual button. See the IPv4 tab. Click on the manual button.

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

  17. How to Configure Static IP Address on Ubuntu 20.04

    Ubuntu Network Method. Click on the ' Manual ' option and new address fields will be displayed. Fill out your preferred static IP address, netmask, and default gateway. Set Manual Network. The DNS is also set to automatic. To manually configure the DNS, click on the toggle to turn off Automatic DNS.

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

    Set a Static IP on Ubuntu With the nmcli Command It's pretty easy to configure Ubuntu 22.04 static IP settings using the nmcli command. nmcli 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 ...

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

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

  21. How to Configure Static IP Address on Ubuntu 24.04

    Step 1: Access Network Settings. Click on the icons at the top right corner of the screen. Click the > icon next to Wired or Wireless connection. Click the (Wired) Settings option as shown in screenshot. This will show you the current IP address with other network details. Click the gear icon in front of them:

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

    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, ... Configure static IP address on Ubuntu 22.04 Server; To apply the new Netplan changes execute: $ sudo netplan apply Alternatively, if you run into some issues run: ...

  23. Change IP address on Ubuntu Server

    You have two options when configuring the IP address on your Ubuntu Server, and that is either a static IP address or DHCP. A static IP address allows you to manually select your IP address by configuring it on the Linux system, whereas DHCP relies on the router or DHCP server to lease you an IP address - either a reserved one or the next available one that is currently free, depending on ...

  24. How To Set Up Your Own VPN Server: A Step-By-Step Guide

    Allocate a static IP or use a DNS service: To ensure your cloud VPN server is easily accessible, allocate a static IP address to your VM. Alternatively, you can use a DDNS service if a static IP isn't available. Test the VPN connection: Connect to your new VPN server using a VPN client. Ensure that you can establish a connection and that all ...

  25. Deploy an on-premise data hub with Canonical MAAS, Spark ...

    Click on the VLAN link to the left of this network. The link is likely titled "untagged". Find and click the button "Configure DHCP". Leave the checkbox "MAAS provides DHCP" checked. Choose "Provide DHCP from rack controller (s)". Click the dropdown list entitled "Select subnet…" and choose the available subnet.

  26. Tutorial: Install a LAMP server on AL2

    The following procedures help you install an Apache web server with PHP and MariaDB (a community-developed fork of MySQL) support on your AL2 instance (sometimes called a LAMP web server or LAMP stack). You can use this server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.