How can I re-map one hostname to another, similar to how one would re-map a hostname to an IP in /etc/hosts
?
For instance, how could I map oneheckofalongdomainname.com
to a.com
on my local machine?
Adding an entry into /etc/hosts
won't work as it maps hostnames to IP addresses, whereas I need to map one hostname to another. I'm also unable to use the target domain's IP because it's subject to change.
Assuming that oneheckofalongdomainname.com is a live website, they probably have a static IP address. Ping oneheckofalongdomainname.com to resolve the DNS entry to an IP. Take that IP, and edit /etc/hosts to map a.com to the resulting IP.
Hope this helps!
You can do so, but this would require a name server and cannot be done by an /etc/hosts entry. You need to forward a CNAME to another CNAME. If it is just temporary you might be ok with resolving the IP address for the hostname you wish to forward and put this into /etc/hosts or - if it is a web page you wish to forward, you could set up Apache accordingly. But for all other services (nfs, rsync, ftp) you will probably not be able to do it without a (dummy) name server.
See also here
Depending on what is on the other end a CNAME won't work either. If it is a website for example it could be using host headers which means it uses the domain name you request on in order to serve the correct website.
One way you could get around this would be to setup a local web server with a redirect to the long named domain. You would then point the short domain in /etc/hosts at the local address 127.0.0.1