技术原理:
网络地址转换NAT (NetworkAddress Translation),被广泛应用于各种类型Internet接入方式和各种类型的网络中。NAT不仅完美解决了IP地址不足的问题,而且还能够有效地避免来自网络外部攻击,隐藏并保护内部网络的计算机。
默认情况下,内部地址是无法被路由到外网的,内部主机10.1.1.1要与外部Intenet通信,IP包到达NAT路由器时,IP包头的源地址10.1.1.1被替换成一个合法的外网IP,并在NAT转发表中保存这条记录。当外部主机发送一条应答到内网时,NAT路由器收到后,查看当前NAT转换表,用10.1.1.1替换掉这个外网地址。
NAT将网络划分为内部网络和外部网络两个部分,局域网主机利用NAT访问网络时,是将局域网内部的IP地址转换成外网地址后转发数据包;
NAT分为两种类型:NAT(网络地址转换)、NAPT(网络端口地址转换IP地址对应一个全局地址)
静态NAT:实现内部地址与外部地址一对一的映射。现实中,用于服务器;
动态NAT:定义一个地址池,自动映射,也是一对一的。用的比较少;
NAPT:使用不同的端口来映射多个内网IP地址到一个指定的外网IP地址,多对一。
实验步骤及拓扑图:
1.路由器之间通过v.35电缆串口连接,DCE端连接在R1上,配置其时钟频率64000;
2.配置pc机、服务器及路由器接口IP地址;
3.在各个路由器上配置静态路由协议,让PC间能互相通信
4.在R1上配置静态NAT
5.在R1上定义内外网络接口。
6.验证主机之间的互通性
实验设备:
Pc一台;server-pt一台;SWITCH2950他、一台;route-pt2台;交叉线;DCE串口线
R0配置:
Router#configt
Enter configuration commands, one perline. End with CNTL/Z.
Router(config)#host R0
R0(config)#int fa0/0
R0(config-if)#ip address 192.168.1.1255.255.255.0
R0(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0,changed state to up
%LINEPROTO-5-UPDOWN: Line protocol onInterface FastEthernet0/0, changed state to u
R0(config-if)#exit
R0(config)#int se2/0
R0(config-if)#ip address 222.0.1.1255.255.255.0
R0(config-if)#clock rate 64000
R0(config-if)#no shut
%LINK-5-CHANGED: Interface Serial2/0,changed state to down
R0(config-if)#exit
R0(config)#
R1配置:
Router>en
Router#config t
Enter configuration commands, one perline. End with CNTL/Z.
Router(config)#host R1
R1(config)#int fa0/0
R1(config-if)#ip address 222.0.2.1255.255.255.0
R1(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0,changed state to up
%LINEPROTO-5-UPDOWN: Line protocol onInterface FastEthernet0/0, changed state to up
R1(config-if)#exit
R1(config)#int se2/0
R1(config-if)#ip address 222.0.1.2255.255.255.0
R1(config-if)#no shut
R1(config-if)#
%LINK-5-CHANGED: Interface Serial2/0,changed state to up
exit
R1(config)#
%LINEPROTO-5-UPDOWN: Line protocol onInterface Serial2/0, changed state to up
在R0上配置静态路由:
R0(config)#ip route 222.0.2.0 255.255.255.0222.0.1.2
在R1上配置静态路由:
R1(config)#ip route 192.168.1.0255.255.255.0 222.0.1.1
Pc上测试:
C>ping 192.168.1.2
Pinging 192.168.1.2 with 32 bytes of data:
Reply from 192.168.1.2: bytes=32 time=70msTTL=126
Reply from 192.168.1.2: bytes=32 time=80msTTL=126
Reply from 192.168.1.2: bytes=32 time=80msTTL=126
Reply from 192.168.1.2: bytes=32 time=70msTTL=126
Ping statistics for 192.168.1.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 70ms, Maximum = 80ms, Average = 75ms
配置NAT:
R0(config)#int fa0/0
R0(config-if)#ip nat inside
R0(config-if)#exit
R0(config)#int se2/0
R0(config-if)#ip nat outside
R0(config-if)#exit
R0(config)#ip nat inside source static192.168.1.2 222.0.1.3
R0(config)#exit
R0#
%SYS-5-CONFIG_I: Configured from console byconsole
R0#sh ip nat translation
Pro Inside global Insidelocal Outside local Outside global
--- 222.0.1.3 192.168.1.2 --- ---
Pc测试:
PC>ping 222.0.1.3
Pinging 222.0.1.3 with 32 bytes of data:
Reply from 222.0.1.3: bytes=32 time=72msTTL=126
Reply from 222.0.1.3: bytes=32 time=70msTTL=126
Reply from 222.0.1.3: bytes=32 time=80msTTL=126
Reply from 222.0.1.3: bytes=32 time=80msTTL=126
Ping statistics for 222.0.1.3:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times inmilli-seconds:
Minimum = 70ms, Maximum = 80ms, Average = 75ms
本文转自 zhuxtqw 51CTO博客,原文链接:http://blog.51cto.com/1054054/1254787,如需转载请自行联系原作者