Best-practices for naming hosts
(from Citrix: Install Linux Virtual Delivery Agent for Ubuntu
and He, Peng: Change the Username and Hostname on Ubuntu)
- Prerequisites
- Choose a Valid Hostname
- Change the Hostname
- Assign a Loopback Address to the Hostname
- Reboot
- Check the host name
- Optional - Disable multicast DNS
- It is best the network is connected and configured correctly before proceeding
- If you are using a Ubuntu 18.04 Live Server, make the following change in the
/etc/cloud/cloud.cfg
configuration file before setting the host name:
preserve_hostname: true
- Use
a-z,A-Z,0-9, and hyphen (-) characters only - Avoid underscores (
_), spaces, and other symbols - Do not start a host-name with a number
- Do not end a host-name with a hyphen
To ensure that the host-name of the machine is reported correctly,
change the /etc/hostname file to contain only the host-name of the machine,
i.e.: NOT the FQDN (Fully-Qualified Domain Name).
sudo nano /etc/hostnameTo ensure that the DNS domain name and FQDN of the machine are reported back correctly,
change the following line of the /etc/hosts file to include the FQDN and host-name as
the first two entries:
127.0.0.1 hostname-fqdn hostname localhost
For example:
127.0.0.1 my-server.example.com my-server localhost
Remove any other references to hostname-fqdn or hostname from other entries in the file.
Reboot the server so the changes will take effect,
for example:
sudo rebootrun:
hostnameThis command should return only the host-name of the machine and not its FQDN.
run:
hostname -fThis command returns the FQDN of the machine.
The default settings have multicast DNS (mDNS) enabled,
which can lead to inconsistent name resolution results.
To disable mDNS, edit /etc/nsswitch.conf and change the line containing:
hosts: files mdns_minimal [NOTFOUND=return] dns
To:
hosts: files dns