Chinaunix首页 | 论坛 | 博客
  • 博客访问: 830811
  • 博文数量: 105
  • 博客积分: 636
  • 博客等级: 中士
  • 技术积分: 1704
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-11 10:57
文章分类

全部博文(105)

文章存档

2017年(4)

2016年(9)

2015年(18)

2014年(16)

2013年(34)

2012年(24)

分类: LINUX

2013-05-20 14:12:41

在安装好centos 5.4后 如果默认启动防火墙,则启动的是ip6tables 如果想更换成iptables 需要先关闭 在启动
系统会启动iptables  为了启动时自己启动iptables 需要如下操作
chkconfig --level 345 ip6tables off
chkconfig --level 345 iptables on
启动和关闭iptables 的命令如下
service iptables start/stop/restart

启动linux 的iptables 后 进行设置
1.首先iptables -h  查看iptables的帮助命令 。通过帮助命令让你尽快熟悉命令的使用
2.iptables -L 查看当前的策略,我的系统显示如下

Chain INPUT (policy ACCEPT)
target     prot opt source               destination        
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere           
ACCEPT     all  --  anywhere             anywhere           
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination        
ACCEPT     all  --  anywhere             anywhere            PHYSDEV match --physdev-is-bridged
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source              destination

3.这里我只说明我修改的地方
  本来是没有开放http:80端口  现在要开通
  默认有三条链 INPUT  FORWARD  OUTPUT    
 这三条链 input 是要访问本主机 ,output 是主机向外访问 ,forward 作为中转
设置 这只这三条链默认策略
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
一般将input 设置为drop,然后添加一些接受策略; 将output 设置为accept 意思是 。外界不允许访问主机,但主机可以向外发送消息。
因为上面有一句REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited  所以在centos中 input 默认为

accept.也就是这句 让我费了好多劲

4.先说一下这句话
iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
我们了解一下这句话的含义 iptables 是命令 -A 参数 说明是增加一条策略 ;input是链 ;-j  reject符合规则的包的处理方式
有accept  drop  reject  。 accept 是符合之后通过 ,drop 是直接删除,reject 比drop 含蓄一点 它接收包 但是不会让包通过,还会返回
告诉访问者 访问有问题的信息。--reject-with 后面就是返回的信息内容。 这里有一点问题是 iptables 策略是从上到下匹配的,
就是说 -j drop 或 -j reject策略出现后。之后的策略如果有和它重合的条件 也不会起作用

例:
我在上句话之后加了一句
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
但是还是不能正常访问80端口  原因就是上句已经把包丢弃了
这句话的含义是  -m  加载模块 -p 网络协议 为什么这里用了 -p tcp 还要用-m tcp 
因为-m tcp 可以使用模块的--dport  .--state 指的的链接状态(这些都需要有一些网络知识帮助我们理解)
5.我只是把用到的简单叙述一下 详细信息还要大家多去 man iptables




阅读(9091) | 评论(0) | 转发(0) |
0

上一篇:管理aix的密码策略

下一篇:监控apache脚本

给主人留下些什么吧!~~