myiptables: iptables常用配置

#!/bin/bash
# myiptables.sh
iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

# DNS
iptables -A OUTPUT -p udp –dport 53 -j ACCEPT
iptables -A INPUT -p udp –sport 53 -j ACCEPT

# 允许包从22端口进入
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
# 允许从22端口进入的包返回
iptables -A OUTPUT -p tcp –sport 22 -m state –state ESTABLISHED -j ACCEPT

# 允许本机访问本机
iptables -A INPUT -i lo -j ACCEPT

# 允许所有IP访问80端口
iptables -A INPUT -p tcp -s 0/0 –dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp –sport 80 -m state –state ESTABLISHED -j ACCEPT

# 保存配置 或者使用命令 service iptables save
iptables-save > /etc/sysconfig/iptables
iptables -L

:仅仅屏蔽外网(eth1)
iptables -P INPUT ACCEPT
iptables -A INPUT -p tcp -i eth1 –dport 8080 -j DROP

:/etc/sysconfig/iptables  实例

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8161 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

1 Comment

Leave a Reply

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

粤ICP备15062915号-1