+5 votes
697 views
in Linux/Unix by (242k points)
reopened
Configure static IP Ubuntu Server 21.04

1 Answer

+3 votes
by (1.6m points)
 
Best answer

How to assign a static IP address in Ubuntu Server 21.04

The IP address of a computer is essential for it to connect to the global Internet network and all associated services can be offered. The IP is basically the identifier of the equipment before all the network parameters ..

 

 

The IP (Internet Protocol) allows a server to manage the equipment and that is why there are two types of IP addresses:

  • Dynamic IP addresses: these are delivered by a DHCP server and these are changing addresses, that is, usually when a new session starts or in a certain time range the IP will be modified
  • Static IP addresses: these are a bit more delicate since as a general rule they are addresses dedicated to a particular computer that fulfills certain roles, for example, a mail, file or service server cannot change its IP since all the computers on the network point to it for access. If it were to be modified, the equipment would not have access and the services would not be able to be delivered.

 

By default Ubuntu Server 21.04 has a dynamic IP address (DHCP) but since it is a server it necessarily requires that it be static or fixed, for this reason getFastAnswer will explain the mechanism to establish a fixed IP in Ubuntu Server 21.04.

 

 

To stay up to date, remember to subscribe to our YouTube channel!   SUBSCRIBE

 

 

How to assign a static IP address in Ubuntu Server 21.04

 

Step 1

The first step is to install the network tools with which it is possible to access details of the network adapter and others, for this we execute the following:
 sudo apt install net-tools 
image

 

Step 2

After this, we validate which is the current IP address of the server, for this we will use the ifconfig command:

 

image

 

Step 3

We see that it ends in .133, to establish it as a fixed IP, we go to the / etc / netplan directory and list its content with the ls command:

 

image

 

Step 4

The file 00-installer-config-yaml contains the current configuration of the network adapter, we will use a text editor to access this:
 sudo nano 00-installer-config-yaml 
image

 

Step 5

We can see by default that the DHCP value is active (true) and there we find the ID of the network card (ens33), we will edit these values ​​as follows:
 dhcp: false addresses: [IP address / 24] gateway4: [IP address] nameservers: addresses: [IP address] 
Note
The version: 2 line should be removed.

 

 

 

image

 

It is important to preserve the spaces and to do it using the space bar but not the Tab key.
Once this is defined, the fixed IP address is 192.168.150.135, we save the changes with the Ctrl + O keys and exit the editor with the Ctrl + X keys..

 

Step 6

We load these changes into the adapter with the following command:
 sudo netplan apply 
image

 

Step 7

Then we use the ifconfig command again to validate that the IP set as fixed is the one that the device has:

 

image

 

With this process in the configuration file, it is possible to assign our static IP address in Ubuntu 21.04.

 


...