Table of Contents
- Name your server.
- Set hostname instantly
- Read the hostname file
- Find your public IP address.
- Set the FQDN
Name your server.
Give your server a name. In my example below, we’re calling the server ‘servername’. Name yours whatever you want.
vi /etc/host
servername
Set hostname instantly
Follow this up by setting the hostname instantly.
hostname servername
Read the hostname file
So we don’t have to restart the server, run the below command
hostname -F /etc/hostname
Find your public IP address.
Use curl to find out your public IP address. You may need to install curl
curl https://ipinfo.io/ip
The results will be shown, here’s an example of what you will see with the above command. Take note of this public ip address, as you will need it in the next step.
123.123.123.123
Set the FQDN
Set the Fully Qualified Domain Name through the hosts file.
Note, for this to work you need to have a domain purchased, with an A record pointing to your servers public ip address.
In our example, we own the domain example.com.au.
vi /etc/hosts
This is what your hosts file should look like.
In the top line, we’ve added our public IP, FQDN and server hostname.
123.123.123.123 servername.example.com.au servername
127.0.0.1 localhost.localdomain localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
0000::0 ip6-localnet
0000::0 ip6-mcastprefix
0000::1 ip6-allnodes
0000::2 ip6-allrouters
0000::3 ip6-allhosts
~