How to set/change FQDN on Ubuntu 20.04 Linux

How do I set/change my server’s Fully Qualified Domain Name (FQDN) on Ubuntu 20.04 LTS “Focal Fossa” Linux?

An FQDN is an acronym for a fully qualified domain name. Also known as an absolute domain name. For example, is FQDN. It is part of DNS (Domain name System). This page explains how to view, set/change FQDN on an Ubuntu Linux 20.04 LTS server or desktop system.

Viewing hostname including FQDN

The hostname command and hostnamectl command shows the Ubuntu system’s fully qualified host name including FQDN. Open the terminal application and then type:
$ hostname
$ hostnamectl status

   Static hostname: nixcraft-wks01.sweet.home
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 7e163c7b219a4bed8968e482b3c3fa30
           Boot ID: 84e3a955a6a14bd8975f44c6bd8b681c
  Operating System: Ubuntu 20.04.1 LTS
            Kernel: Linux 5.4.0-42-generic
      Architecture: x86-64

The /etc/hostname file

A static hostname for the Ubuntu box is always set in the /etc/hostname file. Use the cat command to display it:
$ cat /etc/hostname

Of course, we can use a text editor to modify the file. For example:
$ sudo vim /etc/hostname
## OR ##
$ sudo nano /etc/hostname

Setting or changing FAQDN on Ubuntu 20.04 LTS per interface (advanced config)

However, the recommended way is to use the hostnamectl command to edit/etc/hostname file. The syntax is:
$ sudo hostnamectl set-hostname only-host
$ hostnamectl set-hostname host.your-fqdn-here
$ hostnamectl set-hostname

Verify it:
$ hostnamectl status
# Show the Ubuntu system's DNS domain name #
$ dnsdomainname

How to set change FQDN on Ubuntu 20.04 Linux
Please note that if /etc/hostname file does not exist on Ubuntu Linux, the host name is set by a reverse DNS query when the network interface gets an IP address assigned.

Set or change FQDN ( domain name ) on Ubuntu 20.04 Focal Fossa Linux

You can set or change the system FQDN using network interface config file too. For example, here is config for my eth0 interface:
# cat /etc/systemd/network/

#The network file contains a [Match] section, which determines if a given network file may be applied 
#to a given device; and a [Network] section specifying how the device should be configured. 
#The Domains= defines a whitespace-separated list of domains which should be resolved using 
#the DNS servers on eth0. Each item in the list should be a domain name. The domains with the 
#prefix are called "routing-only domains". The domains without the prefix are called "search domains" 
#and are first used as search suffixes for extending single-label hostnames (hostnames containing no dots) 
#to become fully qualified domain names (FQDNs).
## IPv4 stuff ##

See systemd documentation for more information.

Testing DNS name resolution

FQDN, such as, will only work if you update your DNS and point out to your Ubuntu server’s IPv4/IPv6. In other words, set up DNS A and AAAA entries for Use the dig command or host command to test DNS server connectivity including FQDN:
$ dig
$ host

We can use the ping command to see network connectivity:
$ ping


We use the hostnamectl command to change the host name and update /etc/hostname file on Ubuntu Linux 20.04 LTS box.

This entry is 18 of 19 in the Linux/Unix Set hostname Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Change Hostname (computer name)
  2. Debian Linux: Change Hostname / Computer Name Permanently
  3. Linux change my hostname / computer system name
  4. Linux Change Hostname
  5. RHEL / Centos Linux 7: Change and Set Hostname Command
  6. OpenBSD Change Hostname
  7. CentOS Linux 5/6 Change Hostname Command
  8. Linux setting hostname and domain name of my server
  9. FreeBSD Change Hostname without reboot
  10. SuSe Linux Change Hostname without reboot
  11. How to set the hostname on Fedora Linux
  12. Ubuntu 18.04 LTS change hostname permanently
  13. Ubuntu set hostname permanently (computer name) command
  14. OpenSUSE Linux set hostname permanently (computer name) command
  15. RHEL 8 Linux set hostname permanently (computer name) command
  16. CentOS 8 Linux set hostname permanently (computer name) command
  17. Ubuntu 20.04 LTS set hostname permanently (computer name) command
  18. Set / Change FQDN on Ubuntu 20.04 LTS
  19. Alpine Linux - Setting system hostname

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum