I would like to give an ip access to tcp port 3306 for an hour. After that, all connections must be closed.
How can i add a timeout to the following expression?
iptables -A INPUT -m state --state NEW -m tcp -p tcp --source 1.2.3.4 --dport 3306 -j ACCEPT
I believe (I've never used it, and found it through the iptables man page) --timestart and --timestop will accomplish this.
iptables -A INPUT -m state --state NEW,ESTABLISHED,RELATED -m tcp -p tcp --source 1.2.3.4 --dport 3306 --timestart 13:00 --timestop 14:00 -j ACCEPT
Would allow you between 1 and 2pm.
Alternative solution that does not require iptables time module supported.
This won't close the connections after hour, it will simply return to whatever policy was before allowing the connection; which can be setup to interrupt and drop/reject the no longer allowed traffic unless you have STATE ESTABLISHED ALLOW beforehand.