Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to keep a network alias - without specifying the IP address in the hosts file? For instance, I have but want abcd -> so that ping and ssh work as they normally would.

I want it to work with dynamic IP on, that's why I don't want to state the IP address explicitly.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

A slightly less convienent way is to set up aliases for both ping and ssh, for example:

alias pingfoo="ping foohost.domain.tld"

OpenSSH supports adding hostname aliases (and many more options) to ~/.ssh/config:

Host foo
    Hostname foohost.domain.tld
    # You can also add User, Port, every possible ssh(1) option.
share|improve this answer
Excellent; I can do without ping now that I think of it, 99.9 % of my use is ssh. – Jonas Byström May 28 '10 at 12:08

With dnsmasq's option --cname=<cname>,<target> you can make a CNAME that indicates that <cname> is actually <target>. Note that this works only if the DNS name of <target> is known to dnsmasq (either in hosts file or through DHCP).

If dnsmasq doesn't work, Unbound is a DNS resolver that supports also unknown targets in a similar situation.

share|improve this answer
That's in DNS, not in the hosts file. – mpez0 May 28 '10 at 11:05
@mpez0: It would still work (dnsmasq is intended to be run on one's LAN or a personal computer, as a caching DNS resolver) – grawity Oct 10 '12 at 16:08

If your OS uses GNU glibc, you can use its $HOSTALIASES feature.

From the manual page of gethostbyname(3):


       [etc etc etc] If name doesn't end in a dot and the environment variable
       HOSTALIASES is set, the alias file pointed to by HOSTALIASES will first
       be searched for name (see hostname(7) for the file format). The current
       domain and its parents are searched unless name ends in a dot.

This works with both gethostbyname() and the newer getaddrinfo(); however, it doesn't seem to affect ping at all...

share|improve this answer
Unfortunately not using libc. – Jonas Byström May 28 '10 at 12:06
It doesn't affect ping because ping has setuid set and HOSTALIASES only works with executables that don't have this flag. If you already are root it works, but not when using ping as a normal user. – Boris Jun 4 at 14:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.