Hostname: Porovnání verzí

Z Wiki UnArt Slavičín
Skočit na navigaciSkočit na vyhledávání
Bez shrnutí editace
Bez shrnutí editace
Řádek 1: Řádek 1:
Jak Linux Debian nastavuje hostname?
Jak Linux Debian nastavuje hostname, resp. FQDN (fully qualified domain name)?


Myslíte, že hostname stačí napsat do /etc/hostname ?
Myslíte, že hostname stačí napsat do /etc/hostname ?


Chyba lávky. Je to mnohem složitější.
Chyba lávky. Je to složitější.
Poté, co jsem jeden stroj s Debian Lenny pojmenoval "backup", připojil k UTB síti s DHCP a následně celé dopoledne řešil, proč si některé démony myslí, že s hostname je "vega" nebo "vega.utb.cz", podařilo se mi najít [http://linux.derkeiler.com/Mailing-Lists/Debian/2007-09/msg00017.html toto vysvětlení]:
 
Poté, co jsem jeden stroj s Debian Lenny pojmenoval "backup", připojil na UTB k síti s DHCP a následně celé dopoledne řešil, proč si některé démony myslí, že s hostname je "vega" nebo "vega.utb.cz", podařilo se mi najít [http://linux.derkeiler.com/Mailing-Lists/Debian/2007-09/msg00017.html toto vysvětlení]:


A host is a host. One box, one name.
A host is a host. One box, one name.
Řádek 21: Řádek 22:
With libc6 (or was it 5), the resolver is configured in /etc/nsswitch.conf. That's Name Service Switch, and has many options.
With libc6 (or was it 5), the resolver is configured in /etc/nsswitch.conf. That's Name Service Switch, and has many options.


'''So what is the correct way of setting the hostname and the FQDN?'''
===So what is the correct way of setting the hostname and the FQDN?===


Ok. So you've named the computer. You put this hostname (the name up
Ok. So you've named the computer. You put this hostname (the name up

Verze z 20. 7. 2010, 11:04

Jak Linux Debian nastavuje hostname, resp. FQDN (fully qualified domain name)?

Myslíte, že hostname stačí napsat do /etc/hostname ?

Chyba lávky. Je to složitější.

Poté, co jsem jeden stroj s Debian Lenny pojmenoval "backup", připojil na UTB k síti s DHCP a následně celé dopoledne řešil, proč si některé démony myslí, že s hostname je "vega" nebo "vega.utb.cz", podařilo se mi najít toto vysvětlení:

A host is a host. One box, one name.

A network is a network. One network, one name.

Most hosts are only on one network, however, some hosts are on more than one network and would then possibly have more than one FQDN.

The FQDN of the system is the name that the resolver(3) returns for the host name.

The resolver is the code within libc that maps hostnames to IP addresses.

With libc6 (or was it 5), the resolver is configured in /etc/nsswitch.conf. That's Name Service Switch, and has many options.

So what is the correct way of setting the hostname and the FQDN?

Ok. So you've named the computer. You put this hostname (the name up to but not including the network name(s) to which the box is attached), in /etc/hostname.

So now /bin/hostname will give you your hostname. How does

hostname -f

give the FQDN?

It asks the resover what the dommain name is. The resolver consults the /etc/nsswitch.conf file so see where to look. On debian, it tells it that for hosts it should consult files and if it doesn't get an answer, to consult the DNS via a DNS query to the nameserver that is configured with files, in this case /etc/resolv.conf.

So, the first place it will look is in /etc/hosts. It will see, e.g.

192.168.1.5 rocky.hooton rocky

It will see a FQDN and return rocky.hooton to my hostname -f request.

Now, what if you didn't have this host in /etc/hosts? What if the only line was:

127.0.0.1 localhost

?

It would then look in /etc/resolve.conf and see:

nameserver 192.168.1.1

It will then issue a DNS request to 192.168.1.1 asking what the FQDN is for rocky.

It will be told rocky.hooton.

---

So to finally answer your question, you configure your FQDN wherever you want names resovled. If you want it in files on the box itself, then it goes in /etc/hosts. If you run your own name server like I do (I run dnsmasq for simplicity) then you only have to record the information in one place.

I hope this long-winded answer is of some help. For more clarity, I'd suggest __UNIX_System_Administration_Handbook__ by Evi Nemeth, et. al.

Doug.