4

When there is no FQDN explicitly specified on an Ubuntu server:

$ cat /etc/hostname
banana

$ cat /etc/hosts
127.0.0.1 localhost banana

Then where does mydomain.com come from?

$ hostname -A
banana.mydomain.com

Does this have anything to do with DNS records? (They seem to have been set to Google DNS on my virtual host.)

$ cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

DNS records say as follows:

$ nslookup myip
myip.in-addr.arpa name = banana.mydomain.com

Does this mean that hostname -A falls back to DNS records?

I have dozens of hostnames associated with the server IP address through DNS. How do I decide which of the many hostnames is used as the "official" or "primary" hostname?

2

2 Answers 2

3

The FQDN is something you don't set on the machine itself, it's the DNS resolvable name of your machine. To be precise, it is the host name returned by the getaddrinfo system call.

From the hostname manpage:

The FQDN of the system is the name that the resolver(3) returns for the host name.

The resolver is a set of functions, that query the hostname over domain name systems, according to configurations made in the files /etc/resolv.conf and /etc/nsswitch.conf or /etc/host.conf.

The former defines name servers to query for DNS lookups (in your case the Google DNS servers). The latter defines the order in which name queries should be performed. It depends on the resolver library version which of the latter two is used.

2
  • I thought from this article this was set explicitly on the server using the hosts files: askubuntu.com/questions/158957. Now my question seems to be: How do I decide which of the many hostnames pointing the IP address of my server comes up as the "primary" one when doing nslookup? Commented Mar 18, 2016 at 9:43
  • A FQDN is certainly set on the machine itself, it's just that it also needs to be set in DNS for other machines to be able to resolve it. Commented Jun 27, 2016 at 12:08
1

If it's not configured explicitly on the host, the hostname is generally received through DHCP. You can check your DHCP client's configuration and log files to see if that's the case.

3
  • I'm not proficient with DHCP. How would I go about with this? Commented Mar 18, 2016 at 9:03
  • 1
    That would depend on which distribution and DHCP client you're using. How is the networking on your computer set up? Commented Mar 18, 2016 at 9:05
  • ifconfig would probably tell you. Commented Mar 18, 2016 at 9:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.