...
Skip to main content
Print

How to Change the Hostname on Linux

You change the hostname of your Linux server with the hostnamectl set-hostname command. Then also update /etc/hosts, so the server recognises its own name. Preferably use a full name, such as server1.jedomein.nl. That is especially important if you send email from your server.

Step 1: view the current hostname

hostnamectl

Step 2: set the new hostname

hostnamectl set-hostname server1.jedomein.nl

Step 3: update /etc/hosts

Open the file and put the new name after the IP address of your server:

nano /etc/hosts
127.0.0.1      localhost
JOUW-IP        server1.jedomein.nl server1

Step 4: check the result

Log in again or open a new session and check the hostname:

hostname -f

Step 5: set the PTR record

Point the A record of the hostname to your server and set the same name as rDNS or PTR record in the client area. That way your email is less likely to end up in spam.

Related articles

Table of Contents