How to automatically update your Go Daddy public IP address using godaddypy on Linux

Home > Search > How-to
  by

If the IP address you lease from your ISP is dynamic (meaning it can change without warning), you would need to manually update your public IP address in the systems that contain your public IP address. To prevent downtime or outages, you can map your dynamic IP address to a hostname, such as example.ddns.net. You can sign up for a free account at www.noip.com, and then map your public IP address to a hostname.

Unfortunately, some systems do not accept a hostname. For example, if you rent a domain name from Go Daddy, your domain name must be pointed to an IP address. Go Daddy's system does not allow for hostnames. In this example, the following can be done to check your current IP address at intervals and to then update the public IP address on Go Daddy if the public IP address changes.

If using a Debian distribution:

[root@server1 ~]# apt-get install python
[root@server1 ~]# apt-get install python-pip
[root@server1 ~]# pip install pif
[root@server1 ~]# pip install godaddypy

 

If using a Red Hat distribution:

[root@server1 ~]# rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
[root@server1 ~]# yum install python
[root@server1 ~]# yum install python-pip
[root@server1 ~]# pip install pif
[root@server1 ~]# pip install godaddypy

 

The package will reside at /usr/lib/pythonx.x/site-packages/godaddypy. Ensure the latest version of godaddypy was installed. The versions are listed at https://pypi.python.org/pypi/pygodaddy.

[root@server1 ~]# pip show godaddypy
. . .
Version: x.x.x

 

Request your API key:

  1. Sign into https://developer.godaddy.com/keys/
  2. Select Create Key.
  3. Make note of the key and secret. Ensure the key is a Production key and not a Test key.

 

Create a new directory for the log file.

[root@server1 ~]# mkdir /var/log/godaddy

 

Create a file named go_daddy_ip_update.py in the /etc/cron.hourly directory and a file named go_daddy.log in the /var/log/godaddy directory.

[root@server1 ~]# touch /etc/cron.hourly/go_daddy_ip_update.py
[root@server1 ~]# touch /var/log/godaddy/go_daddy.log

 

The /etc/cron.hourly/go_daddy_ip_update.py file will contain the Go Daddy key and secret.  Ensure root owns the file and only root has access to the file.

[root@server1 ~]# chown root:root /etc/cron.hourly/go_daddy_ip_update.py
[root@server1 ~]# chmod 700 /etc/cron.hourly/go_daddy_ip_update.py

 

Add the following to the go_daddy_ip_update.py file to update Go Daddy if your public IPv4 address changes.

#!/usr/bin/env python

# IMPORTS
import pif
import datetime
from godaddypy import Client, Account

# VARIABLES
my_acct = Account(api_key='PUBLIC_KEY', api_secret='SECRET_KEY')
client = Client(my_acct)
NOW = datetime.datetime.today()
PUBLIC_IPV4 = pif.get_public_ip()
DOMAIN = 'example.com'
SUB1 = client.get_records(DOMAIN, record_type='A', name='sub1')[0]

# EXECUTION
if PUBLIC_IPV4 == SUB1['data']:
        log_file = open("/var/log/godaddy/go_daddy.log", "a")
        log_file.write("\n sub1.example.com IPv4 address NOT updated ")
        log_file.write(str(NOW))
        log_file.close
else:
        client.update_record_ip(PUBLIC_IPV4, DOMAIN, name='sub1', record_type='A')
        log_file = open("/var/log/godaddy/go_daddy.log", "a")
        log_file.write("\n sub1.example.com IPv4 address updated ")
        log_file.write(str(NOW))
        log_file.close

 

Run the script, and then ensure text is written to the log file.

[root@server1 ~]# cat /var/log/godaddy/go_daddy.log
sub1.example.com IPv4 address not updated 2017-01-02 09:45:41

 

Add an entry in crontab to run the script once an hour.

1 * * * * python /etc/cron.hourly/go_daddy_ip_update.py

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments