Chinaunix首页 | 论坛 | 博客
  • 博客访问: 105648
  • 博文数量: 22
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 245
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-10 12:18
文章分类

全部博文(22)

文章存档

2017年(3)

2011年(1)

2010年(10)

2009年(1)

2008年(7)

我的朋友

分类: LINUX

2009-01-10 09:25:53

一个简单的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端口。若需要开放其他的服务可以依次添加。

阅读(1388) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~