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

2 Responses to Fedora 18 hostname resolution problems

  1. Maxo Ti says:

    sudo yum insall nss-myhostname
    should be : sudo yum ins[bold]t[/bold]all nss-myhostname

    for the nsswitch I change to :
    #hosts: files mdns4_minimal [NOTFOUND=return] dns
    hosts: files mdns4_minimal dns myhostname

    Wish I hope is the same as you but I wonder why we add that notfound before ourname and if that wont break something on dns ?
    Anyway thx man =)

  2. akanto says:

    Thanks, the typo has been fixed.

    The [NOTFOUND=return] means that if the entry what it follows (in your case it is the mdns4_minimal) provides an answer and says that the name entry is not found than beleive it and do not continue for hunting the answer. In other words if you leave the [NOTFOUND=return] there and you got the notfound response then the “myhostname” is never used.
    I don’t think that you can mess up anything by removing this entry, maybe in some rare cases you might experience a slower response since the hunting for name is not stopped after you got the not found answer from mdns4_minimal.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: