Linux – HOSTALIASES with Fully qualified domain names

domain-name-systemhostslinux

I am trying to point a fully qualified domain name "example.com" to an external host such as Amazon ELB "site-xxxxxx.us-west-1.elb.amazonaws.com" using HOSTALIASES environment variable and it's not working.

example.com  site-xxxxxx.us-west-1.elb.amazonaws.com

However, when I use a different alias such as "example site-xxxxxx.us-west-1.elb.amazonaws.com". The example correctly resolves.

example site-xxxxxx.us-west-1.elb.amazonaws.com

My Question is can I use a fully qualified domain name "example.com" as an alias pointing to another public domain using HOSTALIASES? If not then what are the other options?

Best Answer

It looks like you can NOT use FQDN hostnames in the first entry:

"If the name consists of a single component, that is, contains no dot, and if the environment variable HOSTALIASES is set to the name of a file, that file is searched for any string matching the input hostname."

Quoted: http://man7.org/linux/man-pages/man7/hostname.7.html

It is not described WHAT the behavior is if you use FQDN as first entry in HOSTALIASES, but there seems to be a restriction and you can only use non domain qualified hostnames