iptables in crontab command

crontab www.attackr.com I m using crontab command to execute some command in our server computer. So I don’t have access it everytime the server need to set something. All command I want is running well except for iptables. The server rejects to do iptables command. Here is a script that I made then I will put it in the crontab.

#!/bin/sh -e
iptables -A FORWARDING -p tcp -s –dport 80 -d www.facebook.com -j DROP
#end of script

Then I use crontab in root priviledge (su)
#sudo crontab -e
0 6 * * 1-5 /home/myuser/skript

But nothing happened. After browsing I discovered that the iptables can’t directly execute in crontab. I found that in a forum. He said that we have to change the script into

#!/bin/sh -e
$iptables -A FORWARDING -p tcp -s –dport 80 -d www.facebook.com -j DROP
#end of script

Now the iptables works just fine using crontab scheduler.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.