Glenn English wrote: > Let's see if I've got this straight... > > Debian squeeze gets the host's domain name from the first > non-comment or non-empty line of /etc/hosts?? If it likes > that line??
No. That is incorrect. Debian sets the hostname from /etc/hostname. This is done at boot time in the /etc/init.d/hostname.sh script. This is called during single user boot time from /etc/rcS.d/S??hostname.sh symlink which will have a system dependent ordering number. Once hostname is set using the sethostname(2) kernel system call man 2 sethostname then later the hostname may be queried using gethostname(2), most often by programs but also by scripts using the 'hostname' program. > Not from /etc/hostname Yes from /etc/hostname. As described above. > and not from the "kernel.domainname = " > line in /etc/sysctl.conf? ("kernel.domainname = example.com" is > that line, commented out, in my recently installed squeeze.) Definitely not. > And not from /etc/resolv.conf? Or does it rely on DNS? DNS is used for the ill conceived 'hostname -f' option. Whoever wrote that code should be stripped of any street cred. It is terrible. Original Unix systems did not have that option. I can't tell you how many times I have rescued systems that had their hostname *set* to "-f" because someone ran "hostname -f" on them. Blech. The way 'hostname -f' works is by looking for the first IP address it can find associated with the first network interface that it can find. Note that the system may have many of both. But with the first one it finds it tries to do a DNS reverse lookup of the IP address. If that name is found in DNS then it reports that name as the fully qualified domain name. That may be okay for a very large number of typical systems but it is also completely incorrect for many valid systems with more IP addresses than just one and more network interfaces than just one. Note that a perfectly valid configuration may specify the hostname as a fully qualified domain name. Many BSD systems are set that way. And BSD is the progenitor of networking. So I have that a lot of good weight. In which case if the hostname is set to a fully qualified domain name then there is no need for a DNS lookup and none is done. I always used to set hostnames to be FQDNs. It works great for single domain systems. But these days I have so many multi-domain systems that I don't do that anymore. Hosts have network interfaces. Perhaps zero of them. Perhaps one. Perhaps two. Perhaps many network interfaces. Network interfaces have IP addresses. Perhaps zero of them. Perhaps one of them. Perhaps many IP addresses. IP addresses have reverse DNS names associated with them. PTR records. They should have only one. But they might actually have many PTR records for any given IP address. When looking up an IP address it is possible that you will get multiple names returned. As you can see the above tree of information might be larger than the simple one-to-one mapping that the hacks that created 'hostname -f' planned for when they added that feature. Sometimes much larger. > I needed to change a domain name this morning on a computer > I'm working on, and I was told to do those different things > from several different websites. Setting it in /etc/hosts seems > to have worked. If all you changed was /etc/hosts then it is likely that your change is incomplete. Also, what mail transfer agent are you using? Postfix? Exim? Almost certainly one of those will need a tweak too. > Why is this trivial task so obscure? Because it pulls together information from several different and independent programs that are not related to each other except by all running on the same machine. > I must be missing something big time. hostname was coming up with > the right answer, but hostname -f kept saying "Name or service not > known". Can anyone tell me what I've got wrong? And the Debian way > of setting the domain name? (It's working now, AFAIK, but I'd like > to set it correctly...) * /etc/hostname Debian uses /etc/hostname to set the network and it is called from the /etc/init.d/hostname.sh script. Red Hat uses /etc/sysconfig/network to set the HOSTNAME=something.example.com variable called from someplace different in their startup sequence. So at the very start you need to change the appropriate file. Debian encourages using only the short name but using the FQDN as the hostname is okay. * /etc/hosts Many modern systems associate the hostname with 127.0.1.1 instead of either 127.0.0.1 or a public IP address such as 192.0.43.10. This is to solve a problem. Mobile devices typically do not always have networking enabled. Even desktops may have networking disabled for at least some of the time. If a public address such as 192.0.43.10 is used then programs such as mailer transfer agents and dns resolvers and others have errors while the network is offline. So using the public address in /etc/hosts is problematic. (Although perfectly fine for servers and desktops that are always online.) And alternatively using 127.0.0.1 is problematic because then instead of the desired name 'hostname -f' would return "localhost" or possibly "localhost.localdomain" depending upon what is in /etc/hosts. And if the host is exchanging information such as hostnames with peers you definitely want to avoid passing localhost as the hostname but want it to use a name that will map through dns back to the public IP. So in the end associating 127.0.1.1 for the local host name in /etc/hosts really makes a lot of sense. The localhost.localdomain is a hack / trick to make all of the system configuration internally consistent with a private configuration in isolation from a public network. That's great. But if you have a public name and IP address then you would use it instead. * /etc/mailname This is a Debian specific file that is intended for configuring the mail transport agent in a generic way. It can be used for either exim or postfix. * /etc/postfix/main.cf I really only know Postfix so will only talk about it. Upstream Postfix expects the hostname to be a FQDN. If it is then that fine and no further configuration is needed. But if the hostname is a short name then postfix needs to be told about it. Postfix uses it to determine the domain name. Debian has patched Postfix so that it may, if configured to do so, use /etc/mailname to set the myorigin variable. This mostly works but I find it better to simply set myhostname to the FQDN. So edit that file and set the myhostname variable to the FQDN. If you are using Exim then you will need to understand what needs to be done for Exim. * /etc/resolv.conf This file controls setting the nameservers and the domain search path. There are some other unnecessary things that can be set there too. I recommend using the 'resolvconf' package and then letting it configure /etc/resolv.conf. I also think you should run a local caching nameserver too. Assuming that you would have two lines in this file. nameserver 127.0.0.1 search example.com subdomain.example.com You might also see "0.0.0.0" used there as a alias for 127.0.0.1. The reason is an obscure bug long fixed in older systems. Now it doesn't matter. The search line does two things. The first entry on the line is used as the default domain name. And the entire list is used to search when doing a dns lookup. So setting the default domain name as the first field of the search line will set the system's current domain name, if the hostname isn't a FQDN already, in which case the value there is highest priority. Some guides will have you set "domain example.com" too. That is fine. But it is the older part of the configuration which has been replaced by the search configuration. Since the search configuration supersedes the domain configuration I always prefer to set search only and nothing else. Setting both isn't DRY (don't repeat yourself) and redundant. It is almost always better to set configuration in only one place and not multiple places. And that is pretty much all that is needed to rename a system to a new hostname. I reboot to ensure that all daemons are restarted using the new hostname. But strictly speaking that isn't needed if everything is restarted. If you have questions then ask. The above was simply an off the top of the head description and I am sure I didn't do a great job of it. Good luck! Bob
signature.asc
Description: Digital signature