Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is it possible to create a local DNS alias? For example I would like that every request to:

123.com is locally routed to 456.com (like it would be for 123.com CNAME 456.com).

I know this is not possible with /etc/hosts, but are there other ways or external tools that do the trick?

Thanks

share|improve this question

put on hold as off-topic by Jenny D, womble, MadHatter, Massimo, Nixphoe 15 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions should demonstrate reasonable business information technology management practices. Questions that relate to unsupported hardware or software platforms or unmaintained environments may not be suitable for Server Fault - see the help center." – Jenny D, MadHatter, Massimo
If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

It is possible with /etc/hosts if it is a host to host mapping. For example

    456.com IP = 1.2.3.4

In /etc/hosts, you put the following line

    1.2.3.4 123.com

It is very doable if you know all the hostname you want to map to.

Also check the following line in /etc/nsswitch.conf

    hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

Yours may have look different, but make sure hosts: is follow immediately by files. That means name/ip lookup use /etc/hosts before dns.

share|improve this answer
    
Actually the request should be forwarded to "456.com" (not to a specific IP address). Kind of: 123.com CNAME 456.com –  Mark Nov 8 '12 at 2:50
    
With the above, the effect is exactly the same. Ping, http, etc. request to 123.com will go to 456.com server. Unless 456.com is a dynamic IP. –  John Siu Nov 8 '12 at 2:55

Set up dnsmasq to give out 456.com as a CNAME for 123.com

Add cname=alias,target to the conf.

share|improve this answer
    
This won't work for OP's purpose. The dnsmasq documentation for cname states Note that this _only_ works for targets which are names from DHCP or /etc/hosts. OP wants to alias one public domain to another. –  chrispix Aug 9 '14 at 20:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.