Making use of AI: C program to handle dynamic IP update to ufw

If you haven't read my previous post on dynamic IP updates for Digital Ocean, check it out. But to make it easy: My primary source of Internet is 5G, with consistent IP changes, and this makes it a bit difficult to stay logged in, or authenticated to certain services (if you're looking for a decent layer of security).

Artificial intelligence is doing magic for some of us. I have searched, and found incredibly old, or otherwise defunct dynamic IP solutions, and most of them work only in one direction, rather than two. I'll have to find a better way to explain that.

But now...  needed to a method for updating my home IP to a specific remote server. It doesn't have a fore-firewall, so its update mechanism must be on the machine itself. I was thinking about using a cron, but decided to setup a full C program as a service.

./ipupdate sub.domain.tld

Compile:

gcc -o ipupdate ipupdate.c

I set this to run as a service. So:

sudo nano /etc/systemd/system/ip-update-ufw.service

Inserting:

[Unit]
Description=UFW Updater Service
After=network.target

[Service]
ExecStart=/path/to/ip-update_ufw_service <domain>
Restart=always
User=root
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=ip-update-ufw
KillSignal=SIGTERM

[Install]
WantedBy=multi-user.target

Reload, and enable:

sudo systemctl daemon-reload
sudo systemctl enable ip-update-ufw.service
sudo systemctl start ip-update-ufw.service

Now, I can rest assured when the IP changes, within five minutes I should have gained access again... if I remember to update the DNS A record!

Thank you for reading!