Is it possible to alias a hostname in Linux?

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

Linux supports aliasing by setting the HOSTALIASES env variable.

echo "fakehost realhost" > /etc/host.aliases
echo "export HOSTALIASES=/etc/host.aliases" >> /etc/profile
. /etc/profile

then you can

ping fakehost

N.B. ping requires you to set this up as root, but you can do it as any user for any application that runs as that user. ping suids to root.


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 

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


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