免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1069 | 回复: 0
打印 上一主题 下一主题

一个简单的iptables应用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-10 09:25 |只看该作者 |倒序浏览

                一个简单的iptables应用
[root@rich ~]# iptables -F
[root@rich ~]# iptables -X
[root@rich ~]# iptables -Z
[root@rich ~]# iptables -t nat -F
[root@rich ~]# iptables -t nat -X
[root@rich ~]# iptables -t nat -Z
[root@rich ~]# service iptables save
将当前规则保存到 /etc/sysconfig/iptables:              [确定]
[root@rich ~]# iptables -P INPUT DROP
[root@rich ~]# iptables -P FORWARD DROP
[root@rich ~]# iptables -P OUTPUT ACCEPT
这一条命令将会为你构建一个非常“安全”的防火墙,我很难想象有哪个hacker能攻破这样的机器,因为它将所有从网络进入你机器的数据丢弃(drop)了。这当然是安全过头了,此时你的机器将相当于没有网络。如果你ping localhost,你就会发现屏幕一直停在那里,因为ping收不到任何回应
[root@rich ~]# iptables -A INPUT -p tcp —sport 80 -j ACCEPT
允许来自所有网络接口,并且来源端口是80的数据进入你的计算机
[root@rich ~]# iptables -A INPUT -p tcp --sport 53 -j ACCEPT
[root@rich ~]# iptables -A INPUT -p udp —sport 53 -j ACCEPT
接受所有来自所有网络接口,upd协议的53端口的数据。53也就是著名的dns端口
[root@rich ~]# service iptables save
将当前规则保存到 /etc/sysconfig/iptables:                 [确定]
[root@rich ~]# iptables -A INPUT -P icmp -j ACCEPT
Iptables -A INPUT -I lo -j ACCEPT  这句只是开放本机访问本机,简单说本机存取自己不设防。
上面的内容为linux作为一个单纯的个人防火墙的配置。上面的sport的寓意是允许远方的web服务器的80端口传送的数据进入我的计算机。
iptables -A INPUT -p tcp —dport 80 -j ACCEPT   允许访问web服务。
这里的dport的寓意是我的linux已经作为一个web服务器,其他的主机要允许访问我的80端口。若需要开放其他的服务可以依次添加。
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/78886/showart_1786174.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP