Configuring a Static IP address on your Ubuntu (24.04, 24.10+) Server

0
39

To configure a static IP address on Ubuntu Server 24.10, follow these simple steps.

Step 1 : Update and Install net-tools

First, update your server and install the net-tools package, which includes essential networking utilities like ifconfig.

sudo apt update
sudo apt install net-tools

Step 2 : Check Ethernet Interfaces

Use the ifconfig -a command to list all the Ethernet interfaces available on your server. Identify the interface for which you want to set a static IP address (e.g., eth0 or enp0s3).

ifconfig -a

Step 3 : Open the Netplan Configuration File

Next, open the Netplan configuration file located at /etc/netplan/50-cloud-init.yaml. Use your preferred text editor (like nano or vim).

sudo nano /etc/netplan/50-cloud-init.yaml

Step 4 : Add Static IP Configuration

In the configuration file, modify or add a section for the Ethernet interface to configure a static IP. Here’s an example configuration:

network:
ethernets:
enp1s0:
dhcp4: no
dhcp6: no
addresses: [192.168.1.36/24]
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [ "8.8.8.8", "8.8.4.4" ]
version: 2

Step 5 : Apply the Changes

After saving the file, apply the changes to the network configuration by running the following command:

sudo netplan apply

Step 6 : Check Connectivity

To verify that the static IP has been successfully applied, ping an external server like Google:

ping google.com

Congratulations! You have successfully configured a static IP address on your Ubuntu Server 24.10.

4 Configure the Hostname

The hostname of your server should be a subdomain like “server1.example.com”. Do not use a domain name without a subdomain part, like “example.com” as the hostname, as this will cause problems later with your mail setup. First, you should check the hostname in /etc/hosts and change it when necessary. The line should be: “IP Address – space – full hostname incl. domain – space – subdomain part”. For our hostname server1.example.com, the file shall look like this:

nano /etc/hosts
-------------------------------------------------------
127.0.0.1 localhost.localdmain localhost
192.168.1.5 serv.yazilimyukle.com serv
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Then edit the /etc/hostname file:

nano /etc/hostname

It shall contain only the subdomain part, in our case:

serv

Finally, reboot the server to apply the change:

systemctl reboot

Log in again and check if the hostname is correct now with these commands:

hostname
hostname -f

The output shall be like this:

root@serv:~# hostname
serv
hostname -f
serv.yazilimyukle.com