linux iptables 开特定端口,封UDP协议

(1)开ssh远程端口
# iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT

(2) 将IPNUT OUTPUT FORWARD 设置为DROP
# iptables -P INPUT DROP
# iptables -P OUTPUT DROP
# iptables -P FORWARD DROP

(3)开放特定的tcp端口 80 ,21, 3306 等
# iptables -A INPUT -p tcp -m multiport --dports 21,80,3306 -j ACCEPT
# iptables -A OUTPUT -p tcp -m multiport --sports 21,80,3306 -j ACCEPT

(4) 开启服务器的ping ,外网可以ping通服务器的ip
# iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
# iptables -A OUTPUT -p icmp --icmp-type 0 -j ACCEPT

禁止PING设置
# iptables -A INPUT -p icmp --icmp-type 8 -s 0/0 -j DROP

(5) 让服务器上互联网
服务器能ping通外网ip,能解析外网的域名
5.1 让服务器能ping通外网的ip
# iptables -A OUTPUT -p icmp --icmp-type 8 -j ACCEPT
5.2 开放服务器的外出DNS查询功能
# iptables -A OUTPUT -p udp --destination 8.8.8.8/255.255.255.255 --dport 53 -j ACCEPT
# iptables -A OUTPUT -p udp --destination 114.114.114.114/255.255.255.255 --dport 53 -j ACCEPT
# iptables -A OUTPUT -p tcp -j ACCEPT
5.3 iptables允许由服务器本身请求的数据通过
# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

(6) 开启本地回环接口 (很多网络程序需要这个接口来通信)
# iptables -A INPUT -i lo -j ACCEPT
# iptables -A OUTPUT -o lo -j ACCEPT

iptables

相关新闻

联系我们

全国服务热线

400-033-9553

电子邮件:admin@example.com
工作时间:09:00-17:00 周一至周五

在线客服
关注微信
关注微信
分享本页
返回顶部