LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 548|回复: 0

请教利用iptables配合crontab的控制访问问题:

[复制链接]
发表于 2004-10-20 12:12:33 | 显示全部楼层 |阅读模式
有两个文件,分别用iptables配置了相应的权限,其中"limit.firewall"是上班时间的设置,"free.firewall"是休息或下班时间的设置。我想

利用crontab在上班时间调用"limit.firewall",下班或休息时间调用"free.firewall"。可不知道为什么总是不行。希望哪位兄弟能给点提示,

先谢谢了。

crontab -l

30 08 * * 1-5 /etc/rc.d/limit.firewall
00 12 * * 1-5 /etc/rc.d/free.firewall
00 13 * * 1-5 /etc/rc.d/limit.firewall
30 17 * * 1-5 /etc/rc.d/free.firewall



free.firewall 和limit.firewall 的属性已设为: -rwxr-xr-x

# free.firewall

echo "Enabling IP Forwarding ......"
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "Starting iptables rules ......"

/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp

/sbin/iptables -F INPUT
/sbin/iptables -F FORWARD
/sbin/iptables -F PREROUTING -t nat
/sbin/iptables -F POSTROUTING -t nat

/sbin/iptables -A INPUT -s 10.8.8.0/24 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -s 222.222.6.0/24 -p tcp --dport 22 -j ACCEPT   
/sbin/iptables -A INPUT -s 222.222.19.0/24 -p tcp --dport 22 -j ACCEPT   
/sbin/iptables -A INPUT -s 0.0.0.0/0 -p tcp --dport 22 -j DROP


/sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE



# limit.fireall

echo "Enabling IP Forwarding ......"
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "Starting iptables rules ......"

/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp

/sbin/iptables -F INPUT
/sbin/iptables -F FORWARD
/sbin/iptables -F PREROUTING -t nat
/sbin/iptables -F POSTROUTING -t nat

/sbin/iptables -A INPUT -s 10.8.8.0/24 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -s 222.222.6.0/24 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -s 222.222.19.0/24 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -s 0.0.0.0/0 -p tcp --dport 22 -j DROP

/sbin/iptables -A FORWARD -p tcp --dport telnet -j DROP


/sbin/iptables -A FORWARD -d 202.104.129.252 -j DROP
/sbin/iptables -A FORWARD -d 218.18.95.220 -j DROP
/sbin/iptables -A FORWARD -d 218.18.95.209 -j DROP
/sbin/iptables -A FORWARD -d 218.18.95.153 -j DROP
/sbin/iptables -A FORWARD -d 219.133.40.95 -j DROP
/sbin/iptables -A FORWARD -d 218.17.209.23 -j DROP
/sbin/iptables -A FORWARD -p udp --dport 8000 -j DROP

/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 81 -j REDIRECT --to-ports 3128
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 3128 -j REDIRECT --to-ports 3128
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 8000 -j REDIRECT --to-ports 3128
/sbin/iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 8080 -j REDIRECT --to-ports 3128


/sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE



每次到crontab设置的时间都会出现如下错识

>N  1 root@localhost.local  Wed Oct 20 12:00  17/617   "Cron <root@tysoft> /etc/rc.d/free.firewall"
&
Message 1:
From root  Wed Oct 20 12:00:00 2004
Date: Wed, 20 Oct 2004 12:00:00 +0800
From: root@localhost.localdomain (Cron Daemon)
To: root@localhost.localdomain
Subject: Cron <root@tysoft> /etc/rc.d/free.firewall
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <ATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>

: No such file or directoryewall
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表