Wednesday, June 15, 2011

Time bases iptables rules


If you want to restrict/allow access to certain service on timely basis using iptables. 
Use : iptables patch-o-matic extension (pom or p-o-m)
That allows us to match a packet based on its arrival or departure  timestamp.
Syntax : iptables RULE -m time –timestart TIME –timestop TIME –days DAYS -j ACTION
                –timestart TIME: Time start value (format is 00:00-23:59)
               –timestop TIME: Time stop value (the same format)
               –days DAYS: a list of days to apply, from (format: Mon, Tue, Wed, Thu, Fri, Sat, Sun).
Example :  We want to  restrict access to SSH between 10:00 pm – 8:00am on weekdays.
#iptables -A INPUT -p tcp -d 192.168.10.1 –dport 22 -m time –timestart 22:00 –timestop 8:00 -days Mon,Tue,Wed,Thu,Fri -j DROP