Setting Fully Qualified Domain Name (FQDN) in Ubuntu

In Ubuntu, open a terminal window.  Log into terminal as your username.  Enter your password when requested.  Switch to the root super user as follows:

sudo -s (enter)
input your password when requested (enter)

Change to the /etc directory as follows:

cd /etc

The ‘hostname’ file will contain your short hostname, such as mx1.

Check the current hostname by entering the hostname command, and the hostname might be something like ‘mx1’ — as follows:

hostname (enter)
mx1

Your fully qualified domain hostname should be something like mx1.yourdomain.com.  Check the current FQDN hostname with the -f option, as follows:

hostname -f (enter)
mx1

The ‘hosts’ file should be edited to insert your FQDN as well.  Using the PICO text editor, open the hosts file to be edited as follows:

pico hosts (enter)

Change the second line of the hosts file from this:
127.0.0.1    localhost
127.0.1.1     mx1

To this:
127.0.0.1    localhost
127.0.1.1     mx1.yourdomain.com     mx1

Then save the hosts file as follows:
CTRL+X
(y)es
hosts (enter)

Now check the fully qualified domain hostname, as follows:

hostname -f (enter)
mx1.yourdomain.com

Check the hostname, which should still be ‘mx1’

hostnamemx1

Escape from the terminal window:

Exit (enter)

Exit (enter)

Print Friendly, PDF & Email