NAT(Network Address Translation)
·NAT核心思想:将私网地址转换成公网地址。
NAT technology enables private IP networks that use nonregistered IP addresses to connect to a public network.
·私网地址范围:
10.0.0.0 - 10.255.255.255
172.16.0.0 - 172.31.255.255
192.168.0.0 - 192.168.255.255
·NAT常用于下述情形:
1.没有足够的公网连接到Internet
2.当更换ISP需要重新编址
3.合并两个使用重叠地址空间的内部网络
4.使用单个IP地址支持基本的负载分担
·使用NAT做地址转换时,可以静态的,也可以是动态的
静态:内部地址被预选映射到指定的外部地址,内部地址和外部地址是一一对应的。
动态:内部地址可以使用地址池中的外部地址。
(内部=私网) (外部=公网)
PAT(Port Add translation):多个内部地址共享一个外部地址,通过
端口号多路复用。
·优点:
1.节省了公网IP地址
2.能够处理编址方案重叠的情况
3.网络发生改变时不需要重新编址
4.隐藏了真正的IP地址
·缺点:
1.NAT引起数据交互的延迟
2.导致无法进行端到端的IP跟踪
3.某些应用程序不支持NAT
4.需要消耗额外的CPU和内存
<静态内部源地址转换>
1)配置IP地址,DCE配置时钟,将R2变成PC机(no ip routing)
2)定义NAT的内口/外口
interface Ethernet0/0
ip address 192.168.8.3 255.255.255.0
ip nat inside
interface Serial0/1
ip address 200.1.1.3 255.255.255.0
ip nat outside
3)地址转换(将私网地址转换成已经购买的公网IP地址)
R3(config)#ip nat inside source static 192.168.8.2 200.1.1.2
(inside local)(inside global)
4)配置默认路由:
R3(config)#ip route 0.0.0.0 0.0.0.0 serial 0/1
路由器接口默认开启Proxy ARP
R3(config-if)#no ip proxy-arp (关闭代理ARP)
PC-R2#clear arp-cache (清ARP表项)
5)在PC机上设置默认网关
PC-R2(config)#ip default-gateway 192.168.8.3
如果路由器接口支持Proxy-arp时也可不用设。(对端接口)
R3#show ip nat translations (查看NAT转换表项)
R3#show ip nat statistics (查看NAT的统计信息)
R3#debug ip nat (查看NAT转换信息)
*Mar 1 01:28:14.110: NAT*: s=192.168.8.2->200.1.1.2, d=1.1.1.1
*Mar 1 01:28:14.114: NAT*: s=1.1.1.1, d=200.1.1.2->192.168.8.2
<PAT>
1)新增加一台主机R4,(no ip rouing),设置网关。
2)定义NAT的内口/外口
3)定义可被转换的私网地址
R3(config)#access-list 8 permit 192.168.8.0 0.0.0.255
4)端口复用
ip nat inside source list 8 interface Serial0/1 overload
(access-list) (出去的端口) (端口复用)
5)设置默认路由
show ip nat [translations]在网关上看一些信息,端口号和IP地址的对应关系,本表项一分钟后就会删除
<动态内部源地址转换>
1)将PC-R4改成192.168.9.4/24
在R3上做一个192.168.9.3/24的secondary地址
ip address 192.168.9.3 255.255.255.0 secondary
2)定义NAT的外口/内口
3)定义可被转换的私网地址
R3(config)#access-list 8 permit 192.168.8.0 0.0.0.255
R3(config)#access-list 9 permit 192.168.9.0 0.0.0.255
R3#show ip access-lists (查看访问控制列表)
4)定义地址池(已经购买的IP地址200.1.1.10-200.1.1.15)
ip nat pool POOL-8 200.1.1.10 200.1.1.12 prefix-length 24
(名字)(起始IP) (终结IP) (掩码)
ip nat pool POOL-9 200.1.1.13 200.1.1.15 netmask 255.255.255.0
5)动态映射:
R3(config)#ip nat inside source list 8 pool POOL-8 [overload]
R3(config)#ip nat inside source list 9 pool POOL-9 [overload]
6)配置静态路由
R3#clear ip nat translation * (清NAT转换表项)
(针对Static映射不起效)
<访问内网服务器>
1)将R2、R4模拟成FTP&WEB服务器。
R2、R3、R4还是在同一网段192.168.8.0/24
2)定义NAT的外口/内口
3)配置映射:
ip nat inside source static tcp 192.168.8.2 23 200.1.1.3 10000 extendable
(inside local) (local port) (inside global) (global port任意指定)
ip nat inside source static tcp
192.168.8.4 23 interface serial 0/1 20000
R3(config)#line vty 0 4
R3(config-line)#no login (telnet本路由器时不需密码)
·在R2、R4上的Line vty 0 4 设置无密码(no login)
测试:在R1上
R1#telnet 200.1.1.3 10000 >FTP
R1#telnet 200.1.1.3 20000 >WEB
R3#show ip nat translations
CCIE中的一道题
3.3 IP Masquerading(R6)
Telnet from any (except R3) within your topology to Y.Y.6.254 will result in a connection to R3 lo0 interface IP address, HTTP session originating from any(except R3)within topology to Y.Y.6.254 to R3 s0/0(36.1/24).Do not transition any other connections session between R3 and any other devices in your topology,不创建新interface 使用secoudry 完成这个
36.1->80
int s0/0(36.0/30)
ip nat inside
int e0/0(67.0/24)
ip nat outside
ip nat inside source static tcp 8.8.36.1 80 8.8.6.254 80 extendable
ip nat inside source static tcp 8.8.3.3 23 8.8. 6.254 23 extendable