iptable 设置 ubuntu

本文详细介绍了如何配置iptables防火墙,包括清除已有规则、设置本地和eth1接口的输入输出规则,以及允许特定端口的流量,同时提供了存储和自动加载iptables规则的方法。
代码:
#删除原来 iptables 里面已经有的规则
iptables -F
iptables -X

#抛弃所有不符合三种链规则的数据包
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#设置:本地进程 lo  的 INPUT 和 OUTPUT 链接 ; eth1的 INPUT链
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i eth1 -m state --state NEW,INVALID -j LOG
iptables -A OUTPUT -o lo -j ACCEPT

#对其他主要允许的端口的 OUTPUT设置:
# DNS
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 53 -j ACCEPT
iptables -A OUTPUT -o eth1 -p UDP --sport 1024:65535 --dport 53 -j ACCEPT

#HTTP
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 80 -j ACCEPT

#HTTPS
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 443 -j ACCEPT

#Email 接受 和发送
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 110 -j ACCEPT
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 25 -j ACCEPT

# FTP 数据和控制
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 20 -j ACCEPT
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 21 -j ACCEPT

#DHCP
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 68 -j ACCEPT
iptables -A OUTPUT -o eth1 -p UDP --sport 1024:65535 --dport 68 -j ACCEPT

#POP3S Email安全接收
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 995 -j ACCEPT

#时间同步服务器 NTP
iptables -A OUTPUT -o eth1 -p TCP --sport 1024:65535 --dport 123 -j ACCEPT

#拒绝 eth1 其他剩下的
iptables -A OUTPUT -o eth1 --match state --state NEW,INVALID -j LOG


最后是有关于iptables存储的命令:
代码:
iptables-save > /etc/iptables.up.rule # 存在你想存的地方

代码:
iptables-restore < /etc/iptables.up.rules #调用


因为iptables 在每次机器重新启动以后,需要再次输入或者调用,为了方便操作,使用
代码:
sudo gedit /etc/network/interfaces


代码:
 auto ath0
       iface ath0 inet dhcp
后面加上
代码:
pre-up iptables-restore < /etc/iptables.up.rules #启动自动调用已存储的iptables

代码:
post-down iptables-save > /etc/iptables.up.rule #关机时,把当前iptables 储存


转载自:http://forum.ubuntu.org.cn/viewtopic.php?t=62432

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值