As I read in man page, it is recommended to put hostname(without domain name) to /etc/hostname. For example, host instead of host.domainsub.domaintld. But, as I know, some software relies on having FQDN in /etc/hostname.

What should one specify in /etc/hostname on Debian/Ubuntu machines?

If not FQDN, where FQDN should be specified instead?

I know, question is a bit old, but didn't found clear answer. Some people say hostname, some - FQDN. Thanks.

  • 1
    Where are you finding people that are saying that you put the FQDN in the /etc/hostname file? That file is only for the hostname of the system.
    – Terrance
    Dec 21, 2016 at 17:47
  • When reading material about it on the internet met somewhere. And where one should specify his FQDN?
    – anon
    Dec 22, 2016 at 6:02
  • @Terrance, actually I want to get answers from experienced people in the field so they show how to do it "right" from the beginning. Write as an answer. And what to do in distributions that don't have /etc/hostname?
    – anon
    Dec 22, 2016 at 11:14

3 Answers 3


Revised Answer:

The host itself does not handle the actual FQDN. That is handled by the DNS. FQDN (Fully Qualified Domain Name) is handled by DNS translating names into IP addresses. Using the /etc/hosts file, you are essentially overriding the DNS server. The computer looks to the /etc/hosts file first to see if an entry is defined for a hostname to IP address. The entries in the /etc/hosts looks like the following: localhost terrance-ubuntu.lan terrance-ubuntu

These entries are not distro specific. All OSes use the same format for these lines. Just the location of the hosts file changes. Linux, typically it is located in the /etc/ folder, where in Windows it is typically located in C:\Windows\System32\drivers\etc\ folder.

Breaking that line up, you can see that I am assigning both terrance-ubuntu.lan, which is my FQDN itself to override DNS so that applications know not to leave my computer, and terrance-ubuntu, which is the hostname, again so that applications know not to leave my computer or (localhost). Assigning my hostname of my system to has no effect on the rest of the computers finding my host on the network. If DNS is working properly, they will see my hostname as The reason for using is for my applications to find my system quicker since it will know that my system is not out somewhere else on my network. My actual hostname with the .lan being my FQDN, the .lan is actually my Domain that I setup via my router which is also another DNS server on my network.

Now, let's say that the DNS services on the local network are not assigning hostnames or FQDNs to IP addresses, but yet you know what the IP address of the host on the local network is. You would then assign that host in your /etc/hosts file so that you don't need to type in the IP address of the host every time you want to access it. The host might be a tool server, printer, or some other network connected system. Add the entry like you would normally to the /etc/hosts file.

I am going to use my network connected printer for example. It has a static IP of I don't know the name of it though. For this, I want to call it hp_printer. I will ping the IP and the hostname for it, then add to /etc/hosts.

terrance@terrance-ubuntu:~$ ping -c 2
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=255 time=0.326 ms
64 bytes from icmp_seq=2 ttl=255 time=0.334 ms

terrance@terrance-ubuntu:~$ ping -c 2 hp_printer
ping: unknown host hp_printer

terrance@terrance-ubuntu:~$ sudo vi /etc/hosts hp_printer.lan hp_printer

