You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/sh
# 黄海反复试验了几次,发现在设置之前关闭防火墙才是最安全的办法,否则会发生连接不上的问题
service iptables stop
iptables -F
iptables -X
iptables -Z
# 允许连接到的内网
iptables -A OUTPUT -d 10.10.21.20 -j ACCEPT
# 允许连接到的外网
iptables -A OUTPUT -d 219.149.194.55 -j ACCEPT
iptables -A OUTPUT -d www.cnblogs.com -j ACCEPT
# 允许icmp包通过,也就是允许ping
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
#本机对外请求相当于OUTPUT,对于返回数据包必须接收啊这相当于INPUT了
iptables -I INPUT -i lo -j ACCEPT
iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#信任IP
iptables -A INPUT -s 10.10.21.20 -j ACCEPT
# 开放80端口
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT
#关闭其它人员进入
iptables -P INPUT DROP
# 禁用所有出去的网络
iptables -P OUTPUT DROP
# 保存iptbales规则
service iptables save
# 重新启动
service iptables restart