Every time I reconnect to the internet, my router is given a different IP address by the upstream internet service provider. That's called dynamic hosting. But if I'm out on the internet, I cannot connect to my server unless I know the current IP. A Dynamic DNS (ddns) host simply tracks my ever-changing IP for me in an internet-accessible way.
The ddns host isn't psychic - I need a small piece of software (a ddns client) on my server that figures out whenever the IP changes, and sends that update to the ddns host.
- Register for a dynamic DNS service. Any good search engine can point you to a good free service.
- The 'ddclient' package is the server program that sends the new IP to the ddns host. Install ddclient using the command
apt-get install ddclient
. The installer will ask questions about the newly-registered dynamic dns account. - There are two ways to run ddclient - as a daemon or as an occasionally-triggered non-daemon.
- To run ddclient as a daemon (always-on), edit the file /etc/init.d/ddclient, and change the line:
run_daemon=false #from run_daemon=true #to
Restart ddclient (service ddclient restart
) to reload the new config. - To run ddclient as a non-daemon, take a look in the /usr/share/doc/ddclient/examples directory for a bunch of possible trigger mechanisms.
I chose to run ddclient whenever my server picks up a new IP address:cp /usr/share/doc/ddclient/examples/sample-etc_dhclient-exit-hooks /etc/dhcp/dhclient-exit-hooks.d/ddclient
It's not perfect for my use, but we'll fix that later.
- To run ddclient as a daemon (always-on), edit the file /etc/init.d/ddclient, and change the line:
That should be it. ddclient should automatically update the ddns host regularly (or event-driven) now.
Usage: If you're out on the internet and need to know your server's IP, just look it up:
dig +short myaccount.dyndns.org # Elsewhere on the internet nslookup myaccount.dyndns.org ns.dyndns.org # Another way from the internet http://www.dnscog.com/dig/myaccount.dyndns.org/ # As a web pageOr have the service look it up for you by simply using the domain name:
ssh myaccount.dyndns.org
Kingbaron: Sometimes my server is also an internet-facing router, sometimes it's just a LAN server. I don't want it erroneously feeding LAN addresses to the ddns. Happily, the dhclient-exit-hook script thought of that already. If the new IP address is in the normal LAN range, ddclient ignores it.
1 comment:
Very helpful! Thank you!
Post a Comment