RH413企业安全加固 第16章 控制网络服务访问

第16章 控制网络服务访问

 

环境配置

1、RHEL6.4 SERVER 10.10.10.221

2、RHEL6.4 CLIENT 10.10.10.223

 

1、IPTABLES防火墙是基于GNU  +  LINUX AND KERNEL

2、IPTABLES 是写防火墙的一个工具

3、IPTABLES 是将防火墙写入到内存中的一种工具

4、Netfilter/IPTABLES 工作的位置

 

 

5、Netfilter/IPTABLES防火墙是基于OSI参考模型的234层插入策略的

6、Netfilter表和Netfilter

 

 

7、Netfilter/IPTABLES防火墙主要分为3大功能表

1) filter表是对数据包做过滤的

2) Nat表是物理地址转换

3) Mangle表是数据包做修改

4) RAW表负责加快封包穿越防火墙机制的速度(注意:这个表用的比较少)

8、Netfilter链主要负责数据包在防火墙中的流向

9、使用IPTABLES命令查看规则

[root@teachers ~]# iptables -L --line-num

10、使用IPTABLES命令查看更详细信息(如:数据包过滤等)

[root@teachers ~]# iptables -L --line-num -vnZ

Chain INPUT (policy ACCEPT 6046 packets, 1629K bytes)

num   pkts bytes target     prot opt in     out     source               destination         

 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)

num   pkts bytes target     prot opt in     out     source               destination         

 

Chain OUTPUT (policy ACCEPT 692 packets, 112K bytes)

num   pkts bytes target     prot opt in     out     source               destination         

Zeroing chain `INPUT'

Zeroing chain `FORWARD'

Zeroing chain `OUTPUT'

 

11、IPTABLES防火墙匹配的规则

1) 规则是至下而上的方式

2) 按照规定的顺序测试数据包

3) 可以匹配多个条件

4) 必须满足规则说明中的每个条件才算匹配(逻辑AND)

5) 没有匹配到规则则使用应用链策略

6) 规则一条条的被加入到INPUT链中

 

12、规则通常考虑的因素

1)写完规则后在关门

2)条件也适用于回送接口

3)和路由一样,规则被载入内存

4)不管在CHAIN之内有多少规则,默认策略永远在每一个链的底端。状态不是ACCEPT就是DROP

 

13、链操作

1) ACCEPT(默认,是内置目标)

2) DROP(内置目标)

3) REJECT(不允许,是扩展目标)

4) 清除某个链的所有规则“-F

5) 把字节和数据包计数器重置为零“-Z

6) 管理定制链“-N”“-X”,-N代表添加链 -X代表删除链

 

14、IPTABLES匹配的条件

1、流入、流出接口(-i”,“-o)   -i  eth0

2、来源、目的地址(-s”,“-d)

-s  192.168.1.0/24

-d www.abc.com

 

3、协议类型“-p” -p tcp udp icmp

4、来源、目的端口( --sport--dport) 注意:“:

--sport 1000 匹配源端口数据为1000的数据包

--sport 1000:3000 匹配源端口是1000-3000的数据包(包含10003000)

 

--sport:3000 匹配源端口是3000以下的数据包(包含3000)

--sport 1000: 匹配源端口是1000以上的数据包(包含1000)

 

5、IPTABLES匹配条件

   如果要否定策略条件可以在 “-s”前面加上一“!”。

 

6、练习

1)配置iptables

[root@student ~]# iptables -F ---清空链

[root@student ~]# iptables -L ---查看链

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         

 

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination         

 

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination 

 

2)SERVER端写入链

[root@student ~]# [root@teachers ~]# iptables -A INPUT -p tcp -s 10.10.10.0/24 --dport 21:22 -j ACCEPT

[root@teachers ~]# iptables -P INPUT DROP ---关闭链

[root@student ~]# service iptables save ---保存链

iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]

 

3)保存的链的文件

[root@student ~]# cat /etc/sysconfig/iptables

# Generated by iptables-save v1.4.7 on Wed Jan 27 08:16:08 2016

*filter

:INPUT ACCEPT [79:10396]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [33:3392]

-A INPUT -s 10.10.10.0/24 -p tcp -m tcp --dport 21 -j ACCEPT 

COMMIT

# Completed on Wed Jan 27 08:16:08 2016

 

4)CLIENT端配置

[root@student ~]# yum install ftp    --安装FTP工具

 

5)使用ftp工具匿名登录

[root@student ~]# ftp teachers

Connected to teachers (10.10.10.221).

220 (vsFTPd 2.2.2)

Name (teachers:root): ftp

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

 

6)使用ls命令查看目录

ftp> ls

227 Entering Passive Mode (10,10,10,221,26,173).     

--被动模式(是由SERVER端发起的,被动模式使用的端口都是随机的)

 

7)连续跟踪

nf_conntrack_ftp

nf_conntrack_tftp

nf_nat_ftp

nf_nat_tftp

 

8)配置SERVER端下的/etc/sysconfig/iptables-config文件

IPTABLES_MODULES="Ip_conntrack_ftp"   ---将随机产生的端口告诉防火墙

 

9)在SERVER端清空链将INPUT打开ACCEPT

[root@teachers ~]# iptables -P INPUT ACCEPT

[root@teachers ~]# iptables -F

[root@teachers ~]# service iptables save

iptables: Saving firewall rules to /etc/sysconfig/iptables: [  OK  ]

 

10)在SERVER端开启回环链

[root@teachers ~]# iptables -A INPUT -i lo -j ACCEPT

[root@teachers ~]# iptables -A INPUT -m state --state INVALID -j REJECT   

--只要这个状态就不要了

[root@teachers ~]# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

--直接将ESTABLISHED放开

[root@teachers ~]# iptables -A INPUT -m state --state NEW -s 10.10.10.0/24 -p tcp --dport 21:22 -j ACCEPT

--开启被动模式

[root@teachers ~]# iptables -A INPUT -j REJECT

--拒绝链

 

11)使用CLIENTftp链接SERVER

[root@student ~]# ftp teachers

Connected to teachers (10.10.10.221).

220 (vsFTPd 2.2.2)

Name (teachers:root): ftp

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> ls

227 Entering Passive Mode (10,10,10,221,161,27).

150 Here comes the directory listing.

drwxr-xr-x    2 0        0            4096 Feb 12  2013 pub

226 Directory send OK.

ftp> ls

227 Entering Passive Mode (10,10,10,221,132,15).

150 Here comes the directory listing.

drwxr-xr-x    2 0        0            4096 Feb 12  2013 pub

226 Directory send OK.

以上就是状态防火墙配置

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

随行之旅

python国产化自动化

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值