Skip to content

Instantly share code, notes, and snippets.

@a-c-t-i-n-i-u-m
Created July 7, 2015 12:07
Show Gist options
  • Save a-c-t-i-n-i-u-m/bc4b1ff265b277dbf195 to your computer and use it in GitHub Desktop.
Save a-c-t-i-n-i-u-m/bc4b1ff265b277dbf195 to your computer and use it in GitHub Desktop.
Dynamic DNS support shell script for freenom.com
#!/bin/bash
# settings
# Login information of freenom.com
freenom_email="main@address"
freenom_passwd="pswd"
# Open DNS management page in your browser.
# URL vs settings:
# https://my.freenom.com/clientarea.php?managedns={freenom_domain_name}&domainid={freenom_domain_id}
freenom_domain_name="domain.name"
freenom_domain_id="000000000"
# main
# get current ip address
current_ip="$(curl -s "https://api.ipify.org/")"
if [ "${current_ip}" == "" ]; then
echo "Could not get current IP address." 1>&2
exit 1
fi
# login
cookie_file=$(mktemp)
loginResult=$(curl --compressed -k -L -c "${cookie_file}" \
-F "username=${freenom_email}" -F "password=${freenom_passwd}" \
"https://my.freenom.com/dologin.php" 2>&1)
if [ "$(echo -e "${loginResult}" | grep "/clientarea.php?incorrect=true")" != "" ]; then
echo "Login failed." 1>&2
exit 1
fi
# update
updateResult=$(curl --compressed -k -L -b "${cookie_file}" \
-F "dnsaction=modify" -F "records[0][line]=" -F "records[0][type]=A" -F "records[0][name]=" -F "records[0][ttl]=14440" -F "records[0][value]=${current_ip}" \
"https://my.freenom.com/clientarea.php?managedns=${freenom_domain_name}&domainid=${freenom_domain_id}" 2>&1)
if [ "$(echo -e "$updateResult" | grep "<li class=\"dnssuccess\">")" == "" ]; then
echo "Update failed." 1>&2
exit 1
fi
# logout
curl --compressed -k -b "${cookie_file}" "https://my.freenom.com/logout.php" > /dev/null 2>&1
# clean up
rm -f ${cookie_file}
exit 0
@oliveiraigorm
Copy link

if someone is having problems with the script, try to create a new record on the DNS MANAGEMENT page and then run the script.

@kordinox
Copy link

WOW ITS FUCKING WORKING !
TY hwiorn AND a-c-t-i-n-i-u-m

@xgusto
Copy link

xgusto commented Jun 28, 2021

I use this script for IP update and it works great

#!/bin/bash
set -u
 
# settings
# Login information of freenom.com
freenom_email="main@address"
freenom_passwd="password"
# Open DNS management page in your browser.
# URL vs settings:
#   https://my.freenom.com/clientarea.php?managedns={freenom_domain_name}&domainid={freenom_domain_id}
freenom_domain_name="domain.name"
freenom_domain_id="00000000000"
BASE_URL="https://my.freenom.com"
CAREA_URL="$BASE_URL/clientarea.php"
LOGIN_URL="$BASE_URL/dologin.php"
LOGOUT_URL="$BASE_URL/logout.php"
MANAGED_URL="$CAREA_URL?managedns=$freenom_domain_name&domainid=$freenom_domain_id"
GET_IP_URL="https://api.ipify.org/"
 
# get current ip address
current_ip="$(curl -s "$GET_IP_URL")"
 
if [ -z "$current_ip" ]; then
    echo "Could not get current IP address." 1>&2
    exit 1
fi
 
cookie_file=$(mktemp)
cleanup() {
    echo "Cleanup"
    rm -f "$cookie_file"
}
trap cleanup INT EXIT TERM
 
echo "Login"
loginResult=$(curl --compressed -k -L -c "$cookie_file" \
                   -F "username=$freenom_email" -F "password=$freenom_passwd" \
                   -e "$CAREA_URL" \
                   "$LOGIN_URL" 2>&1)
 
if [ ! -s "$cookie_file" ]; then
    echo "Login failed: empty cookie." 1>&2
    exit 1
fi
 
if echo "$loginResult" | grep -q "/clientarea.php?incorrect=true"; then
    echo "Login failed." 1>&2
    exit 1
fi
 
echo "Update $current_ip to domain($freenom_domain_name)"
updateResult=$(curl --compressed -k -L -b "$cookie_file" \
                    -e "$MANAGED_URL" \
                    -F "dnsaction=modify" \
                    -F "records[0][line]=" \
                    -F "records[0][type]=A" \
                    -F "records[0][name]=" \
                    -F "records[0][ttl]=14440" \
                    -F "records[0][value]=$current_ip" \
                    "$MANAGED_URL" 2>&1)
 
if ! echo "$updateResult" | grep -q "name=\"records\[0\]\[value\]\" value=\"$current_ip\""; then
    echo "Update failed." 1>&2
    exit 1
fi
 
echo "Logout"
curl --compressed -k -b "$cookie_file" "$LOGOUT_URL" > /dev/null 2>&1
 
exit 0

I have one account on freenom, but 3 domains. How do I get the IP address updated on all domains? I guess this won't work

freenom_domain_name="domain1.name;domain2.name;domain3.name"

@xgusto
Copy link

xgusto commented Jun 28, 2021

I tried it and it doesn't work

@xgusto
Copy link

xgusto commented Jun 30, 2021

ok thank you

@xgusto
Copy link

xgusto commented Aug 31, 2021

??

@liqingzhang
Copy link

Hi, thanks for your work!
However, I tried the script and got an error in the updateResult: There was an error in the request. Please try again in a minute.
Any idea?

@codexna
Copy link

codexna commented Apr 2, 2022

Freenom web works bad sometimes

@DaGeek247
Copy link

for everyone else who had issues with this script (for whatever reason, the freenom website is spotty at the ebst of times), you can also use a third party service instead of adjusting the dns in the freenom website specifically with a cname record. i used duckdns.org which looked like this in freenom;
SUBDOMAIN - CNAME - 14440 - subdomain.duckdns.org
and then pointing my update service to the duckdns website. doing it this way allows you to change the freenome dns once, while you can update the actual ip address how often you want using the third party dns service.

@felmur
Copy link

felmur commented Jul 14, 2023

Mmmmm... I'm testing it with my two domains on freenom.

I'm not sure that 14400 for TTL value is a good idea. I've set 300 for this value, so the update of address of *.duckdns.org will do every 5 minutes and not every 4 hours.

On freenom I had also set the main address of the domain, i.e. the one without host name and with only the domain name (so you could write "ping domain.tk" or http://domain.tk, or get an HTTPS certificate issued for the domain domani.tk).
With this change of yours, that line in the freenom config is lost, because you need to use a numeric address to configure it.

So the https certificate doesn't work either. So the https certificate for the domains doesn't work either.

Thank you, anyway.
Regards

for everyone else who had issues with this script (for whatever reason, the freenom website is spotty at the ebst of times), you can also use a third party service instead of adjusting the dns in the freenom website specifically with a cname record. i used duckdns.org which looked like this in freenom; SUBDOMAIN - CNAME - 14440 - subdomain.duckdns.org and then pointing my update service to the duckdns website. doing it this way allows you to change the freenome dns once, while you can update the actual ip address how often you want using the third party dns service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment