Hostname: Porovnání verzí
Bez shrnutí editace |
|||
(Nejsou zobrazeny 4 mezilehlé verze od stejného uživatele.) | |||
Řá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 | 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 [http://linux.derkeiler.com/Mailing-Lists/Debian/2007-09/msg00017.html toto vysvětlení]: | |||
=Linux Debian hostname a FQDN= | |||
A host is a host. One box, one name. | A host is a host. One box, one name. | ||
Řádek 13: | Řádek 14: | ||
one network and would then possibly have more than one FQDN. | one network and would then possibly have more than one FQDN. | ||
The FQDN of the system is the name that the resolver(3) | '''The FQDN of the system is the name that the resolver(3) returns for the host name.''' | ||
returns for the host name. | |||
The resolver is the code within libc that maps hostnames to IP | The resolver is the code within libc that maps hostnames to IP | ||
Řádek 21: | Řádek 21: | ||
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?== | |||
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 | ||
Řádek 71: | Řádek 71: | ||
Doug. | Doug. | ||
=Co můj problém?= | |||
Centrální DNS na UTB mělo již pro stroj s názvem backup.utb.cz záznam: | |||
backup:/proc# dig backup.utb.cz | |||
; <<>> DiG 9.6-ESV-R1 <<>> backup.utb.cz | |||
;; global options: +cmd | |||
;; Got answer: | |||
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37912 | |||
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 3 | |||
;; QUESTION SECTION: | |||
;backup.utb.cz. IN A | |||
;; ANSWER SECTION: | |||
backup.utb.cz. 86400 IN CNAME '''vega.utb.cz'''. | |||
A řešení: dopsal jsem do /etc/hosts veřejnou IP adresu a jiné doménové jméno: | |||
127.0.0.1 localhost | |||
195.113.96.248 backup.fai.utb.cz backup | |||
Jak prosté? |
Aktuální verze z 19. 2. 2011, 15:32
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í:
Linux Debian hostname a FQDN
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.
Co můj problém?
Centrální DNS na UTB mělo již pro stroj s názvem backup.utb.cz záznam:
backup:/proc# dig backup.utb.cz ; <<>> DiG 9.6-ESV-R1 <<>> backup.utb.cz ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37912 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 3 ;; QUESTION SECTION: ;backup.utb.cz. IN A ;; ANSWER SECTION: backup.utb.cz. 86400 IN CNAME vega.utb.cz.
A řešení: dopsal jsem do /etc/hosts veřejnou IP adresu a jiné doménové jméno:
127.0.0.1 localhost 195.113.96.248 backup.fai.utb.cz backup
Jak prosté?