tomclegg.net |
Dynamic IP Posted April 25, 2004 Create a DNS group. # pw groupadd DNS -g 995 Make sure the tinydns data directory is writeable by the DNS group. # chown root:DNS /service/tinydns/root # chmod g+rwx,g+s /service/tinydns/root Split the DNS data into two files, # cd /service/tinydns/root # mv -i data root.data # touch dynip.data Create a Makefile to concatenate the data.cdb: data /usr/local/bin/tinydns-data chmod g+w data.cdb data: *.data echo >data.tmp '#' echo >>data.tmp '# DO NOT EDIT THIS FILE' echo >>data.tmp '#' cat *.data >>data.tmp mv data.tmp data Create a dynip user and make it a member of the DNS group. # pw useradd dynip -m -G DNS -s /usr/local/bin/bash As the dynip user, create bin/ and .ssh/ folders. # su -l dynip $ mkdir .ssh $ chmod 700 .ssh $ mkdir bin
#!/bin/sh exec </dev/null if [ "$HOST" = "" ] then echo "dynip register: fatal: no host name" exit 1 fi ip=`echo $SSH_CLIENT | cut -d' ' -f1 | sed -e 's,::ffff:,,'` if [ "$ip" = "" ] then echo "dynip register: fatal: no ip address" exit 1 fi echo $ip > $HOME/data/$HOST $HOME/bin/update >/dev/null 2>/dev/null date echo "$HOST -> $ip"
#!/bin/sh domain1=example.com domain2=example.net tinydnsroot=/service/tinydns/root exec </dev/null TMPFILE=`mktemp /tmp/data.dyn.XXX` egrep -v '.\.'"$domain1"':' $tinydnsroot/dynip.data \ | egrep -v '.\.'"$domain2"':' > $TMPFILE cd $HOME/data for host in [a-z]* do ip=`cat $host` echo >>$TMPFILE "=$host.$domain1:$ip:5" echo >>$TMPFILE "=$host.$domain2:$ip:5" done \ && chown dynip:DNS $TMPFILE \ && mv $TMPFILE $tinydnsroot/dynip.data \ && cd $tinydnsroot \ && chmod a+r dynip.data \ && make Make sure bin/update and bin/register are executable. $ chmod +x bin/update bin/register Client setupCreate an SSH key with no passphrase. # ssh-keygen -t dsa -f /root/.ssh/id_dsa -N '' Arrange for the client to connect to the server periodically (or, if possible, whenever its IP address changes). If you use daemontools, your #!/bin/sh while : do ssh -2 -i /root/.ssh/id_dsa -n dynip@server.ip.addr sleep 300 done For an SSH2 client, add a line like this to /home/dynip/.ssh/authorized_keys on the server.
For an SSH1 client, add a line like this to /home/dynip/.ssh/authorized_keys on the server.
Execute your su-2.05b# cd /var/service/dynip su-2.05b# ./run The authenticity of host '204.244.102.57 (204.244.102.57)' can't be established. DSA key fingerprint is c8:b1:de:4d:f6:b3:0d:9d:1d:ed:f9:46:0a:66:d2:da. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '204.244.102.57' (DSA) to the list of known hosts. Sun Nov 14 21:35:28 PST 2004 mal -> 24.71.13.118 Connection to 204.244.102.57 closed. ^C |