Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a domain setup to point to my LAN's external IP using dynamic DNS, because my external IP address changes frequently. However, I want to create an alias to this host, so I can access it with home. So I appended the following to my /etc/hosts:

domain.com home

However, it doesn’t seem to like the domain name. If I change it to an IP:

0.0.0.0 home

… then it works, but of course this defeats the purpose of dynamic DNS!

Is this possible?

share|improve this question
    
Why does your external IP change frequently? Is this your provider internet-IP that gets assigned to you from a pool? –  Nils Dec 19 '12 at 20:39
    
Yes, it is. I don't know why, my ISP just seem to change it sometimes! –  Oliver Joseph Ash Dec 19 '12 at 20:43

2 Answers 2

up vote 5 down vote accepted

The file /etc/hosts contains IP addresses and hostnames only. You cannot alias the string "home" in the way that you want by this method.

If you were running your own DNS server you'd be able to add a CNAME record to make "home.example.com" an alias for "domain.com", but otherwise you're out of luck.

The best thing you could do is use the same DNS client to update a fully-qualified name.

share|improve this answer
    
Thanks for clearing that up! –  Oliver Joseph Ash Dec 19 '12 at 20:49

This looks to me as if you should register to DYNDNS or something like that.

If you really want to use /etc/hosts you have to monitor your IP. As soon as it changes:

  • Change the entry in /etc/hosts
  • Reload the hosts-cache
  • Keep monitoring

Update If you are using dhcpcd you can use the "-c" option for a script that changes your /etc/hosts-entry an then reloads the host-cache.

This depends on the capabilities of your dhcp-client.

share|improve this answer
    
I’ve registered to no-ip, which provides a similar service to DYNDNS I believe (I couldn't see to sign up on the DYNDNS homepage!) –  Oliver Joseph Ash Dec 19 '12 at 20:47
1  
@OliverJosephAsh so you can use the name you registered on no-ip! I do not see your reason to do this via /etc/hosts. –  Nils Dec 19 '12 at 20:58
    
Quite simply it is because I’m lazy! Typing home is quite a few keystrokes less than oliverjash.no-ip.org –  Oliver Joseph Ash Dec 19 '12 at 22:48
    
have you thought of aliases within you shell, or setting your domain search list in /etc/resolv.conf? –  mdpc Dec 20 '12 at 3:17
    
@mdpc I did not ask the question. But an alias within the shell will propably not work within the browser. He could use a local proxy with a rewrite-rule, though... –  Nils Dec 20 '12 at 21:46

Your Answer

 
discard

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.