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, server1.cyberciti.biz 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.

ADVERTISEMENTS

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
nixcraft-wks01.sweet.home
$ 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

server1.cyberciti.biz

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 server1.cyberciti.biz

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/010-eth0.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. 
[Match]
Name=eth0
 
[Network]
DHCP=no
DNS=192.168.2.254 10.8.0.1
 
#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). 
Domains=server1.cyberciti.biz
IPv6PrivacyExtensions=false
 
## IPv4 stuff ##
Gateway=192.168.2.254
Address=192.168.2.25/24
Address=10.8.0.2/24

See systemd documentation for more information.

Testing DNS name resolution

FQDN, such as server1.cyberciti.biz, 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 server1.cyberciti.biz. Use the dig command or host command to test DNS server connectivity including FQDN:
$ dig server1.cyberciti.biz
$ host server1.cyberciti.biz

We can use the ping command to see network connectivity:
$ ping server1.cyberciti.biz

Conclusion

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
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.