这是一个通过路由器的静态PAT来访问FTP服务器(Server)的测试,把最常见的两种FTP模式(主动模式和被动模式)都要做一遍。可以深入理解日常ftp操作的方法,对处理组网中的传输故障也很有帮助。
1.本方法是在cisco模拟器上完成的,测试的拓扑图很简单就不画出来了,路由器R2(作为ftp客户端)连接路由器R1,再连接一个FTP服务器,其ip地址和端口配置如下:
R2 (FTP Client 202.100.1.2/24)-------------------(202.100.1.2/24) R1 (10.1.1.1/24)---------------------(10.1.1.18/24)FTP Server
2.测试目标:
通过测试,理解FTP的两种模式:被动模式,主动模式
A.被动模式:
command :Client (源端口>tcp 1024) ------>FTP Server (目标端口tcp 21)
data:Client (目标端口>tcp 1024) ------ > FTP Server (源端口>tcp 1024)
B.主动模式:
command :Client (源端口>tcp 1024) ------>FTP Server (目标端口tcp 21)
data:Client (目标端口>tcp 1024) <------ FTP Server (源端口tcp 20)
3.基本配置:
R1:
config t
interface Ethernet0/0
ip address 202.100.1.1 255.255.255.0
no shutdown
interface Ethernet0/1
ip address 10.1.1.1 255.255.255.0
no shutdown
R2:
config t
interface Ethernet0/0
ip address 202.100.1.2 255.255.255.0
no shutdown
FTP服务器:
IP:10.1.1.18/25
GW:10.1.1.1
4.R1路由器PAT配置:
A.先只配置静态PAT
config t
interface Ethernet0/0
ip nat outside
interface Ethernet0/1
ip nat inside
ip nat inside source static tcp 10.1.1.18 21 interface e0/0 21
B.查看静态PAT设置
R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
tcp 202.100.1.1:21 10.1.1.18:21 --- ---
5.FTP访问测试:
①FTP被动模式测试
A.R2作为FTP客户端配置FTP客户端为被动模式:
config t
ip ftp passive
----备注:思科路由器默认采用的是被动模式,可以不用敲
B.R2作为FTP客户端配置FTP用户名密码:
config t
ip ftp username xll
ip ftp password 1234qwer
B.R2作为客户端可以成功拷贝文件:
R2#copy ftp://202.100.1.1 flash:
Address or name of remote host [202.100.1.1]?
Source filename [watch.sh]?
Destination filename [watch.sh]?
%Warning:There is a file already existing with this name
Do you want to over write? [confirm]
Accessing ftp://202.100.1.1/watch.sh...
Erase flash: before copying? [confirm]
Erasing the flash filesystem will remove all files! Continue? [confirm]
Erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased
Erase of flash: complete
Loading watch.sh !
[OK - 986/4096 bytes]
Verifying checksum... OK (0xE972)
986 bytes copied in 7.492 secs (132 bytes/sec)
C.在文件拷贝过程中,在R1查看NAT转换:
R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
tcp 202.100.1.1:21 10.1.1.18:21 202.100.1.2:30662 202.100.1.2:30662
tcp 202.100.1.1:21 10.1.1.18:21 202.100.1.2:35984 202.100.1.2:35984
tcp 202.100.1.1:21 10.1.1.18:21 202.100.1.2:46087 202.100.1.2:46087
tcp 202.100.1.1:21 10.1.1.18:21 202.100.1.2:48529 202.100.1.2:48529
tcp 202.100.1.1:21 10.1.1.18:21 --- ---
tcp 202.100.1.1:1576 10.1.1.18:1576 202.100.1.2:28656 202.100.1.2:28656
tcp 202.100.1.1:1577 10.1.1.18:1577 202.100.1.2:30584 202.100.1.2:30584
tcp 202.100.1.1:1578 10.1.1.18:1578 202.100.1.2:48461 202.100.1.2:48461
-----可出看出:在对外映射的时侯采用了21端口,IOS会自动识别这个端口是FTP控制口,
从而去检查里面FTP数据控制数据发现服务器告诉客户端的这个用于传送数据的端口,然后自动的添加映射。
②FTP主动模式测试
A.R2作为FTP客户端配置FTP客户端为主动模式:
config t
no ip ftp passive
B.R2作为FTP客户端配置FTP用户名密码:
--同上步
B.R2作为客户端可以成功拷贝文件,
R2#debug ip ftp
*Mar 1 01:00:05.831: %SYS-5-CONFIG_I: Configured from console by console
R2#copy ftp://202.100.1.1 flash:
Address or name of remote host [202.100.1.1]?
Source filename [watch.sh]?
Destination filename [watch.sh]?
%Warning:There is a file already existing with this name
Do you want to over write? [confirm]
Accessing ftp://202.100.1.1/watch.sh...
*Mar 1 01:00:14.627: FTP: 220 3Com 3CDaemon FTP Server Version 2.0
*Mar 1 01:00:14.627: FTP: ---> USER xll
*Mar 1 01:00:15.211: FTP: 331 User name ok, need password
*Mar 1 01:00:15.215: FTP: ---> PASS 1234qwer
*Mar 1 01:00:15.759: FTP: 230 User logged in
*Mar 1 01:00:15.759: FTP: ---> TYPE I
D.再次拷贝文件,可以成功
R2#copy ftp://202.100.1.1 flash:
Source filename []? watch.sh
Destination filename [watch.sh]?
%Warning:There is a file already existing with this name
Do you want to over write? [confirm]
Accessing ftp://202.100.1.1/watch.sh...
Erase flash: before copying? [confirm]
Erasing the flash filesystem will remove all files! Continue? [confirm]
Erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased
Erase of flash: complete
Loading watch.sh !
[OK - 986/4096 bytes]
Verifying checksum... OK (0xE972)
986 bytes copied in 7.704 secs (128 bytes/sec)
R2#
----从R2上tcp 20的抓包来看,tcp三次握手是由FTP服务器发起的:
R2#debug ip tcp packet port 20
TCP Packet debugging is on for port number 20
*Mar 1 00:57:00.967: tcp0: I LISTEN 202.100.1.1:20 202.100.1.2:21993 seq 84304373
OPTS 24 SYN WIN 65535
*Mar 1 00:57:00.971: tcp0: O SYNRCVD 202.100.1.1:20 202.100.1.2:21993 seq 2180803741
OPTS 4 ACK 84304374 SYN WIN 8192
*Mar 1 00:57:01.035: tcp0: I SYNRCVD 202.100.1.1:20 202.100.1.2:21993 seq 84304374
ACK 2180803742 WIN 65535
*Mar 1 00:57:01.039: tcp0: I ESTAB 202.100.1.1:20 202.100.1.2:21993 seq 84304374
DATA 986 ACK 2180803742 PSH WIN 65535
*Mar 1 00:57:01.043: tcp0: I ESTAB 202.100.1.1:20 202.100.1.2:21993 seq 84305360
ACK 2180803742 FIN WIN 65535
---在路由器上可以通debug ip ftp查看完整的FTP过程,可以看到客户端是否采用主动模式取决于客户端是否会发出PASV命令
6.修改FTP端口:
如果修改FTP服务器的端口为2121,在路由器配置静态NAT如下:
ip nat inside source static tcp 10.1.1.18 2121 interface Ethernet0/0 21
此时如果FTP客户端采用FTP主动模式与FTP服务器连接是没有问题的,
但是如果采用FTP被动模式,因为R1作为NAT设备没有临时设置静态PAT,导致客户端连接服务器的数据端口失败,因此需要在R1上配置告诉R1路由器FTP服务器的端口。
access-list 20 permit 10.1.1.18
ip nat service list 20 ftp tcp port 2121
Copyright ©2017-2021 武汉市朗联科技有限公司 鄂ICP备案号17020357