Fedora 18 hostname resolution problems

After you have installed Fedora 18, you probably noticed that it starts up with the default localhost.localdomain hostname. In the former versions of Fedora the HOSTNAME variable that determined the hostname of your machine was stored in /etc/sysconfig/network file, but starting from from Fedora 18 it is not there anymore. Furtunately there is a command that can be used to update your hostname:

$ sudo hostnamectl set-hostname DESIRED_HOST_NAME


The hostname command can be used to check whether the hostname was successfully updated or not on your machine. However you might notice that pinging or nslookup your own hostname will not work and you gey and error for the hostname -f.

#The hostname will return your current hostname
$ hostname
DESIRED_HOST_NAME

#However it is not able to reslove it (nor does the ping or nsloookup)
$hostname -f
hostname: Name or service not known


The reason behind of this is that you probably don’t have a DNS server (or it is misconfigured). The easy solution to fix this without having a DNS server is to edit the nsswitch.conf file and add myhostname for host resolution.

Please be sure that the nss-myhostname is installed on your machine.

$ sudo yum install nss-myhostname


Edit the /etc/nsswitch.conf file and add myhostname value to hosts section.

$ sudo vi /etc/nsswitch.conf

#Note: just add the myhostname value as you see below and not your real host name!!!
hosts:      files dns myhostname


After these changes you shall be able to resolve your own hostname with hostname -f or even with nslookup.

You might think that editing of /etc/hosts file is also a good workaround, but please consider that if your machine is getting its IP address dynamically then you always need to update the /etc/hosts file, but with the above solution your hostname will be resolved always correctly even in case of variable IP addresses.

Advertisements