The functionality you are looking for is implemented in glibc. You can define a custom hosts file by setting the HOSTALIASES environment variable. The names in this file will be picked up by gethostbyname (see documentation).

Example (tested on Ubuntu 13.10):

$ echo 'g' >> ~/.hosts
$ export HOSTALIASES=~/.hosts
$ wget g -O /dev/null

Some limitations:

  • HOSTALIASES only works for applications using getaddrinfo(3) or gethostbyname(3)
  • When setuid is used libc sanitizes the environment, which means that the HOSTALIASES setting is lost. ping is setuid root (because it needs to listen for ICMP packets), so HOSTALIASES will not work with ping unless you're already root before you call ping.
  • 2
Reply Report

For anything ssh based (including rsync over ssh) you can add entries to your ~/.ssh/config file


Host myhost

Then ssh myhost will connect you to

  • 4
Reply Report

Related Questions

Trending Tags