8

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.

Phillip B Oldham
  • 1,016
  • 5
  • 15
  • 24

3 Answers3

2

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!

spadge67
  • 43
  • 5
1

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

Stephan
  • 417
  • 1
  • 5
  • 13
1

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

JamesRyan
  • 8,138
  • 2
  • 24
  • 36