5

How to Configure Static IP Address on Ubuntu 22.04 LTS

 2 years ago
source link: https://www.makeuseof.com/configure-static-ip-address-settings-ubuntu-22-04/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to Configure Static IP Address on Ubuntu 22.04 LTS

By Fatih Küçükkarakurt Published 9 hours ago

Switching from dynamic IP allocation to static IP addresses is easy on Ubuntu 22.04 "Jammy Jellyfish."

The IP address of most devices today is generated by the Dynamic Host Configuration Protocol (DHCP) server. 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 in Ubuntu 22.04 LTS in three different ways. Here's how to get started.

Set a Static IP on Ubuntu With the nmcli Command

It is easy to set static IP settings in Ubuntu 22.04 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.

Follow the steps below to set a static IP address with the nmcli command.

You can get information about your connection with the following command:

nmcli connection show

The output of this command will be as follows:

NAME                UUID                                  TYPE             DEVICE 
Wired connection 1 12f312a7-f0e7-334a-8ab4-c7b3f8249c7e ethernet enp0s3

Create a static link with the command below. Then, manually configure the enp0s3 and ipv4 settings with the appropriate parameters in the nmcli command.

sudo nmcli con add type ethernet con-name 'static' ifname enp0s3 ipv4.method manual ipv4.addresses 192.168.1.89/24 gw4 192.168.1.1

If you use the nmcli connection show command again, you can see that the static link has been added.

nmcli-add-static-command-show

After this process, add the static connection you created to the DNS IP.

sudo nmcli con mod static ipv4.dns 192.168.*.*

Now use the command below to activate the connection:

sudo nmcli con up id 'static'

If the output displays "connection successfully activated," you've successfully set up a static IP address on your machine.

You can verify the static IP you want to assign to your device by running the following command:

ip route
ip-route-command-output

Using Netplan for Static IP Settings on Ubuntu

Similar to nmcli, the netplan command allows you to set static IP settings on Ubuntu 22.04 LTS. To do this, follow the steps below.

First, find out the name of your network interface using the command below:

sudo ip a
sudo-ip-a-command-output

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.

sudo vim /etc/netplan/01-netcfg.yaml

Add the following lines to the file:

network:
version: 2
renderer: networkd
ethernets:
eth0: #Edit this line according to your network interface name you just saw.
dhcp4: no
addresses:
- 192.168.1.10/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4

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 command to apply the changes:

sudo netplan apply

Configure Static IP Settings on Ubuntu Graphically

The graphical network settings interface in Ubuntu 22.04 is very useful if you don't like to deal with the command line. You can set the static IP address you want 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.

settings-screen-settings-1

Then, switch to the IPv4 tab in the window that opens.

ipv4-settings-with-gui

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.

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

gui-settings-apply

Why Should You Use Static IP Addresses?

You learned how to configure static IP settings in "Jammy Jellyfish" 22.04, the latest LTS version of Ubuntu, using both the graphical settings interface and the two terminal commands: nmcli and netplan.

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.

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.

About The Author
624db80f0078d-profile.jpg?fit=crop&w=100&h=100

Fatih Küçükkarakurt (3 Articles Published)

An engineer and software developer who is a fan of math and technology. He has always liked computers, mathematics and physics. He has developed game engine projects as well as machine learning, artificial neural networks and linear algebra libraries. Moreover continues to work on machine learning and linear matrices.

More From Fatih Küçükkarakurt

Subscribe to our newsletter

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!

Click here to subscribe

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK