什么都不多说,记录一下使用iptables的实例,防止长时间不用忘记!
OS: debian4.0(etch)
实验环境: 192.168.1.0/255.255.255.0
服务器 Debian(etch)4.0 IP:192.168.1.10
客户机1 Windows XP SP2 IP:192.168.1.15
客户机2 Windows XP SP2 IP:192.168.1.16
常用iptables维护命令:
#iptables -L -n 显示当前iptables规则
#iptables-save > iptables-script 保存规则
#iptables-restore 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.15无限制连接至192.168.1.10服务器(便于维护与测试服务器)
#iptables -A INPUT -s 192.168.1.15 -d 192.168.1.10 -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.10服务器的80端口
#iptables -A INPUT -p tcp -s 192.168.1.0/24 -d 192.168.1.10 –dport 80 -j ACCEPT
5,拒绝192.168.1.16 Ping 192.168.1.10
#iptables -A INPUT -p icmp -s 192.168.1.16 -d 192.168.1.10 -j DROP
6,拒绝所有Ping
#iptables -A INPUT -p icmp -j DROP
7,拒绝192.168.1.10 Ping 192.168.1.16
#iptables -A OUTPUT -p icmp -s 192.168.1.10 -d 172.28.156.8 -j DROP
8,拒绝192.168.1.15连接192.168.1.10的80端口
#iptables -A INPUT -p tcp -s 192.168.1.15 -d 192.168.1.10 –dport 80 -j DROP
9,允许192.168.1.10服务器使用Ping
#iptables -A INPUT -p icmp -d 192.168.1.10 -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.15的电脑Ping服务器192.168.1.10
#iptables -A INPUT -p icmp -s 192.168.1.15 -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 localip -j DROP
#iptables -A OUTPUT -p icmp –icmp-type 8 -s localip -j DROP
Powered by MightyAdsense
2 条评论了已经
发表评论
字体为 粗体 是必填项目,邮箱地址 永远不会 公布。
允许部分 HTML 代码:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs(网站链接)必须完整有效 (比如: http://www.23day.com),所有标签都必须完整的关闭。
超出部分系统将会自动分段及换行。
请保证评论内容是与日志或 Blog 内容相关的,灌水、攻击性或不恰当的评论 可能 会被编辑或删除。
怎么不写ubuntu啦
呵呵,Debian做服务器用的,Ubuntu跑桌面