After some hours of research, trial, and error, I figured out a more appetizing or perhaps philosophically appealing way to configure a machine name.
Please correct me if something here is not quite right.
First, do
NOT put your machine name in /etc/hosts. Leave it alone as "127.0.0.1 localhost" and don't add any aliases. (With ipv6 you'll may want "::1 localhost6" too)
Second, do
NOT put the domain in /etc/sysconfig/network where you say HOSTNAME=yourmachine. Leave that as the single word machine name, no domain.
Then to expose what's happening in your current setup try this command, and note the result (replace XX and YYY with numbers for your machine):
Code:
$ ping liXX-YYY
PING liXX-YYY.members.linode.com (AA.BB.CC.DD) 56(84) bytes of data.
Why did it magically add "members.linode.com"? That's because /etc/resolv.conf has this in it:
Code:
; generated by /sbin/dhclient-script
search members.linode.com
nameserver EE.FF.GG.HH
nameserver ...(etc)...
These values came from DHCP. I'm using the /sbin/dhclient DHCP client. Happily, it can be told to override the domain name handed to you by DHCP. You simply create the file /etc/dhclient-eth0.conf containing only:
Code:
supersede domain-name "yourdomain.com";
Next time you restart, you'll see /etc/resolv.conf has the new value
Code:
$ cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search yourdomain.com
nameserver EE.FF.GG.HH
nameserver ...(etc)...
If you run hostname, your machine name is truly the short single word "yourmachine". And if you run "hostname --fqdn", your machine name plus true domain is correct "yourmachine.yourdomain.com".
Do "ping localhost" and you goes to 127.0.0.1. Do "ping yourmachine" and it does to the IP AA.BB.CC.DD. Try "ping www" and see it also go to AA.BB.CC.DD since the domain is right and the search suffix has been correctly set.
The last thing to do is add an A record to DNS for "yourmachine", just like there's an A record for "www" and perhaps "mail".
Does Bill Gates do "ssh microsoft.com"? Probably there's a machine name in front of the domain. So adding the A record legitimizes that. Now you can finally "ssh yourmachine.yourdomain.com" and it gets to the right place from the outside.
If you add a second machine associated with your domain, this setup continues to work, rather than trying to figure out what to do to ssh or scp files to a particular machine or another. And if you are on one machine on your domain, you can "ssh othermachine" (without domain name) and you are there.