2022年网络地址转换的简介文件 .pdf
网络地址转换(NAT)的简介首先,要了解NAT 是一个过程,而不是一个结构化协议!1、IP NAT 术语内部本地网络指的是连接到属于私有LAN 的路由器接口的网络。对于内部网络中的主机发送到外部目的地的分组,必须对其中的IP地址进行转换。外部全局网络指的是与LAN 外部的路由器相连的网络,它们不能识别LAN 中主机的私有地址。内部本地地址指的是内部网络主机配置的私有IP 地址。使用这种地址的分组离开内部网络前,必须对其地址进行转换。内部全局地址指的是外部网络看到的内部主机的IP 地址,这是转换后的IP地址。外部本地地址是本地网络发送分组时使用的目标地址,它通常与外部全局地址相同。外部全局地址是外部主机实际使用的公有IP 地址,这种地址是从全局可路由地址空间分配的。2、静态和动态NAT 使用 NAT 的优点之一是,无法从公共Internet 直接访问主机。然而,如果需要从Internet 访问内部网络中一台或多台主机运行的服务以及其他设备,该怎么办呢?从 Internet 访问本地主机,方法之一是给该设备指定静态地址转换。静态转换可确保特定主机的私有 IP地址总是转换为同一个全局IP地址,还将确保其他本地主机的IP地址不会转换为该注册地址。这称为静态NAT。动态 NAT 指的是路由器被配置成动态地给内部私有网络设备分配全局地址池中的IP地址。只要会话没有关闭,路由器就将监控该内部全局地址,并向发起会话的内部设备发送确认。会话结束时,路由器将内部全局地址归还到地址池。动态 NAT 让内联网中使用私有IP地址的主机能够访问公共网络(如Internet);而静态NAT 让公共网络中的主机能够访问私有网络中的特定主机。这意味着配置NAT 以便用户能够访问外部网络时,应配置动态NAT;如果希望外部主机能够访问内部网络中的设备,应使用静态NAT。必要时,可同时部署这两种NAT 方法。3、基于端口的网络地址转换(PAT)如果机构注册的IP地址池很小甚至只有一个IP地址,仍可以通过NAT 重载(端口地址转换(PAT)机制,使多个用户可以同时访问公共网络。PAT将多个本地地址转换为一个全局IP地址。当源主机向目标主机发送消息时,将结合使用IP地址和端口号来跟踪与目标主机的会话。在PAT中,网关将分组中本地源地址和端口转换为一个全局IP地址和大于1024 的端口号。虽然所有主机的IP 地址都将转换为同一个全局IP地址,但与会话相关联的端口号是唯一的。响应数据流将发送到转换后的IP 地址和主机使用的端口。路由器有一个表,其中列出了被转换为外部地址的内部IP地址和端口号组合。响应数据流被发送到外部地址,然后被转发到合适的内部地址和端口号。由于可用的端口超过64000 个,因此路由器不太可能耗尽端口号。4、以下是实验实例:名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 11 页 -(一)静态 NAT R1#sh run Building configuration.Current configuration:943 bytes!version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption!hostname R1!boot-start-marker boot-end-marker!no aaa new-model memory-size iomem 5 ip cef!multilink bundle-name authenticated!名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 11 页 -!interface FastEthernet0/0 ip address 10.39.140.1 255.255.255.0 ip nat inside ip virtual-reassembly duplex auto speed auto!interface FastEthernet0/1 ip address 221.100.100.1 255.255.255.0 ip nat outside ip virtual-reassembly duplex auto speed auto!ip route 221.100.200.0 255.255.255.0 FastEthernet0/0!ip http server no ip http secure-server ip nat inside source static 10.39.140.2 221.100.200.2 ip nat inside source static 10.39.140.3 221.100.200.3 ip nat inside source static 10.39.140.4 221.100.200.4!no cdp run!control-plane!line con 0 logging synchronous transport preferred none 名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 11 页 -line aux 0 line vty 0 4!end R1#sh ip na R1#sh ip nat%Incomplete command.R1#sh ip nat?nvi NVI information statistics Translation statistics translations Translation entries R1#sh ip nat s R1#sh ip nat statistics Total active translations:3(3 static,0 dynamic;0 extended)Outside interfaces:FastEthernet0/1 Inside interfaces:FastEthernet0/0 Hits:29 Misses:65 CEF Translated packets:93,CEF Punted packets:0 Expired translations:66 Dynamic mappings:Queued Packets:0 R1#sh ip nat t R1#sh ip nat translations Pro Inside global Inside local Outside local Outside global-221.100.200.2 10.39.140.2-221.100.200.3 10.39.140.3-221.100.200.4 10.39.140.4-R1#sh ip rou R1#sh ip route Codes:C-connected,S-static,R-RIP,M-mobile,B-BGP D-EIGRP,EX-EIGRP external,O-OSPF,IA-OSPF inter area N1-OSPF NSSA external type 1,N2-OSPF NSSA external type 2 E1-OSPF external type 1,E2-OSPF external type 2 i-IS-IS,su-IS-IS summary,L1-IS-IS level-1,L2-IS-IS level-2 ia-IS-IS inter area,*-candidate default,U-per-user static route o-ODR,P-periodic downloaded static route Gateway of last resort is not set 名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 11 页 -C 221.100.100.0/24 is directly connected,FastEthernet0/1 S 221.100.200.0/24 is directly connected,FastEthernet0/0 10.0.0.0/24 is subnetted,1 subnets C 10.39.140.0 is directly connected,FastEthernet0/0 R1#*Mar 1 00:18:26.431:NAT*:s=10.39.140.3-221.100.200.3,d=221.100.100.2 61198*Mar 1 00:18:27.079:NAT*:s=10.39.140.3-221.100.200.3,d=221.100.100.2 61454*Mar 1 00:18:27.151:NAT*:s=221.100.100.2,d=221.100.200.3-10.39.140.3 61454 R1#*Mar 1 00:18:27.823:NAT*:s=10.39.140.3-221.100.200.3,d=221.100.100.2 61710*Mar 1 00:18:27.919:NAT*:s=221.100.100.2,d=221.100.200.3-10.39.140.3 61710*Mar 1 00:18:28.567:NAT*:s=10.39.140.3-221.100.200.3,d=221.100.100.2 61966*Mar 1 00:18:28.687:NAT*:s=221.100.100.2,d=221.100.200.3-10.39.140.3 61966 R1#*Mar 1 00:18:29.263:NAT*:s=10.39.140.3-221.100.200.3,d=221.100.100.2 62222*Mar 1 00:18:29.407:NAT*:s=221.100.100.2,d=221.100.200.3-10.39.140.3 62222*Mar 1 00:18:29.983:NAT*:s=10.39.140.3-221.100.200.3,d=221.100.100.2 62478*Mar 1 00:18:30.059:NAT*:s=221.100.100.2,d=221.100.200.3-10.39.140.3 62478 VPCS 2 p 221.100.100.2 221.100.100.2 icmp_seq=1 timeout 221.100.100.2 icmp_seq=2 time=218.000 ms 221.100.100.2 icmp_seq=3 time=235.000 ms 221.100.100.2 icmp_seq=4 time=312.000 ms 221.100.100.2 icmp_seq=5 time=329.000 ms VPCS 2 sh NAME IP/CIDR GATEWAY LPORT RPORT PC1 10.39.140.2/24 10.39.140.1 10001 21001 PC2 10.39.140.3/24 10.39.140.1 10002 21002 PC3 10.39.140.4/24 10.39.140.1 10003 21003 PC4 0.0.0.0/0 0.0.0.0 10004 30003 PC5 0.0.0.0/0 0.0.0.0 10005 30004 PC6 0.0.0.0/0 0.0.0.0 10006 30005 PC7 0.0.0.0/0 0.0.0.0 10007 30006 PC8 0.0.0.0/0 0.0.0.0 10008 30007 PC9 0.0.0.0/0 0.0.0.0 10009 30008(二)动态 NAT 原图在 R1 上配置动态NAT,由于 ACL的设置,导致PC3无法 PING通 R2 的 F0/0 端口:R1#sh run Building configuration.名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 11 页 -Current configuration:920 bytes!version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption!hostname R1!boot-start-marker boot-end-marker!no aaa new-model memory-size iomem 5 ip cef!multilink bundle-name authenticated!interface FastEthernet0/0 ip address 10.39.140.1 255.255.255.0 ip nat inside ip virtual-reassembly duplex auto speed auto!interface FastEthernet0/1 ip address 221.100.100.1 255.255.255.0 ip nat outside 名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 11 页 -ip virtual-reassembly duplex auto speed auto!ip route 221.100.200.0 255.255.255.0 FastEthernet0/0!ip http server no ip http secure-server ip nat pool jxw 221.100.200.2 221.100.200.4 prefix-length 24 ip nat inside source list 1 pool jxw!access-list 1 permit 10.39.140.2 0.0.0.1 no cdp run!control-plane!line con 0 logging synchronous transport preferred none line aux 0 line vty 0 4!end R1#sh ip nat st R1#sh ip nat statistics Total active translations:2(0 static,2 dynamic;0 extended)Outside interfaces:FastEthernet0/1 Inside interfaces:FastEthernet0/0 Hits:58 Misses:95 CEF Translated packets:152,CEF Punted packets:0 Expired translations:96 Dynamic mappings:-Inside Source 名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 11 页 -Id:1 access-list 1 pool jxw refcount 2 pool jxw:netmask 255.255.255.0 start 221.100.200.2 end 221.100.200.4 type generic,total addresses 3,allocated 2(66%),misses 0 Queued Packets:0 VPCS 1 sh NAME IP/CIDR GATEWAY LPORT RPORT PC1 10.39.140.2/24 10.39.140.1 10001 21001 PC2 10.39.140.3/24 10.39.140.1 10002 21002 PC3 10.39.140.4/24 10.39.140.1 10003 21003 PC4 0.0.0.0/0 0.0.0.0 10004 30003 PC5 0.0.0.0/0 0.0.0.0 10005 30004 PC6 0.0.0.0/0 0.0.0.0 10006 30005 PC7 0.0.0.0/0 0.0.0.0 10007 30006 PC8 0.0.0.0/0 0.0.0.0 10008 30007 PC9 0.0.0.0/0 0.0.0.0 10009 30008 VPCS 1 p 221.100.100.2 221.100.100.2 icmp_seq=1 time=375.000 ms 221.100.100.2 icmp_seq=2 time=313.000 ms 221.100.100.2 icmp_seq=3 time=250.000 ms 221.100.100.2 icmp_seq=4 time=250.000 ms 221.100.100.2 icmp_seq=5 time=297.000 ms VPCS 2 p 221.100.100.2 221.100.100.2 icmp_seq=1 time=390.000 ms 221.100.100.2 icmp_seq=2 time=203.000 ms 221.100.100.2 icmp_seq=3 time=390.000 ms 221.100.100.2 icmp_seq=4 time=360.000 ms 221.100.100.2 icmp_seq=5 time=343.000 ms VPCS 3 p 221.100.100.2 221.100.100.2 icmp_seq=1 timeout 221.100.100.2 icmp_seq=2 timeout 221.100.100.2 icmp_seq=3 timeout 221.100.100.2 icmp_seq=4 timeout 221.100.100.2 icmp_seq=5 timeout R1#sh ip nat tran Pro Inside global Inside local Outside local Outside global icmp 221.100.200.3:57619 10.39.140.2:57619 221.100.100.2:57619 221.100.100.2:57619 icmp 221.100.200.3:57875 10.39.140.2:57875 221.100.100.2:57875 221.100.100.2:57875 名师资料总结-精品资料欢迎下载-名师精心整理-第 8 页,共 11 页 -icmp 221.100.200.3:58131 10.39.140.2:58131 221.100.100.2:58131 221.100.100.2:58131 icmp 221.100.200.3:58387 10.39.140.2:58387 221.100.100.2:58387 221.100.100.2:58387-221.100.200.3 10.39.140.2-221.100.200.2 10.39.140.3-R1#sh ip nat tran Pro Inside global Inside local Outside local Outside global icmp 221.100.200.3:57619 10.39.140.2:57619 221.100.100.2:57619 221.100.100.2:57619 icmp 221.100.200.3:57875 10.39.140.2:57875 221.100.100.2:57875 221.100.100.2:57875 icmp 221.100.200.3:58131 10.39.140.2:58131 221.100.100.2:58131 221.100.100.2:58131 icmp 221.100.200.3:58387 10.39.140.2:58387 221.100.100.2:58387 221.100.100.2:58387 icmp 221.100.200.3:58643 10.39.140.2:58643 221.100.100.2:58643 221.100.100.2:58643 icmp 221.100.200.3:58899 10.39.140.2:58899 221.100.100.2:58899 221.100.100.2:58899-221.100.200.3 10.39.140.2-icmp 221.100.200.2:61459 10.39.140.3:61459 221.100.100.2:61459 221.100.100.2:61459 icmp 221.100.200.2:61715 10.39.140.3:61715 221.100.100.2:61715 221.100.100.2:61715-221.100.200.2 10.39.140.3 R1#sh run Building configuration.Current configuration:920 bytes!version 12.4 service timestamps debug datetime msec service timestamps log datetime msec no service password-encryption!hostname R1!boot-start-marker boot-end-marker!no aaa new-model memory-size iomem 5 ip cef!multilink bundle-name authenticated!名师资料总结-精品资料欢迎下载-名师精心整理-第 9 页,共 11 页 -!interface FastEthernet0/0 ip address 10.39.140.1 255.255.255.0 ip nat inside ip virtual-reassembly duplex auto speed auto!interface FastEthernet0/1 ip address 221.100.100.1 255.255.255.0 ip nat outside ip virtual-reassembly duplex auto speed auto!ip route 221.100.200.0 255.255.255.0 FastEthernet0/0!ip http server no ip http secure-server ip nat pool jxw 221.100.200.2 221.100.200.4 prefix-length 24 ip nat inside source list 1 pool jxw!access-list 1 permit 10.39.140.2 0.0.0.1 no cdp run!control-plane!line con 0 logging synchronous 名师资料总结-精品资料欢迎下载-名师精心整理-第 10 页,共 11 页 -transport preferred none line aux 0 line vty 0 4!end R1#sh ip nat s Total active translations:2(0 static,2 dynamic;0 extended)Outside interfaces:FastEthernet0/1 Inside interfaces:FastEthernet0/0 Hits:88 Misses:125 CEF Translated packets:212,CEF Punted packets:0 Expired translations:126 Dynamic mappings:-Inside Source Id:1 access-list 1 pool jxw refcount 2 pool jxw:netmask 255.255.255.0 start 221.100.200.2 end 221.100.200.4 type generic,total addresses 3,allocated 2(66%),misses 0 Queued Packets:0(三)复用在动态 NAT 基础上R1(config)#ip nat inside source list 1 pool jxw overload 具体不再累述,Over!名师资料总结-精品资料欢迎下载-名师精心整理-第 11 页,共 11 页 -