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

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

link|improve this question
feedback

3 Answers

up vote 1 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.
link|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
feedback

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.

link|improve this answer
That's in DNS, not in the hosts file. – mpez0 May 28 '10 at 11:05
feedback

If GNU libc is used, you can use its $HOSTALIASES feature.

From the manual page of gethostbyname(3):

DESCRIPTION

       [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...

link|improve this answer
Unfortunately not using libc. – Jonas Byström May 28 '10 at 12:06
feedback

Your Answer

 
or
required, but never shown

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