Linux – Is it possible to alias a hostname in Linux

aliashostnamelinux

Is it possible to alias a hostname in Linux?

It has been asked by jmillikin at various 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 a Subversion server. In my case, realhost
is under a dynamic IP address. So, the "/etc/hosts" alias doesn't work. I want to
access my Subversion server as svn://my_svnserver/my_repos instead of
svn://realhost/my_repos.

Best Answer

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 real-hostname

Host fakehost2
  Hostname real-hostname2

Host fakehost3
  Hostname real-hostname3