1

One would set up his hostname in /etc/hostname. I wonder why one might need to use FQDN if he has his DNS server properly configured?

Say, for example, one has following configuration of bind that servers his FQDN too.

$ORIGIN department.domain.

@ IN SOA department.domain. dnsmaster (
  1
  604800
  86400
  2419200
  604800)

  IN NS department.domain.
  IN NS ns.department.domain.

department.domain.    IN A 192.168.0.7
ns.department.domain. IN A 192.168.0.8
employee007.department.domain. IN A 192.168.12.2

Now configuration of client machine:

Have in /etc/resolv.conf

search department.domain.
nameserver 192.168.0.8

I see that it is possible to resolve FQDN of this host just issuing

dig @192.168.0.8 employee007.department.domain

Why one might need to have /etc/hostname filled with hostname or string in /etc/hosts like this:

127.0.1.1 employee007.department.domain. employee007

If DNS server alone solves the problem? One might consider dropping out /etc/hostname and unneeded stuff in /etc/hosts altogether if gets a reasonable rationale. Thanks.

  • You mean there are many disadvantages and complications of running DNS server? I will glad if write an answer clarifying your point. – Bulat M. Dec 28 '16 at 9:21
1

The file /etc/hostname is mainly used to set the hostname at bootup. Now you also could accept the hostname the DNS server pushes out. That's OK in small environments where you can keep records of each single client.
In a big network environment, where you have a lot of different subnets and clients, you normally want the client to push his hostname to the DNS server. Otherwise an admin would have to adopt the DNS entries every time the client gets a new IP address.

/etc/hosts is nowadays mainly used for the localhost lookups which normally also includes the real hostname. As muru already outlined, it might be that your DNS lookup is broken or incorrect and a service or configuration that relies on a DNS lookup of the hostname would fail.

  • Could you please elaborate on "Otherwise an admin would have to adopt the DNS entries every time the client gets a new IP address.". A bit vague for me. Thanks. – Bulat M. Dec 28 '16 at 11:47
  • 1
    When you have static DNS entries like myhost resolves to 192.168.0.12, you also have to make sure that 192.168.0.12 is assigned to myhost. When one now moves his computer to another building where a different subnet is assigned from DHCP, like 192.168.1.0/24, the computer will get e.g. 192.168.1.12 as address but the DNS entry would still resolve to 192.168.0.12. – Thomas Dec 28 '16 at 12:08
  • And what does mean " you normally want the client to push his hostname to the DNS server"? Isn't it about using dynamic updates to bind? – Bulat M. Dec 28 '16 at 12:17
  • 1
    Yes, dynamic DNS updates. Announced by the client. – Thomas Dec 28 '16 at 12:20
  • Could you give some insight why kernel needs hostname? Just curious. – Bulat M. Dec 28 '16 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.