In this tutorial you will learn how to set / change server's Fully Qualified Domain Name (FQDN) on Ubuntu Ubuntu 20.04 Focal Fossa Linux server or desktop

In this tutorial you will learn:
  • How to change or set FQDN via /etc/hosts
Retrieve FQDN ( domain name ) on Ubuntu 20.04 Focal Fossa Linux
Retrieve FQDN ( domain name ) on Ubuntu 20.04 Focal Fossa Linux

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

How to change FQDN ( domain name ) on Ubuntu 20.04 step by step instructions

HOSTNAME(1) - MANUAL PAGE (excerpt)
The FQDN (Fully Qualified Domain Name) of the system is the name that the resolver(3) returns for the host name, such as, ursula.example.com. It is usually the hostname followed by the DNS domain name (the part after the first dot). You can check the FQDN using hostname --fqdn or the domain name using dnsdomainname.

You cannot change the FQDN with hostname or dnsdomainname.

The recommended method of setting the FQDN is to make the hostname server1 as retrieved in the previous step be an alias for the fully qualified name using /etc/hosts, DNS, or NIS.
  1. First, check your current hostname:
    $ hostname
    server1
    $ hostname --fqdn
    server1 
    
    At this point both, the hostname and FQDN is set to server1.

    Optionally, change your hostname before proceeding to the next step.
  2. As an example now we will define hostname server1 as retrieved in the previous step to be an alias for the fully qualified domain name www.linuxconfig.org on the IP address 1.2.3.4. To do so edit the /etc/hosts file by using the sudoedit /etc/hosts command and add the following line:
    1.2.3.4 www.linuxconfig.org server1
    
    NOTE
    The order is important! The FQDN www.linuxconfig.orgmust precede the hostname server1.

  3. SUBSCRIBE TO NEWSLETTER
    Subscribe to Linux Career NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


  4. All done and no reboot required. Check your FQDN by using the hostname command:
    $ hostname --fqdn
    www.linuxconfig.org
    
    Alternatively, also check your domain name:
    $ dnsdomainname 
    linuxconfig.org
    
FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.