在订阅extmail的文章会不定时发送一些内容.但有些觉的还不错.特别是这个有关iptables的设置邮件方面.现在很多做防火墙只是专一的防火墙.所以你在做邮件服务器可以同时使用这个那更加不错了.下面这些是来处extmail.
以下是我测试iptables的一些实例,相信在邮件服务器也用得着,所以分享给大家看看.
实验环境: 192.168.1.0/255.255.255.0
服务器 Debian(etch)4.0 IP:192.168.1.96
客户机1 Windows XP SP2 IP:192.168.1.90
客户机2 Windows XP SP2 IP:192.168.1.234
iptables以顺序方式执行,从上到下!
常用iptables维护命令:
#iptables -L -n 显示当前iptables规则
#iptables-save > /etc/iptables-script 保存规则
#iptables-restore /etc/iptables-script 恢复保存的规则
设置iptables开机自动加载规则,添加以下内容至/etc/rc.local文件中即可
/sbin/iptables-restore /etc/iptables-script
需要注意的是,必须写完全路径,要不然系统找不到命令与规则及脚本
1,缺省策略,让信息毫无限制地流出,但不允许信息流入
#iptables -P INPUT DROP
#iptables -P FORWARD DROP
#iptables -P OUTPUT ACCEPT
2,允许192.168.1.90无限制连接至192.168.1.96服务器(便于维护与测试服务器)
#iptables -A INPUT -s 192.168.1.90 -d 192.168.1.96 -j ACCEPT
3,允许127.0.0.1环路
#iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
#iptables -A OUTPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
4,允许局域网192.168.1.0内的所有机器能访问192.168.1.96服务器的80端口
#iptables -A INPUT -p tcp -s 192.168.1.0/24 -d 192.168.1.96 –dport 80 -j ACCEPT
5,拒绝192.168.1.92 Ping 192.168.1.96
#iptables -A INPUT -p icmp -s 192.168.1.92 -d 192.168.1.96 -j DROP
6,拒绝所有Ping
#iptables -A INPUT -p icmp -j DROP
7,拒绝192.168.1.96 Ping 192.168.1.8
#iptables -A OUTPUT -p icmp -s 192.168.1.96 -d 192.168.1.8 -j DROP
8,拒绝192.168.1.234连接192.168.1.96的80端口
#iptables -A INPUT -p tcp -s 192.168.1.234 -d 192.168.1.96 –dport 80 -j DROP
9,允许192.168.1.96服务器使用Ping
#iptables -A INPUT -p icmp -d 192.168.1.96 -j ACCEPT
10,允许DNS查询
#iptables -A INPUT -p udp –sport 53 -j ACCEPT
#iptables -A INPUT -p tcp –sport 80 -j ACCEPT (注:上网好像需要开这个端口???)
11,允许来自192.168.1.234的电脑Ping服务器192.168.1.96
#iptables -A INPUT -p icmp -s 192.168.1.234 -j ACCEPT
12,如果要自己能ping人家,而人家不能ping你,可以:
#iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -j DROP
#iptables -A INPUT -p icmp –icmp-type 0 -s 0/0 -j ACCEPT
#iptables -A OUTPUT -p icmp –icmp-type 0 -s 192.168.1.96 -j DROP
#iptables -A OUTPUT -p icmp –icmp-type 8 -s 192.168.1.96 -j DROP
注:icmp的type 0为回显应答(Ping应答),8为请求回显(Ping请求).Tcpip第6章ICMP:Internet控制报文协议
13,无法使用apt-get update解决方法
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
14,使用FTP问题
#modprobe ip_nat_ftp 加载模块
#modprobe ip_conntrack
#modprobe ip_conntrack_ftp
#iptables -A INPUT -p tcp –sport 21 -j ACCEPT
#iptables -A INPUT -P tcp –dport 21 -j ACCEPT
#iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
15,查看某一条规则序号并删除
#iptables -L -n –line-numbers
iptables -D INPUT 8
16,拒绝192.168.1.90连接服务器的80端口(注意,必须放在允许规则前面)
#iptables -I INPUT 1 -p tcp -s 192.168.1.90 -d 192.168.1.96 –dport 80 -j DROP
原创文章,转载请注明: 转载自PT Ubuntu Blog