Skip to content

Instantly share code, notes, and snippets.

@Reiikz
Forked from a-c-t-i-n-i-u-m/freenom.com.ddns.sh
Last active December 10, 2023 21:48
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reiikz/4184e68892a13b97b7a8bd2e9117fc4a to your computer and use it in GitHub Desktop.
Save Reiikz/4184e68892a13b97b7a8bd2e9117fc4a to your computer and use it in GitHub Desktop.
Dynamic DNS support shell script for freenom.com
#!/bin/bash
GET_IP_URL="https://api.ipify.org/"
UPDATE_SCRIPT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/update
LOGGER_SCRIPT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/log
source $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/config
HOST_RESULT="$(host $freenom_domain_name 80.80.80.80)"
DNS_IP=$(echo $HOST_RESULT | cut -d' ' -f 12)
CURR_IP="$(curl -s $GET_IP_URL)"
$LOGGER_SCRIPT start
$LOGGER_SCRIPT continue "Current IP: $CURR_IP :: DNS IP: $DNS_IP"
if [ $DNS_IP = $CURR_IP ]
then
$LOGGER_SCRIPT continue "No change is needed, exiting"
else
$LOGGER_SCRIPT continue "Change is needed procedeing to execute freenom update script"
$UPDATE_SCRIPT
fi
$LOGGER_SCRIPT end
#!/bin/bash
freenom_email="example@example.com"
freenom_passwd="hackme"
freenom_domain_name="example.com"
freenom_domain_id="000000000"
#!/bin/bash
FULL_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/log.log
if [ ! -e $FULL_PATH ]
then
touch $FULL_PATH
fi
case $1 in
"erase")
rm $FULL_PATH
;;
"start")
echo "Started domain address check at: $(date)" >> $FULL_PATH
;;
continue)
echo $2 >> $FULL_PATH
;;
"end")
echo "" >> $FULL_PATH
echo "" >> $FULL_PATH
echo "" >> $FULL_PATH
echo "" >> $FULL_PATH
;;
*)
echo "$1 no es una opción"
exit 1
;;
esac
#!/bin/bash
set -u
# settings
# Login information of freenom.com
# Open DNS management page in your browser.
# URL vs settings:
# https://my.freenom.com/clientarea.php?managedns={freenom_domain_name}&domainid={freenom_domain_id}
source $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/config
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/"
LOGGER_SCRIPT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )/log
# get current ip address
current_ip="$(curl -s "$GET_IP_URL")"
if [ -z "$current_ip" ]; then
$LOGGER_SCRIPT continue "Could not get current IP address."
exit 1
fi
cookie_file=$(mktemp)
cleanup() {
$LOGGER_SCRIPT continue "Cleanup"
rm -f "$cookie_file"
}
trap cleanup INT EXIT TERM
$LOGGER_SCRIPT continue "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
$LOGGER_SCRIPT continue "Login failed: empty cookie."
exit 1
fi
if echo "$loginResult" | grep -q "/clientarea.php?incorrect=true"; then
$LOGGER_SCRIPT continue "Login failed."
exit 1
fi
$LOGGER_SCRIPT continue "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
$LOGGER_SCRIPT continue "Update failed." 1>&2
exit 1
fi
$LOGGER_SCRIPT continue "Logout"
curl --compressed -k -b "$cookie_file" "$LOGOUT_URL" > /dev/null 2>&1
exit 0
@tompointexe
Copy link

Hi ,did this still work ??, thanks

@Reiikz
Copy link
Author

Reiikz commented Dec 8, 2018

Hi ,did this still work ??, thanks

yeah shure i still using it, just execute the check file and it'll work.
keep in mind i'm using it on debian 9, i don't know if there is any problem with other distributions.

@enreador
Copy link

Hi!
Do the program erase the log when it is so big?

It works perfect!
Thanks a lot!

@Reiikz
Copy link
Author

Reiikz commented Jan 16, 2019

Hi!
Do the program erase the log when it is so big?

It works perfect!
Thanks a lot!

HI thanks I'm glad someone find it useful, no, it doesn't you have to use cron to call the log script and send "erase" after the file location like: "/home/some-cool-guy/freenom-updater/log erase"

@sunlewuyou
Copy link

Excuse me, can this script run in openwrt?

@Reiikz
Copy link
Author

Reiikz commented Aug 28, 2019

I've been using this science I published it and it still working on my Debian Stretch server, It's just a very basic bash script, it should work on any linux distro that has curl really

@chechuhood
Copy link

Hola, estoy intentando cambiar la ip publica con este script y el login va bien, pero el update no me funciona, no se si porque en el freenom_domain_id="000000000" no lo cambio, porque no se que poner , mire en freenom pero ese dato no lo veo, me podriais ayudar , muchas gracias de antemano y saludos

@Reiikz
Copy link
Author

Reiikz commented Aug 31, 2019

le das a manage freenomdns y cuando se abre el panel de administración en la url esta el id, sin ese dato no va a andar.
imagen

@chechuhood
Copy link

