How to Manually Update NoIP IP - Custom Dynamic DNS Update Client (DUC)

How to Manually Update NoIP IP - Custom Dynamic DNS Update Client (DUC)

Getting Started

NoIP is a Dynamic DNS (DDNS) service that is created by Vitalwerks Internet Solutions LLC, you can learn more about it here. In this article, we are only going to focus on how to set up an automatic IP updater for your NoIP account.

As the name suggests, a Dynamic DNS (DDNS) is a method of automatically updating a name server in a Domain Name System (DNS). This means that your DNS will not always be the same but it is going to depend on the IP/name server you refer to. This can be very helpful for IoT devices or a home lab server whereas the IP that comes from the Internet Service Provider (ISP) is dynamically changed over time, by dynamically updating the IP for those devices you can then easily access it no matter what the IP is.

A DDNS service like NoIP and many more is works by mapping the Dynamic IP with a custom URL e.g (noip.ddns.net, noip.ddnsking.net, etc). The URL will then be used to access your devices, you can do pretty much anything with it e.g  (SSH, FTP, WebServer, etc).

Dynamic DNS Update Client (DUC)

As that said, because the IP is dynamically updated then a DDNS service usually comes with a custom program called Dynamic DNS Update Client (DUC) that will periodically update your IP to your NoIP account. For most cases, this program already have a cron and updates your IP periodically but there are some cons which are :

  • You will need to install it on your devices, for a case like a server, this will be a problem whereas you want to make a minimal program to be installed in your server, either for performance and maintainability.
  • Logging, no matter what the program is there always going to be a chance of error and misconfiguration. So it might be a good idea if we can see the logs of whatever is happening in your devices.

Reference :

Custom Dynamic DNS Update Client (DUC)

Aside from using DUC you also manually update your IP by executing this command :

curl -u 'noipusername:noippassword' 'https://dynupdate.no-ip.com/nic/update?hostname=hostname.noip.com'

Notes :

  • Don’t forget to change noipusername, noippassword, and hostname.noip.com based on your configuration

PHP – Custom Dynamic DNS Update Client (DUC)

There is a good gist script that you can use if you want to translate the curl command into a custom PHP script, or if you want a short version you can use this script :

echo file_get_contents(sprintf(
    "http://%s:%s@dynupdate.no-ip.com/nic/update?hostname=%s",
    "NO-IP USERNAME", // NO-IP USERNAME
    "NO-IP PASSWORD", // NO-IP PASSWORD
    "NO-IP HOSTNAME", // NO-IP HOSTNAME
));

Custom Scheduler with Cron jobs

If you haven’t read our article yet about cron jobs, probably you want to check it out here, We explain in detail how to install and set up a cron job in your system. Previously you already define a command or a script on how to dynamically update your IP but for this to be able to work you will need to do it periodically, and thankfully you don’t have to do it manually you can use a cron job to execute it. Here is the cron table that you can use to update your IP :

*/15 * * * * curl -u 'noipusername:noippassword' 'https://dynupdate.no-ip.com/nic/update?hostname=hostname.noip.com' > /dev/null 2>&1

Notes :

  • Don’t forget to change noipusername, noippassword, and hostname.noip.com based on your configuration

Custom Scheduler with Apache Airflow

For the more advanced user, you might want to consider apache airflow as your system scheduler, it already got all the features you need e.g (Integration, Logging, Monitoring, etc). Here is the DAG that you can use to update NoIP IP dynamically :

# Libraries
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import PythonOperator
import logging
import os

# NoIP Config
config = {
    'username': 'NOIP USERNAME',
    'password': 'NOIP PASSWORD',
}

# NoIP Updater
def noipUpdater(hostname):
    cmd = "curl -S -k --user-agent 'coppit docker no-ip/.1 {}' -u '{}:{}' 'https://dynupdate.no-ip.com/nic/update?hostname={}'"
    cmd = cmd.format(
        config['username'],
        config['username'],
        config['password'],
        hostname
    )
    os.system(cmd)
    logging.info('Execute:' + cmd)
    return True

# Args
default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2020,10,22),
    'email': ['youremail@mail.com'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
}

# Dag Config
dag = DAG('noip_updater',
          description='NoIP dynamic update',
          default_args=default_args,
          schedule_interval='*/15 * * * *',
          catchup=False)

# Operator
noip = DummyOperator(task_id='noip', retries=3, dag=dag)
noipUpdateHostname = PythonOperator(
    task_id='hostname',
    python_callable=noipUpdater,
    op_kwargs={"hostname": "hostname.ddns.net"},
    dag=dag
)

# Executor
noip >> noipUpdateHostname

Notes :

  • Don’t forget to change NOIP USERNAME, NOIP PASSWORD, and hostname.ddns.net based on your configuration

Conclusion

In our cases, I think it is better to update your hostname manually rather than relying on the default DUC program that comes with NoIP, with that you can control the output e.g (Logging, Integration, Monitoring, etc).

Sharing is caring

© 2022 All Rights Reserved by Artistudio

Website problem, contact us!