Ubuntu – Iptables allow dyndns domain name and auto update rules

iptables

I have registered with dyndns domain for my dynamically changing public ip address to use with iptable rules. On a server I've allowed some ports for this domain in the iptables configuration like the below entries:

-A INPUT -s mycompany.dyndns.com -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -s mycompany.dyndns.com -p tcp -m tcp --dport 3306 -j ACCEPT
-A INPUT -s mycompany.dyndns.com -p tcp -m tcp --dport 21 -j ACCEPT

But when ever my modem restarts, I couldn't connect to these allowed ports as public ip changes with modem restart and are not updated in the iptables on the server. Is there any option to automatically update iptable rules on server.

Best Answer

In short: no, the only way to update an iptables rule is to replace it (iptales -R ...) or to delete it and add a new one with the updated IP address (iptables -D ... followed by iptables -A ...).

This blo post discusses the issue and sketches a solution.