Skip to main content

Adjusting the Time-To-Live (TTL) in DynamicDNS (os-ddclient) Configuration in OPNsense

·2 mins
Table of Contents

Unfortunately, in OPNsense, it is not possible to set the TTL (Time to Live) for Dynamic DNS, which means DNS entries always have a TTL of 10800 seconds or 3 hours. This limitation undermines the purpose of Dynamic DNS, in my opinion.

To address this, I present a short script that sets the TTL to 300 seconds at system startup. The script adds the line ttl=300 \ after each line that begins with password=. We create the script using Syshook with the “Early” start option, as described in the OPNsense Documentation Autorun.

Script #

We create the script using Syshook with the “Early” start option as described in the OpnSense Documentation Autorun.

The subdirectory after rc.syshook.d indicates when the script will be executed.

  • early: means that a script is started before the system network start.

Instructions #

  1. DDClient Backup:
cp /usr/local/etc/ddclient.conf /usr/local/etc/ddclient.conf.bak
  1. Create Script File:
vi /usr/local/etc/rc.syshook.d/early/50-add_ttl.sh
  1. Insert Script Content:
#!/bin/sh

# Define the file path
DDCLIENT_CONF="/usr/local/etc/ddclient.conf"

# Use sed to insert 'ttl=300 \' followed by a newline after any line starting with 'password='
sed -i '' '/^password=/a\
ttl=300 \\\
' "$DDCLIENT_CONF"
  1. Make Script Executable:
chmod +x /usr/local/etc/rc.syshook.d/early/50-add_ttl.sh
  1. Test Script:

Manually execute the script to ensure it works:

/usr/local/etc/rc.syshook.d/early/50-add_ttl.sh
  1. Verify DDClient Config:

Check if the line ttl=300 \ has been correctly added.

vi /usr/local/etc/ddclient.conf

This is a very basic script, and I would love to hear your suggestions for improvements in the comments! 😊