Linux Cookbook

 < Day Day Up > 

20.11.1 Problem

You're not sure how to configure a fully qualified domain name on your system. You know there are several files to edit, but you aren't quite sure what they are or what to put in them.

20.11.2 Solution

On most Linux systems, you must edit /etc/hostname and /etc/hosts. /etc/hostname sets only the system's hostname:

windbag

/etc/hosts sets the domain name:

127.0.0.1 localhost.localdomain localhost 192.168.1.5 windbag.test.net windbag

On Red Hat and Fedora, you must edit /etc/sysconfig/network instead of /etc/hostname:

HOSTNAME=windbag

Check your configurations as follows:

$ hostname windbag $ hostname fqdn windbag.test.net $ dnsdomainname test.net

You must reboot for hostname changes to take effect.

20.11.3 Discussion

/etc/sysconfig/network and /etc/hostname are read at boottime to set the hostname.

You can change the domain name anytime and have it take effect by restarting networking. On Debian, use:

# /etc/init.d/networking restart

On Red Hat and Fedora, use:

# /etc/init.d/network restart

However, this is not foolproof, because some applications will not be updated with a networking restart. A reboot is usually best.

20.11.4 See Also

  • hosts(5), hostname(1)

     < Day Day Up > 

    Категории