Ubuntu中没有像Redhat一样可以自动配置IPTables,针对本机提供:
引用:
FTP
HTTP
SSH
MySQL
Printer等服务,
写了以下脚本,放在/etc/init.d目录下,自动启动
代码:
#!/bin/bash
case "$1" in
start)
echo -n "Staring to write your Iptbales:..."
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j DROP
/sbin/iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 139 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 631 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 445 -j ACCEPT
/sbin/iptables -A INPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -p all -m state --state INVALID,NEW -j DROP
echo "Ok"
;;
stop)
echo -n "Cleaning your Iptables:..."
/sbin/iptables -P INPUT ACCEPT #必须将INPUT 设置成ACCETP 否则会拒绝所有的INPUT
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -Z
echo "Ok"
;;
restart)
echo -n "Cleaning your Iptables:..."
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -Z
echo "Ok"
echo -n "Staring to write your Iptbales:..."
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j DROP
/sbin/iptables -A INPUT -p tcp -m tcp --dport 20 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 445 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m tcp --dport 139 -j ACCEPT
/sbin/iptables -A INPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -A INPUT -p all -m state --state INVALID,NEW -j DROP
echo "Ok"
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
阅读(362) | 评论(0) | 转发(0) |