Advertisement
zilexa

1. Update IP address to domain service

Jul 16th, 2013
2,435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. Dynamic DNS
  2. By using a domain name service, you can easily connect to your Raspberry Pi when you are not home. This is actually necessary if the IP address given by your provider changes frequently. But also if you always have the same IP: simply using a pretty url to connect is nice.
  3.  
  4. Schedule this script to run every x hours, mine runs every 4 hours:
  5. crontab -e
  6. add this line at the bottom:
  7. 0 */4 * * * sudo sh /etc/ipupdate/ipupdate.sh
  8.  
  9.  
  10.  
  11. # this script will check if the current external IP address has been changed by your ISP internet provider.
  12. # If so, it will update your subdomain (for example: mypc.freedns.org). This way, you will always be able to
  13. # connect to your Raspberry when you are not at home and don't know the IP address of your home. Also handy
  14. # if your ISP internet provider keeps changing your IP.
  15.  
  16. TOKEN="UHpTbTVsZGtIODBuWldKY0IxcW1hWTlBOjEwNDg1NDY2"
  17. IFACE=eth0
  18.  
  19. if test -f /etc/ipupdate/ipupdate.conf
  20. then
  21. CacheIP=$(cat /etc/ipupdate/ipupdate.conf)
  22. fi
  23.  
  24. ExternIP=$(wget -qO- http://ipecho.net/plain)
  25.  
  26. if [ "$ExternIP" = "$CacheIP" ]
  27. then
  28. # Both IP are equal
  29. echo "Update not required..."
  30. else
  31. # The IP has change
  32. echo "Updating http://free.afraid.org with " $ExternIP
  33. wget http://freedns.afraid.org/dynamic/update.php?$TOKEN -o /dev/null -O /dev/stdout
  34. echo `date` "Updating log with IP " $ExternIP >> /var/log/dmesg
  35. fi
  36. sudo rm -f /etc/ipupdate/ipupdate.conf
  37. sudo echo $ExternIP > /etc/ipupdate/ipupdate.conf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement