Dynamic DNS Print

  • RaspberryPi, Dynamic DNS, PHP
  • 260

We have created the following PHP script for easily running Dynamic DNS on your cPanel account or free DNS account. Simply run the php script on any linux system that has a dynamic public IP. Something like a RaspberryPi would work great.

https://ipxup.com/dyndns.phps (save as .php)

The script has five variables that need to be adjusted.

#1 The url of the cpanel server, you can usually use your domain here.
$dyndnsCpanel = 'https://server.ipxcore.com:2083';

#2 username and password used to login to cpanel
$dyndnsCpanelUser = 'yourcpanelusername';
$dyndnsCpanelPass = 'youcpanelpassword';

#3 the main domain name of the account on cpanel
$dyndnsDomain = 'yourdomain.com';

#4 the record that you would like to update
$hostname = "home.yourdomain.com";

Next you will need to set a cronjob to run the php script on a timed interval. To do this, you will need to note where php is located on your system with the "whereis" command.

root@pi:~# whereis php
php: /usr/bin/php /usr/share/php /usr/share/man/man1/php.1.gz

Also note where the dyndns.php is saved, then create a cronjob  with "crontab -e" as follows:

*/5 * * * * /usr/bin/php /root/dyndns.php 2>&1

The above cron entry will run every five minutes (*/5 * * * *)/usr/bin/php and /root/dyndns.php need to be changed based on your own system locations.

Lastly test to see if the cronjob works.

root@pi:~# /usr/bin/php /root/dyndns.php

Make sure you use the right cPanel username and password. Otherwise you could get yourself blocked. If this happens, you can unblock yourself with these instructions.

Was this answer helpful?

« Back