How to configure a static IP address on the Ubuntu 22.10 server?

How to configure a static IP address on the Ubuntu 22.10 server?

When using an Ubuntu server, it is important to have an IP address assigned to it so that it can communicate with other devices on the network. In most cases, the IP address is assigned dynamically by the DHCP server. This means that it can change at any time. However, in some cases, it is preferable to assign a static IP address to the server. And this for security reasons or for the configuration of specific services.

In this article, we will see how to set up a static IP address on your Ubuntu server in a few simple steps.

Understanding the basics

A static IP address is a fixed IP address that is manually assigned to a device on the network. This can be servers, routers or printers.

Unlike a dynamic IP address, which is assigned automatically via DHCP server, a static IP address does not change. This means that the device keeps the same IP address even after a reboot.

Identify the IP address of your Ubuntu 22.10 server

Before you can configure a static IP address on your Ubuntu server, you must identify the current IP address of your server and the network interface used by the server. You can do this by following these steps:

Step 1: Connect via your terminal to your Ubuntu server;

Step 2: Type the following command to display the current IP address of your server:

ip address show 

This command displays all network interfaces currently available on your Ubuntu server, along with their current IP addresses.

So you should see an output similar to this one:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 76:e1:4d:64:dc:91 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.79/24 metric 100 brd 192.168.1.255 scope global dynamic enp0s1
       valid_lft 86073sec preferred_lft 86073sec
    inet6 2c0f:f0f8:69b:9100:74e1:4dff:fe64:dc91/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 873sec preferred_lft 873sec
    inet6 fe80::74e1:4dff:fe64:dc91/64 scope link 
       valid_lft forever preferred_lft forever

In this example, the current IP address of the server is 192.168.1.79, which is assigned to the enp0s1 interface. Note that your command output may differ depending on your network configuration.

Now that you have identified the current IP address of your Ubuntu server and the network interface used by the server, we will see how to configure a static IP address on your server.

Static IP address configuration on an Ubuntu server

To do this configuration, you must edit the configuration file of the corresponding network interface.

Here are the steps to follow to configure a static IP address for your Ubuntu server:

Step 1: Connect via your terminal to your Ubuntu server;

Step 2: Edit the corresponding network interface configuration file using the nano or vim text editor. In this example, we will use nano :

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

Step 3: In the configuration file, you must add your static IP address information. Here is an example of a configuration:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.1.79/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

In this example, we have configured the IP address 192.168.1.79 with a subnet mask of 24, the default gateway is 192.168.1.1 and the DNS servers are 8.8.8 and 8.8.4.4. So note that you must replace the values in this configuration file with the appropriate values for your network.

Step 4: Once you have finished editing the configuration file, save it using Ctrl + X, Y, then Enter.

Step 5: Apply the new configuration by running the following command:

sudo netplan apply

This command applies the new network configuration and restarts the network interface.

Congratulations! You have just configured a static IP address on your Ubuntu server.

Test of the configuration

Now that we have configured a static IP address on your Ubuntu server, we can check if the configuration works correctly.

Here is how to test the configuration:

Step 1: Connect via a terminal on your Ubuntu server;

Step 2: Check the IP address of your network interface with the following command:

ip addr show enp0s1

Replace enp0s1 with the name of the network interface you have configured.

So you should see an output that looks like this:

2: enp0s1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 76:e1:4d:64:dc:91 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.79/24 metric 100 brd 192.168.1.255 scope global dynamic enp0s1
       valid_lft 86059sec preferred_lft 86059sec
    inet6 2c0f:f0f8:69b:9100:74e1:4dff:fe64:dc91/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 1087sec preferred_lft 1087sec
    inet6 fe80::74e1:4dff:fe64:dc91/64 scope link 
       valid_lft forever preferred_lft forever

The line starting with inet should display your new static IP address.

Step 3: Check that you can access the Internet using the ping command:

ping google.com

If the ping command succeeds, it means that your Internet connection is working properly.

Congratulations! You have completed the configuration of your static IP address and verified that the configuration works correctly. You are now ready to use your Ubuntu server with a static IP address.

See how to install Ubuntu?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.