Host and Domain names in Linux

DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
HI,

In Linux what is the agreed way to set up the host name?

I know in windows you set the host name, and the domain name separate and they are combined to form the FQDN

but in linux if I add a host name to the /etc/hostname file. should I just be adding the plain host name or the FQDN?

As I understand it there are 3 files to deal with

Hostname, (for local host name)
resolv.conf (for setting up DNS servers and search domains)
and hosts (for host namesthat should be resolved locally)

now I know that in the resolv.conf file you can supply a domain name varibable, so is this combined with the domain name in resolv.conf to create the FQDN or are these completely separate?

and what the command to make a change in the hostname file take affect?

Cheers

Aaron
  • If you can't explain it simply, you don't understand it well enough. Albert Einstein
  • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.

Comments

  • dynamikdynamik Banned Posts: 12,312 ■■■■■■■■■□
    You should update the hostname (FQDN) in /etc/sysconfig/network and do a service network restart. I'm not sure if that last part is necessary since doing a hostname prior shows changes.

    I'm not sure if that varies by distro or not; that's how it is on the Fedora 13 machine I'm currently using.
  • Met44Met44 Member Posts: 194
    For Debian-based systems, which don't have an /etc/sysconfig, this will work to change the hostname:

    1) Change the current hostname in /etc/hostname to the new hostname (not a FQDN)
    2) Edit /etc/hosts and add a mapping for your new name (you can comment out or remove the old mapping while you're here). The FQDN goes here as well -- but see below.
    3) Run "invoke-rc.d hostname.sh start", or "hostname <HOSTNAME>"

    You'll need to log out and log back in to make X happy -- you won't be able to start new GUI-based programs until you do. Alternatively, if you're in a shell, starting a subshell will reflect the hostname change -- within that subshell, at least.

    Regarding the FQDN, from 'man hostname':
    Technically: The FQDN is the name gethostbyname(2) 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 (usually in /etc/host.conf)
    how you can change it. Usually (if the hosts file is parsed before DNS
    or NIS) you can change it in /etc/hosts.
    All of this is right except that current versions of glibc use /etc/nsswitch.conf to determine which method(s) should be used to resolve names, and in what order -- not /etc/host.conf as this man page states. As long as your nsswitch.conf's "hosts:" line begins with "files", which was the default on my system, adding the FQDN to /etc/hosts will be enough.

    It is interesting to note that these lines from /etc/hosts are not equivalent:
    127.0.1.1       node.example.com     node
    
    vs
    127.0.1.1        node     node.example.com
    
    In the second case, when the hostname comes first, using 'hostname -f' to retrieve the FQDN prints 'node' -- not what you wanted. Some other programs using gethostbyname() will do the same. The first line will print 'node.example.com' as expected. Although it shouldn't usually matter a whole lot, to be safe, the FQDN should come before the hostname in /etc/hosts.
  • NightShade03NightShade03 Member Posts: 1,383 ■■■■■■■□□□
    dynamik wrote: »
    You should update the hostname (FQDN) in /etc/sysconfig/network and do a service network restart. I'm not sure if that last part is necessary since doing a hostname prior shows changes.

    It is necessary because even though 'hostname' shows the updated name of the computer/domain there are other scripts that won't recognize the name change until the network service is restarted.
Sign In or Register to comment.