Hostname: Porovnání verzí

Z Wiki UnArt Slavičín
Skočit na navigaciSkočit na vyhledávání
(Nová stránka: Jak Linux Debian nastavuje hostname? Myslíte, že hostname stačí napsat do /etc/hostname ? Chyba lávky. Je to mnohem složitější. Poté, co jsem jeden stroj s Debian Lenny p...)
 
Bez shrnutí editace
Řádek 38: Řádek 38:
So, the first place it will look is in /etc/hosts. It will see, e.g.
So, the first place it will look is in /etc/hosts. It will see, e.g.


192.168.1.5 rocky.hooton rocky
192.168.1.5 rocky.hooton rocky


It will see a FQDN and return rocky.hooton to my hostname -f request.
It will see a FQDN and return rocky.hooton to my hostname -f request.
Řádek 45: Řádek 45:
line was:
line was:


127.0.0.1 localhost
127.0.0.1 localhost


?
?
Řádek 51: Řádek 51:
It would then look in /etc/resolve.conf and see:
It would then look in /etc/resolve.conf and see:


nameserver 192.168.1.1
nameserver 192.168.1.1


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

Verze z 20. 7. 2010, 11:02

Jak Linux Debian nastavuje hostname?

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

Chyba lávky. Je to mnohem 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 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.