How to Change Hostname and FQDN/Fullname on Linux

By default, the system hostname is set during the installation process, or if you are creating a virtual machine it is dynamically assigned to the instance at startup, but there are situations when you need to change it.

In this tutorial, We will learn How to Change Hostname & FQDN/Full-name on Linux

Prerequisites

  • Operating system: Linux ( Ubuntu, Debian, CentOS, CentOS Stream, RockyLinux, AlmaLinux,…)
  • User privileges: root or non-root user with root privileges
  • Recommend: Your server already configure the static IP address
  • VIM editor installed

Step 1 – Check the current Hostname & FQDN/Fullname

To check the current Hostname and FQDN/Full-name of your system execute the following command below:

### Check the current hostname

hostname

### Check the current FQDN/Full-name

hostname -f

And also check the IP address of your system:

ifconfig

Check Hostname current

From output:

  • Current Hostname: ubt22-1
  • Current FQDN/Full-name: ubt22-1
  • IP address: 192.168.1.10

Step 2 – Change Hostname & FQDN/Full-name

For this example, We will change as below:

  • New Hostname: server-1
  • New FQDN/Full-name: server-1.totatca.local

First, open the /etc/hostname file to change the Hostname of the system:

sudo vim /etc/hostname

Replace the current hostname with the new hostname:

Save and exit the file when you are done.

 Configure Hostname

Next, open the /etc/hosts file to change the FQDN/Full-name of the system:

sudo vim /etc/hosts

Add new content below:

### Synx
### IP-Server FQDN/Full-name Hostname
###
192.168.1.10 server-1.totatca.local

Save and exit the file when you are done.

Configure Fullname

Lastly, restart the systemd-hostnamed service to apply the changes:

sudo systemctl restart systemd-hostnamed

Now, verify changes with the new Hostname and FQDN/Full-name:

hostname

hostname -f

Sample output:

Verify

Don’t forget to replace New Hostname = Your-Hostname and New FQDN = Your-FQDN !!!

Thank you for reading !!!

2 thoughts on “How to Change Hostname and FQDN/Fullname on Linux

Leave a Reply

Your email address will not be published. Required fields are marked *