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