terrance@terrance-ubuntu:~$ ping -c 2 hp_printer
PING hp_printer.lan ( 56(84) bytes of data.
64 bytes from hp_printer.lan ( icmp_seq=1 ttl=255 time=0.334 ms
64 bytes from hp_printer.lan ( icmp_seq=2 ttl=255 time=0.303 ms

Now, I can also access the webpage for my printer setup at the name I gave it instead of the IP address which could be easier to remember:

enter image description here

Your /etc/resolv.conf file is also used by DNS to help find hostnames. It is the configuration file for the resolver. It provides the search domain so that you don't have to specify your FQDN all the time when you're looking for a host. It also supplies the IP address for the DNS or nameserver of your local network. The search line below shows the name lan which is my domain name.

terrance@terrance-ubuntu:~$ cat /etc/resolv.conf 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
search lan

Hopefully this helps give a better understanding of how DNS and FQDNs work.

  • why do you map FQDN in /etc/hosts to
    – anon
    Dec 23, 2016 at 13:42
  • 1
    @BulatM. Please see my revised answer.
    – Terrance
    Dec 23, 2016 at 15:08
  • 1
    @BulatM. Click on the links in my answer, and they take you to more information about things. Like en.wikipedia.org/wiki/Resolv.conf gives much more information. I am here to help, not to teach you. I don't get paid, as this is all volunteer, so please do some studying of your own.
    – Terrance
    Dec 24, 2016 at 18:13
  • 1
    @Terrance Apologies if you felt I was talking down to you, that wasn't my intent. I've been in computers just as long. I've encountered enough people who get confused over this particular issue including sys-admins with more like 30 years experience. Oct 27, 2021 at 10:02
  • 1
    @aderchox There isn't a need, but this might help. serverfault.com/questions/363095/…
    – Terrance
    Nov 20, 2021 at 23:51

In the /etc/hostname file you use only the hostname. The FQDN you can set on: /etc/hosts that might look like:        thishost.mydomain.org    thishost

According to manual of the hosts file.


  • 1
    FIX: Thanks, however it would be to know about pros and cons of specify/not specifying of FQDN in /etc/hostname. I know about your solution: it is a stub for programs that want to get FQDN resolved to something(does not matter to what address) to work.
    – anon
    Dec 21, 2016 at 17:35

The manpage of hostname(1) discusses this (the paragraph in bold is emphasised by me):

   The  FQDN  (Fully Qualified Domain Name) of the system is the name that
   the resolver(3) returns for the host name, such as, ursula.example.com.
   It  is  usually  the hostname followed by the DNS domain name (the part
   after the first dot).  You can check the FQDN using hostname --fqdn  or
   the domain name using dnsdomainname.

   You cannot change the FQDN with hostname or dnsdomainname.

   The  recommended  method of setting the FQDN is to make the hostname be
   an alias for the fully qualified name using /etc/hosts,  DNS,  or  NIS.
   For  example,  if  the  hostname was "ursula", one might have a line in
   /etc/hosts which reads

    ursula.example.com ursula

   Technically: The FQDN is the name getaddrinfo(3) returns for  the  host
   name returned by gethostname(2).  The DNS domain name is the part after
   the first dot.

   Therefore it depends on the configuration of the resolver  (usually  in
   /etc/host.conf) how you can change it. Usually the hosts file is parsed
   before DNS or NIS,  so  it  is  most  common  to  change  the  FQDN  in

And if you give a FQDN as the hostname during installation, it writes only the fist component to /etc/hostname and keeps the FQDN in /etc/hosts.

So, in this case, just let the installer do what it does.

  • Is it(inclusion of ursula.example.com ursula in /etc/hosts) Debian\Ubuntu specific or could be applied equally well to any other distr?
    – anon
    Dec 23, 2016 at 13:43
  • 1
    Dunno about other distros. You can do the same in Arch and Cent OS, though. Questions about other distros should be asked at Unix & Linux.
    – muru
    Dec 23, 2016 at 13:56
  • The net-snmpd package takes the value from /etc/hostname as default for the sysName oid. So you end up having an snmpd propagating "ursula" as sysName, which then gets you into trouble with systems that rely on the sysName setting, like LibreNMS, when you happen to have a bunch of servers that are sharing the hostname part (like srv1.customer.com, srv1.othercustomer.com, srv1.thirdcustomer.com and so on), because LibreNMS will only add one of them and refuse the other due to "duplicate sysName".
    – frank42
    May 21, 2021 at 9:35
  • "And if you give a FQDN as the hostname during installation" FWIW, Ubuntu Server 22.04 installer doesn't let me specify the FQDN in its basic UI (the "Your server's name" field doesn't accept dots), so I had to do it manually: sudo sed -i 's@[email protected] myhost@' /etc/hosts
    – Nickolay
    Jul 14, 2022 at 15:19

You must log in to answer this question.