Buenos días, gracias por la ayuda, pero algo estoy haciendo mal porque sigue sin funcionar estoy montando un servidor debian 9, pero sigue sin funcionar me el update, me podrías explicar donde instalo los tres scripts y en que orden los ejecuto para que me funcionen, agradezco mucho el tiempo que empleas en estos post y te doy las gracias por todo, llevo cuatro días con esto y estoy muy confuso con esto, muchas gracias, saludos

@Reiikz
Copy link
Author

Reiikz commented Aug 31, 2019

da igual donde los pongas, lo que no puede ser en un directorio de sistema porque los scripts generan un log en el mismo directorio en el que estan, lo que debes hacer es ponerlos todos juntos en una carpeta y ejecutar el que dice check, con crontab (yo te recomendaría que cada 5 o 10 min), el dice config tienes que reemplazarle todos los datos por los tuyos, y deberias ejecutar (ya sea con crontab o de otra manera) el que dice log, con el comando erase ("./log erase") o ya sea borrar el log tu mismo, para que este no se vuelva descomunal.
Cualquier cosa tengo discord, si quieres mas aiuda :V CrappyDragon#5188

@chechuhood
Copy link

hola lo hice y me da error
freenom
me dices el canal de discord

@chechuhood
Copy link

https://discord.gg/ajDYb7
cree este servidor

@Reiikz
Copy link
Author

Reiikz commented Aug 31, 2019

agregame CrappyDragon#5188, sacale la extension .sh a todos los archivos y ejecutalo con bash no con sh

@chechuhood
Copy link

pincha en el enlace

@chechuhood
Copy link

los cambie con extension bash y nada los cambio a txt haber y nada
frenom2

@chechuhood
Copy link

algo hago mal los permisos de ejecución creo

@chechuhood
Copy link

https://discord.gg/ZbJbgct
este enlace es la invitacion

@chechuhood
Copy link

nada le di permisos pero nada
freenom3

@chechuhood
Copy link

ya me lo cambio, muchas gracias, solo me falta el crontab

@Reiikz
Copy link
Author

Reiikz commented Sep 1, 2019

https://crontab.guru/ esta pagina es una buena ayuda para usar crontab.

@vinanrra
Copy link

https://crontab.guru/ esta pagina es una buena ayuda para usar crontab.

Buenas, perdón por molestar, pero sigue funcionando?

@Reiikz
Copy link
Author

Reiikz commented Jan 21, 2020

https://crontab.guru/ esta pagina es una buena ayuda para usar crontab.

Buenas, perdón por molestar, pero sigue funcionando?

la pagina carga y que yo sepa la manera de configurar un cronjob no ha cambiado, debería funcarte :v

@vinanrra
Copy link

@Reiikz decía el script

@Reiikz
Copy link
Author

Reiikz commented Mar 11, 2021

vinanrra lol nunca me llego una notificación de esto, pensaba hacer un mejor script basado en este, y por cierto la ultima vez que lo use fue hace unas 2 semanas, este mismo codigo que esta aca sin cambio alguno, estoy haciendo mejoras y no estoy usando esto de momento, pero hare una version mejorada usando este mismo codigo, algo con un comando para configurarlo y agregar multiples dominios, si te interesa cuando lo haga lo comento aca.

@vinanrra
Copy link

vinanrra lol nunca me llego una notificación de esto, pensaba hacer un mejor script basado en este, y por cierto la ultima vez que lo use fue hace unas 2 semanas, este mismo codigo que esta aca sin cambio alguno, estoy haciendo mejoras y no estoy usando esto de momento, pero hare una version mejorada usando este mismo codigo, algo con un comando para configurarlo y agregar multiples dominios, si te interesa cuando lo haga lo comento aca.

Sí, me sigue interesando

@Reiikz
Copy link
Author

Reiikz commented Mar 11, 2021

Genial!, ahora estoy con clases en la uni asi que no lo hare muy pronto pero estare en ello en cuanto pueda!

@babypoodle
Copy link

Hi Reiikz,
It's seems freenom changed the login with pre-auth checking that makes your update script no longer work. I got "login failed, empty cookie". Is it possible to make it works again?
Thanks

@Reiikz
Copy link
Author

Reiikz commented Dec 10, 2023

Sorry I took a week to answer, I saw the notification and then completely forgot about it.
I don't use freenom anymore and I don't plan on supporting this anymore.
I also advice you and anyone currently using or thinking about using freenom to pay for a domain name with a different registrar, you can find ones for 1 USD or you can get things like a .net for about 12 USD a year at this point in time.
The reason why I'm telling you not to use them is I've had a bad experience with freenom where I couldn't modify my dns records or even register a new domain.
Their registrar was down for months, and I was even paying them at that point, it wasn't a .tk it was a .eu.

Currently I'm using namecheap.com + noip.com for dyndns and I haven't had any problems with it so far and it's been a year.
Namecheap even allows you to set your tld to point to another hostname so I set it to the noip hostname. IE you register avocado.net then you can point your avocado.net to a noip hostname, log in with noip on the router and it completely negates the necessity for this script.
I'm just telling you this last bit because it's the alternative to this program that works for me, I don't know if it will for you, hopefully it was helpful.

@babypoodle
Copy link

Hi Reiikz,
Thanks for your feedback. and definitly will look into your suggestion see will this work for me.
Thanks once again.

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