I already have ddclient
3.8.2 working with OpenDNS. I'm running it on my laptop. I may travel with my laptop, and so I don't want to update the IP if I'm not home.
How do I restrict ddclient
to update the IP only if I'm on my home network? This selectively has to be automated.
There are at least two ways to define whether I'm on my home network:
Assume I use wifi, and that my home wifi SSID name is
home-ssid
. Assume I can configure this name.Alternatively, assume the MAC address of my router is
F7:C1:A2:54:4F:71
(fake). Assume I can configure this value. This approach is intended to work for both wifi and/or wired.
If nothing else, a hack could be to use use=cmd
instead of use=web
in /etc/ddclient.conf
. I can then potentially have the external command intelligently fail or return an unchanged IP if I'm not home. For this purpose, note that /var/cache/ddclient/ddclient.cache
caches the last known IP.
Please provide a complete working solution.
I have two custom solutions you might be able to utilize. One uses Wifi SSID only, the other uses MAC address determination.
Both versions have a prerequisite of you having a working
ddclient
configuration for OpenDNS.Step 1 for both: Disable
ddclient
automatic executions.I know the guide you used to set this up had you set it up as a daemon, but we are going to disable the automated
ddclient
update processes.Edit
/etc/default/ddclient
. We're going to disable the daemon mode to start with, and disabledhclient
andipup
integrations. That should make it look similar to this:Now, disable the
ddclient
service so it will not autorun. I only have the 16.04 and later syntax to disable the service, but there are other threads on "How to disable services".After this is done, you can use either of the two options below and their instructions to set up customized automatic processes.
Step 2: Decide which approach you want to use: Wifi-only SSID detection, or MAC address detection. Depending on which solution you wish to go with, follow the specific section below.
Wifi Only: SSID Detection
This is the python code itself for an SSID-based detection. Put the proper Wifi SSID in for the value stored in
WIFI_NETWORK_NAME
.Store this code in
/opt/py-selective-ddclient.py
. You may have to store this in your home directory and then copy it into/opt/
withsudo
.Wifi and Ethernet: MAC Address Detection
This is the Python code for this solution; update the value for
MAC_ADDRESS_ROUTER
accordingly:Store this code in
/opt/py-selective-ddclient.py
. You may have to store this in your home directory and then copy it into/opt/
withsudo
.Step 3: Automate the Python code calls.
Now, we have to automate running
ddclient
, or more specifically automate the Python script. The defaultddclient
settings have a 300 second (5 minute) delay between update checks.First we need to make the Python script executable.
Then, start by making a file in
/etc/cron.d/
with the following contents. Note that you will need to usesudo
to create the file.This executes the
ddclient
manually, every 5 minutes. You can change the*/5
part to make it execute at different intervals, but I am emulatingddclient
's setup here.Now, every 5 minutes
ddclient
will be called using our 'wrapper' script which does the selective determination.These scripts require a working
ddclient
configuration for OpenDNS.Here is a bash version that checks home wifi network name
If you want a less verbose minimal code, use the following lines:
Here is a bash version that checks home router's MAC address
You need only one of these. Store either of the three scripts in
/opt/home_wifi_ddclient.sh
and make the script executable:sudo chmod +x /opt/home_wifi_ddclient.sh
To create the cron entry I suggest using
crontab
:This command will open the
crontab
file for the root user if one exists, or create a blank new file. Add the following line at the end of the file:The
*/5
part means the script will run every 5 minutes.If you use nano as the text file editor, exit the editor by pressing Ctrl+X. The editor will prompt you to save the changes. Press Y and then press Enter to select the default file name.
Hope this helps