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

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

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
share|improve this answer
    
Or more simple ssh user@$(runMyScript), where the script just outputs the ip address. –  ott-- Feb 19 '13 at 14:39
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.