Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
    
Good answer. Again I've to use script. Ok, how about if use mac address in the iptable rules –  user3215 Oct 13 '10 at 9:54
1  
@user3215 MAC addresses stay local to your LAN; they will not travel across internet routers. –  Riccardo Murri Oct 13 '10 at 9:57

http://wjoseph.com/?p=20 Here is a blog post with a link to a script that takes a host or a file with a list of hosts as an argument, adds rules to iptables for each host for chosen ports, then adds a cron job which checks for host IP changes periodically.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.