I am looking for the right answer to the above question.

It has been asked by jmillikin at ubuntu forums as follows:


Is it possible to create a hostname alias? Sort of like /etc/hosts, but with other hostnames rather than IP addresses. So that with some file like this, you could ping "fakehost1", and it would be re-mapped to "realhost", and then "realhost" would be resolved to an IP address.

# Real host        # Aliases
realhost           fakehost1 fakehost2 fakehost3


Somebody has answered about ssh. But not about ping, etc. My main purpose is to use it as an alias for svn server. In my case, realhost is under dynamic ip. So, "/etc/hosts" alias doesn't work. I want to access my svn server as svn://my_svnserver/my_repos instead of svn://realhost/my_repos.

Thanks in advance for any advice.

link|improve this question
feedback

5 Answers

You can setup this on your DNS server, CNAME records allow a machine to be known by more than one hostname. So add CNAME records to your DNS server like that :


fakehost1 IN CNAME realhost 
fakehost2 IN CNAME realhost 
fakehost3 IN CNAME realhost 

link|improve this answer
Thanks, I will try it tomorrow after setting up my local dns server. – user10178 Sep 14 '09 at 16:12
3  
a light-weight DNS server to try would be dnsmasq (it also serves DHCP). – sybreon Sep 14 '09 at 16:25
feedback

I often do this with environment variables. I know this only works for the command line, but it is where I am most often craving hostname aliases (I worked with several supercomputer accounts, all with long URLs). Here's an example, if you're using BASH. In ~/.bashrc:

export fakehost="long.ass.annoying.url.org"

then, in a fresh shell:

ssh christopher@$fakehost

link|improve this answer
feedback

For those who don't have an account on the forums (or don't wish to login):

if your main issue is not to ping but to ssh, you can create/edit your ~/.ssh/config adding lines like these:

Host fakehost1 Hostname realhost

Host fakehost2 Hostname realhost

Host fakehost3 Hostname realhost

link|improve this answer
feedback

The only way this can be done is if you have your own local dns server.

link|improve this answer
Yeah, now it seems the only solution. Thanks. Cannot upvote since I don't have enough reputation. – user10178 Sep 14 '09 at 16:11
If the ever-changing IP address of a DSL or dialup connection is the issue, dyndns is a better solution, IMHO. – SvenW Sep 14 '09 at 16:16
No, it's not a better solution. Once the server has a hostname that is handled by something else then all the OP needs is a CNAME for the first hostname. DYNDNS and similar rely on the host informing the dns server that it's ip has changed. – theotherreceive Sep 14 '09 at 16:37
feedback

You'll need an dyndns server that will map your current IP address to a hostname. You'll tell this server about your current IP address whenever you login, and it will update your hostname record.

(Dyndns.org is a good choice, IMHO).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown