4

I have an server that has a dynamic IP address and is accessible over SSH. On the server, a script uploads a text file containing the server's public IP address to a web location whenever that address changes.

How can I connect from to the server from some other client? This would be similar to DynDNS, but using the web to obtain the IP address.

3

If you don't have access to or can't use a DynDNS service, create an alias in ~/.ssh/config and edit the IP address whenever it changes. Put these two lines (optionally followed by other settings for that host alias) in ~/.ssh/config:

Host nickname
HostName 1.2.3.4
CheckHostIP no
HostKeyAlias nickname

Run this script whenever the address may have changed.

#!/bin/sh
url='http://example.com/my-server-ip.txt'
ip_address=$(wget -q "$url")
case $ip_address in
  '') :;; # empty file or connection error
  *[!.:0-9A-Fa-f]*) # bad character
    echo 1>&2 "The content at $url doesn't look like an IP address!"; exit 1;;
  *) # this looks like an IP address
    ed -s ~/.ssh/config <<EOF
/^ *Host  *nickname
/^ *HostName 
s/e .*/e $ip_address/
w
q
EOF
esac
1
  • Or more simple ssh user@$(runMyScript), where the script just outputs the ip address. – ott-- Feb 19 '13 at 14:39
3

You can use the nsupdate command to do a Dynamic DNS update to the remote server. I'm assuming, but it's not clear, that you're comparing the (free) commercial service offered by DynDNS against "something else". It turns out that "dynamic DNS" is actually a standardized protocol for updating records. You don't need to move around a .txt file with a record in it (though that could work too). You can instead use nsupdate to update an entry in a live zone instead.

0

Why don't you simply update your DNS entries with that IP?

I'm doing this using ssh-dyndns. See the description in my blog entry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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