Dynamic IP changed overnight - how do I automate updating my Public IP across all servers?

You can get a vHost 2CPU/ 4GB Ram/ 50 GB storage for 10 euro, and you can use that as your fixed IP that check for your home server, and use it as relay for Postfix or something.
Or 1 vcore/ 2gb ram/ 25 gb space 1 IP

Thanks for the information on the Virtualmin commands.

I guess I misunderstood how this worked. I thought it only ran when the system registered a change in its IP. I can still use it to change the virtual server IPs but I may as well just continue to use my old python script in a cron job to change my Host records.

Is it possible to obtain the old IP and the new IP as variables that I could pass to my python script inside the bash script?

You can use something like this https://www.noip.com/
I used them 20 years ago or something. And recently for my IP cameras.

I don’t really like Oracle but VIrtualmin give you the posibility to use it

You could check which environmental variables Virtualmin sets when running your script by dumping them into a file, e.g.:

import os

# Open file to write environment variables
with open('/root/virtualmin-newdynip-envs', 'w') as f:
    for key, value in os.environ.items():
        f.write(f"{key}: {value}\n")

@staff - confirming it is expected behavior that the script is run every 5 minutes, regardless if the IP changes or not?

This would seem to generate a lot of calls / logs / emails / traffic unnecessarily.

No it should only be run when the IP changes, unless the script fails…

Meaning that the external script that can be called in Addresses and Networking ⇾ Dynamic IP Update page should manually check if the IPs were changed? Or it simply won’t be called at all if the IPs weren’t changed?

Do you need me to open a bug / ticket via private support for this? I found that my setup is calling the script every 5 min, regardless of if the IP has changed or not. It’s sending me an email every 5 min that the change IP script failed because the IP has not changed.

It won’t be run if Virtualmin thinks the IP hasn’t changed.

Confirming this is an issue - even though the IP has not changed, the script is still being called:

An attempt to update the dynamic IP for webhost.aiskon.net to 76.117.62.249
with Run external script .. failed: /root/dynamicip-update.sh 76\.117\.62\.249
webhost\.aiskon\.net failed : The old and new IP addresses are the same!

Update all virtual servers with a new IP address.

virtualmin modify-all-ips [--old-ip address | --default-old-ip]
                          [--new-ip address | --detect-new-ip]Sent by Virtualmin at: https://webhost.aiskon.net:10000

Thanks xlad but I already have a method for switching my Host records for updating DNS. I really don’t want to add an extra service.

I was looking at the Dynamic IP Update tool in Virtualmin as a way to trigger the process but GJSchaller reports that it is being called every 5 minutes regardless of an IP change or not.

I misunderstood the use of the tool. I was expecting that it was monitoring the IP in use, in the background, and when the IP changed it would provide the old IP the new IP and a few other variables listed in the dialog and that information could be used in an exteranl script. At the same time, if it was set to Active, it would go ahead and change the internal IPs listed for each virtual server and update Webmins IP settings. I was going on the help info provided (in the dialog) but couldn’t find any more detailed info until Illia gave me the information on the Virtualmin commands.

Since it only has DynDNS listed (I don’t use them) I figured that running an external script allowed me to define a script that altered my Registrar’s Host records myself. My reasoning was that DynDNS was a service already supported, but if you used something else you would create your own script to interact with your host records meaning that Webmin/Virtualmin would not have to create a bunch of different scripts for all the different dynamic DNS providers.
Since I already had a script made, I assumed I could call my python script (the one that interacts with my registrar) and use several variables passed from this Dynamic IP Update tool to my script.

It would simplify my setup in a couple of ways. It would not require me to use a cron job to monitor my IP and it would save me from actually storing the current and changed IPs on my system in a file (that my script checks for a change to initiate the host record change.)
It would also automatically update the the virtual servers within webmin/virtualmin to the new IP, eliminating the warning message I get in Webmin and the need for me to manually change the IPs for my virtual servers.

Apparently that’s not how this Dynamic IP Update tool works. From this thread it appears it will run a script using a virtualmin command that will update the internal IPs for any virtual server. Not sure why it works that way. Looks like you can get it to run any command line command simply by adding it into a scripts and that it will run every 5 minutes. I can do that with a cron job.
I’m not sure why the command
virtualmin modify-all-ips --default-old-ip --detect-new-ip
has to be added as the external script since it should be one of the purposes of this function in the first place.
In my way of thinking the process should be

  1. Monitor IP for changes and begin the process when it happens
  2. Send the new IP of the server to the DNS provider to change the host records (DynDNS or External script or Skip)
  3. Change all the internal (virtual server, webmin etc.) ips to the new IP
  4. Log changes
  5. Send a report indicating success or failure
2 Likes

@GJSchaller ok it looks like the script is failing because it has nothing to do, which causes Virtualmin to keep running it!

Maybe just edit /root/dynamicip-update.sh and add exit 0 at the end so it never appears to fail.

I can do that, but I was also thinking of adding a line to it to update my NameCheap DNS for the one domain that doesn’t have DNS hosted locally… I don’t want to be hitting NameCheap every 5 minutes if I can help it, I’d rather do it only when the IP changes.

If the script is only called when the IP changes, it will save a lot of processing / calls.

Maybe you should open a new issue on VIrtualmin bug tacker, if that’s the correct procedure to do it, and put there exactly this what you just wrote: Issues · virtualmin/virtualmin-gpl · GitHub

I makes sense.

And should be fairly simple to compare old domain ip from VIrtualmin domain files with current system IP (if the provider changed it), than send old IP, new IP and domain to an external script and trigger Virtualmin actions (domain IP change).

You already have the domains IP / hostname pairs in /etc/webmin/virtual-server/domains no need for other files to compare (ip=xxx.xxx.xxx.xxx), and current IP (ip addr show eth0)

But I’m not really a programmer and just visit VIrtualmin until I setup my server(s)

Once you change the script to exit with status zero, it won’t be called again until the IP changes.

Ah, I see. I’ll set that now and test it.

Thank you!

How are you planning to update your script to provide the new IP to your NameCheap DNS?

Done, thanks

1 Like

NameCheap’s API lets you visit a URL and provide arguments (domain name, username, and API Key) that will update the domain’s IP to match where the call came from. By running cURL (update url & arguments) when my server’s IP changes, it will pass this up to NameCheap as a part of the process.

Thanks Illia,

19 variables but none of them useful for my purposes.

I can pull the current IP from the system network adapter
If the Dynamic IP Update only runs when there is a new IP I can then use it to initiate a hosts record update and won’t have to do the check in my python script.

I will experiment with Jamie’s suggestion of adding exit 0