将路由器打造成防火墙 —— IOS精典防火墙 (下)
防火墙产品介绍(可略过):
防火墙大致分为软件防火墙和硬件防火墙两类,一般常用的都是硬件防火墙。软件防火墙如微软的TMG。硬件防火墙的品牌就较多了,国外知名的有Checkpoint,Juniper,PALoalto,Cisco、fortinet(飞塔 )等,国内知识的有天融信、山石、华为等。
下面正式进入今天的主题:Cisco IOS 防火墙
拓扑图如下:
基本配置:
R1配置:
- R1(config)#int f0/0
- R1(config-if)#ip add 12.1.1.1 255.255.255.0
- R1(config-if)#no shut
- R1(config-if)#router rip
- R1(config-router)#ver 2
- R1(config-router)#no auto
- R1(config-router)#net 12.0.0.0
R2配置:
- Router(config)#host R2
- R2(config)#int f0/0
- R2(config-if)#ip add 12.1.1.2 255.255.255.0
- R2(config-if)#no shut
- R2(config-if)#int f1/0
- R2(config-if)#ip add 23.1.1.2 255.255.255.0
- R2(config-if)#no shut
- R2(config-if)#router rip
- R2(config-router)#ver 2
- R2(config-router)#no auto
- R2(config-router)#net 12.0.0.0
- R2(config-router)#ver 23.0.0.0
R3配置:
- Router(config)#host R3
- R3(config)#int f1/0
- R3(config-if)#ip add 23.1.1.3 255.255.255.0
- R3(config-if)#no shut
- R3(config-if)#router rip
- R3(config-router)#ver 2
- R3(config-router)#no auto
- R3(config-router)#net 23.0.0.0
- R3(config)#line vty 0 4
- R3(config-line)#no login
防火墙配置:
在防火墙出接口配置一条Deny any的ACL,防止由外部始发的流量访问内部网络(如果内网有服务器发布到外网,需要在ACL中进行放行)
在内部网络的流量访问外部网络时候配置监测,可以在内部接口入方向或外部接口出方向配置监测。推荐在外接口的出方向做inspect,这样可以不用考虑inside区域接口的数量,都能够监测到。
配置全局参数(可选)
配置要求:
R1能够ping通R3,不能telnetR3。
配置前测试:
- R1#ping 23.1.1.3
- Type escape sequence to abort.
- Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
- !!!!!
- Success rate is 100 percent (5/5), round-trip min/avg/max = 92/99/116 ms
- R1#telnet 23.1.1.3
- Trying 23.1.1.3 ... Open
- R3>
R2 CBAC配置
- R2(config)#ip access-list extended outside-acl
- R2(config-ext-nacl)#deny ip any any
- R2(config)#int f1/0
- R2(config-if)#ip access-group outside-acl in
配置完上述命令,R1再次telnetR3
- [Connection to 23.1.1.3 closed by foreign host]
- R1#telnet 23.1.1.3
- Trying 23.1.1.3 ...
- % Connection timed out; remote host not responding
发现无法telnet通R3,还一正处于一种卡着的状态。其实telnet的数据包是能够发出去的,并且已经到达了R3,但是R3回来的数据包被在R2入方向的ACL阻止了,因此导致telnet超时。
继续配置第二步,对数据包进行检测:
- R2(config)#ip inspect name outside.inspect tcp
- R2(config)#ip inspect name outside.inspect udp
- R2(config-if)#int f1/0
- R2(config-if)#ip inspect outside.inspect out
再次telnet进行测试,已经可以telnet通R3了。
- R1#telnet 23.1.1.3
- Trying 23.1.1.3 ... Open
- R3>
通过show命令进行查看
R2#show ip inspect sessions
Established Sessions
Session 682C3818 (12.1.1.1:30018)=>(23.1.1.3:23) tcp SIS_OPEN
我们再来进行PING测试,发现PING不通,这是因为没有配置针对ICMP的检测。
- R1#ping 23.1.1.3
- Type escape sequence to abort.
- Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
- .....
- Success rate is 0 percent (0/5)
配置ICMP监测:
R2(config)#ip inspect name outside.inspect icmp
再次测试:
- R1#ping 23.1.1.3
- Type escape sequence to abort.
- Sending 5, 100-byte ICMP Echos to 23.1.1.3, timeout is 2 seconds:
- !!!!!
- Success rate is 100 percent (5/5), round-trip min/avg/max = 76/98/116 ms
show ip inspect查看:
R2#show ip inspect sessions
Established Sessions
Session 682C3818 (12.1.1.1:8)=>(23.1.1.3:0) icmp SIS_OPEN
注意:虽然配置了针对TCP和UDP的检测,但只能单信道的一些协议生效,如果是FTP、SIP等多协议的,还需要对它们进行专门的监测。
配置如下:
R2(config)#ip inspect name outside.inspect ftp
R2(config)#ip inspect name outside.inspect sip
这样配置只能监控FTP默认21端口,假设FTP服务器更改端口为2121则无法监测了。下面引入技术PAM(Port-To-ApplicationMapping),通过这个技术,为应用定义端口号。例如我公司里面21和2121都是FTP,配置如下:
R2(config)#ip port-map ftp port tcp 21 2121
通过show ip port map来查看已有的映射关系。
思科IOS CBAC防火墙现在已有不怎么使用了,IOS Zone-Based Firewall更加灵活好用和专业。