GliderJan Varho

Aliasing Hostnames on Linux (Ubuntu)

  • alias
  • command
  • DNS
  • Firefox
  • host
  • Linux
  • ssh

When Googling for hostname aliasing on Linux, the most prominent answers were for SSH hostname aliasing, which is simple. For a general purpose solution the common answer was "install a DNS server", which is way over the top. Here's what I managed to figure out.

The objective is to have something like /etc/hosts, except like "hostname hostname2" instead of "address hostname".

My solution is to use the HOSTALIASES variable, which should point to a host alias file. In my case I did:

echo 'hostname hostname2' > .hostaliases echo 'export HOSTALIASES=$HOME/.hostaliases' >> .bashrc

Thereafter, all my bash sessions use the host alias file and apps such as ftp, wget and Firefox can all resolve the alternative hostname correctly.

Unfortunately not all tools seem to resolve hostnames in a way that supports host aliases. E.g. ping does not.