2.6-NAT
网络地址转换协议NAT(Network Address Translation):
交换和远程都要用,先上什么就放在哪一块讲,具体来说NAT还是属于远程的。
NAT的三组概念:
-----------------------------------------------------------------

-----------
LAB1:NAT的基本配置(原理性的NAT):
STEP1:按图构建拓朴:
R2/R4配置为PC模拟用户,R5的环回路口模拟公网;宣告RIP网络时不宣告192.168.1.0/24网段,这是因为现实中私网地址是不会被宣告到公网中的;R5可以宣告所有,公网的边界路由器R3上则宣告35.0.0.0/24网段和13.0.0.3/24接口;
STEP2:在私网的边缘路由器上做指向公网的默认静态路由:
R1(c)#ip route 0.0.0.0 0.0.0.0 serial 1 ;
STEP3:在PC上指定网关:
(c)#ip default-gateway 192.168.1.1然后Ping确认能与网关通讯;这个时候PC2/PC4能够将包发往R5,但是R5上没有到PC2/PC4的路由(没有宣告)所以无法回包;现实中的ISP会在路由器上做ACL将私网地址过滤掉,所以PC2/PC4的包也不能到R5;
STEP4:在公网边界路由器配置ACL过滤私网地址:
首先过滤私网地址:(c)#access-list 1 deny 10.0.0.0 0.255.255.255 →access-list 1 deny 192.168.0.0 0.0.255.255→access-list 1 deny 172.16.0.0 0.15.255.255 →access-list 1 permit any any →int s0(在ISP连接用户的路由器接口上调用) →ip access-group 1 in ;
然后允许ISP卖出的地址连入:(c)#access-list 13 permit 13.0.0.0 →router-map R-13 permit 10 →match ip add 13 →set metric 1 →router rip(要重分布)→redistribute connected route-map R-13 ;
STEP5:配置NAT:
注意实验需求要在私网边界内口关闭ARP:(c)#int e0 →no ip proxy-arp ;
然后配置NAT的内/外口:(c-i)#ip nat inside/outside ;
接着配置NAT地址转换公网地址:(c)#ip nat inside(我方) source(所发起的) static 192.168.1.2(私网地址) 13.0.0.10(公网地址);
STEP6:一些查看命令:
R1#show ip nat translations(察看NAT的转换表);
R1#debug ip nat (察看NAT的转换过程)的结果:
发送:s=192.l68.1.2->13.0.0.10 d=5.5.5.5 ;
接收:s=5.5.5.5 d=13.0.0.10->192.168.1.2 ;
结论:静态NAT不实用,PC4也要做NAT,如果用户多的话,要购买相当多的NAT公网地址。
------------------------------------------------------------

----------------
LAB2:中小型企业通常使用基于接口的端口复用(Overload):
STEP1:定义NAT的外口/内口:
……(同LAB1);
STEP2:通过ACL,定义准备进行NAT的内网的用户群:
(c)#access-list 1 permit 192.168.1.0 0.0.0.255 ;
STEP3:进行基于接口的NAT端口复用:
(c)#ip nat inside source list 1(通过ACL指定内网用户) interface serial 1(NAT外口) overload(端口复用:新IOS里面默认启用) ;
测试:实现了192.168.1.*整个网段的用户共享一个IP地址连接到Internet。
----------------------------------------------------------------------------
LAB3:使用Route-Map做基于接口的端口复用:
STEP1:定义NAT的外口/内口,定义内网用户群:
……(同LAB2);
STEP2:使用Route-map调用ACL:
(c)#route-map X →match ip address 1 ;
STEP3:进行基于接口的NAT端口复用:
(c)#ip nat inside source route-map X interface serial 1 overload ;
测试:实现了192.168.1.*整个网段的用户共享一个IP地址连接到Internet。
----------------------------------------------------------------------------
LAB4:大型企业用较多的公网IP利用POOL对不同的部门进行NAT转换:
STEP1:构建拓朴并定义NAT的外口/内口:
修改IP后……(同LAB3);
STEP2:通过ACL,定义准备进行NAT的内网的用户群:
(c)#access-list 10 permit 192.168.10.0 0.0.0.255 →access-list 20 permit 192.168.20.0 0.0.0.255 ;
STEP3:在PC上指定网关:
实际工作中不需要此步,但是实验中为了更全面的了解课程内容所以关闭了ARP就要配了;
首先为各个网段配置同一网段的网关IP,可以使用secondaryIP或者子接口配置:(c)#in e0 →ip add 192.168.10.1 255.255.255.0 →ip add 192.168.20.1 255.255.255.0 secondary ;
然后在PC设定网关:(c)#ip default-gateway 网关IP ;注意养成好习惯:PC2/PC4都要测试能否ping通自己的网关!!!!!
STEP5:在私网边界路由器将从ISP买到的公网IP放入地址池(pool):
掩码可以使用两种格式,这是等价的:(c)#ip nat pool PL-A 13.0.0.8(起始IP) 13.0.0.11(终止IP) prefix-length 24/netmask 255.255.255.0(IP长度:ISP给定) →ip nat pool PL-B 13.0.0.12 13.0.0.0.15 prefix-length 24 ;
STEP6:为不同的部门进行基于不同POOL的NAT转换:
(c)#ip nat inside source list 10 pool PL-A overload →ip nat inside source list 20 pool PL-B overload ;
然后可以用一些命令查看:R1#sh ip nat translation ;
STEP7:在公网边界路由器的操作:
为了让R5有回包路由,在R3上重分布静态路由到RIP中:
(c)#ip route 100.0.0.0 255.255.255.248 13.0.0.1 (定义静态路由)→ip prefix-list 100 permit 100.0.0.8/29 →route-map R-100 →match ip add prefix-list 100 →set metric 1 (定义重分布的范围)→route rip →redistribute static route-map R-100 (重分布);
然后观察:R5#sh ip route rip可读到100.0.0.8/29 。
-----------------------------------------------------

-----------------------
LAB5:通过NAT实现镜像服务器的负载均衡(实际工程少用→了解即可):
STEP1:定义NAT外口/内口:
同LAB4;实验需求:公网上能访问这两台服务器,而且负载均衡地到PC2/4;
STEP2:通过ACL定义我方公网地址成为来自外网访问的目标地址:
(c)#access-list 10 permit 13.0.0.10 0.0.0.0(精确匹配,只转换一个地址);
STEP3:定义内网服务器群的地址池:
(c)#ip nat pool pl 192.168.10.2 192.168.10.3 prefix-length 24 type rotary(轮转类型) ;
STEP4:定义NAT:
(c)#ip nat inside destination list 10 pool pl ;
STEP5:为了实验目的:
PC上:(c)#line vty 0 4 →no login (不需要密码就可以被TELNET→危险→现实请谨慎);
然后在R5上:(c)#telnet 13.0.0.10 可以看到是轮流的。
----------------------------------------------------------------------------
LAB6:使用一个接口的公网IP对外提供多个不同的服务器:
STEP1:定义NAT外口/内口:
同LAB5;注意:静态的TCP端口映射,静态的端口复用;
拓朴使用一个接口的公网IP对外网提供多个不同的服务器:如果你向访问我的FTP(TCP10000号端口或21口)或者WWW服务器(20000号端口或80口);
STEP2:在私网边界路由器构建服务器:
FTP服务器:(c)#ip nat inside source static tcp 192.168.10.2 21 13.0.0.1 21 ;
WWW服务器:(c)#ip nat inside source static tcp 192.168.10.4 80 13.0.0.1 80 ;
∵没有服务器∴实验中无法达成;
实验中可以把私网端口改为23号端口代替(公网端口不要改):
FTP服务器:(c)#ip nat inside source static tcp 192.168.10.2 13.0.0.1 21 ;
WWW服务器:(c)#ip nat inside source static tcp 192.168.10.4 13.0.0.1 80 ;
R1:(c)#line vty 0 4 →no login ;
R5:(c)#TELNET 13.0.0.1(进入了R1,无端口号) →telnet 13.0.0.1 21 (进入了FTP服务器) →telnet 13.0.0.1 80 (进入了WWW服务器);

r1(config)#do sh run
Building configuration...
Current configuration : 737 bytes
!
version 12.2
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname r1
!
logging queue-limit 100
!
ip subnet-zero
no ip domain lookup
!
!
!
!
interface Ethernet0
ip address 10.1.1.1 255.255.255.0
ip nat inside
!
interface Serial0
no ip address
shutdown
!
interface Serial1
ip address 13.1.1.1 255.255.255.0
ip nat outside
!
ip nat inside source list 1 interface Serial1 overload
no ip http server
ip classless
ip route 192.168.1.0 255.255.255.0 Serial0
ip route 192.168.1.0 255.255.255.0 Serial1
!
!
!
access-list 1 permit 2.2.2.0 0.0.0.255
access-list 1 permit 10.1.1.0 0.0.0.255
!
!
line con 0
exec-timeout 0 0
logging synchronous
line aux 0
line vty 0 4
!
end
静态NAT配置
ip nat inside static source-IP des-IP
指定什么端口是inside什么是outside
int e 0
ip nat inside
int s 0
ip nat outside
动态NAT配置
#ip nat pool "name" "start-ip" "end-ip"(只有公网地址作池才有意义)mask x.x.x.x
access-list "access-list-number" permit source [source-wildcard]
ip nat inside source list
example:
ip nat pool ccna 12.1.1.4 12.1.1.5 mask 255.255.255.0
ip access-list standard NAT
r1(config-std-nacl)permit 10.1.1.4 0.0.0.1
ip nat inside source list NAT POOL CCNA
clear ip nat translations * 清空nat表,让地址池重置
Overloading端口复用PAT--主流应用
router(config)#access-list access-list-number permit source source-wildcard
ip nat source list NAT interface serial 0 overload
sh ip nat translation
sh ver:35
Switch#sh ver
Cisco IOS Software, C3550 Software (C3550-IPSERVICESK9-M), Version 12.2(25)SEE1, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Mon 22-May-06 08:08 by yenanh
Image text-base: 0x00003000, data-base: 0x00DC0370
ROM: Bootstrap program is C3550 boot loader
Switch uptime is 5 minutes
System returned to ROM by power-on
System image file is "flash:/c3550-ipservicesk9-mz.122-25.SEE1.bin"
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
export@cisco.com.
Cisco WS-C3550-48 (PowerPC) processor (revision H0) with 65526K/8192K bytes of memory.
Processor board ID CAT0733Z2K3
Last reset from warm-reset
Running Layer2/3 Switching Image
Ethernet-controller 1 has 12 Fast Ethernet/IEEE 802.3 interfaces
Ethernet-controller 2 has 12 Fast Ethernet/IEEE 802.3 interfaces
Ethernet-controller 3 has 12 Fast Ethernet/IEEE 802.3 interfaces
Ethernet-controller 4 has 12 Fast Ethernet/IEEE 802.3 interfaces
Ethernet-controller 5 has 1 Gigabit Ethernet/IEEE 802.3 interface
Ethernet-controller 6 has 1 Gigabit Ethernet/IEEE 802.3 interface
48 FastEthernet interfaces
2 Gigabit Ethernet interfaces
The password-recovery mechanism is enabled.
384K bytes of flash-simulated NVRAM.
Base ethernet MAC Address: 00:0D:BD:CF:FA:00
Motherboard assembly number: 73-5701-09
Power supply part number: 34-0967-01
Motherboard serial number: CAT07330AHT
Power supply serial number: DTH07310QPW
Model revision number: H0
Motherboard revision number: A0
Model number: WS-C3550-48-SMI
System serial number: CAT0733Z2K3
Configuration register is 0x10F
sh ver:29
Switch(config)#do sh ver
Cisco Internetwork Operating System Software
IOS (tm) C2950 Software (C2950-I6K2L2Q4-M), Version 12.1(22)EA10, RELEASE SOFTWARE (fc2)
Copyright (c) 1986-2007 by cisco Systems, Inc.
Compiled Tue 08-May-07 12:18 by myl
Image text-base: 0x80010000, data-base: 0x8067C000
ROM: Bootstrap program is C2950 boot loader
Switch uptime is 9 minutes
System returned to ROM by power-on
System image file is "flash:/c2950-i6k2l2q4-mz.121-22.EA10.bin"
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
export@cisco.com.
cisco WS-C2950-24 (RC32300) processor (revision J0) with 19925K bytes of memory.
Processor board ID FOC0822S11E
Last reset from system-reset
Running Standard Image
24 FastEthernet/IEEE 802.3 interface(s)
32K bytes of flash-simulated non-volatile configuration memory.
Base ethernet MAC Address: 00:0D:28:61:62:00
Motherboard assembly number: 73-5781-11
Power supply part number: 34-0965-01
Motherboard serial number: FOC06500G8M
Power supply serial number: PHI071900ED
Model revision number: J0
Motherboard revision number: A0
Model number: WS-C2950-24
System serial number: FOC0822S11E
Configuration register is 0xF
- Host Only、NAT和Bridge三种网络连接
Host Only.NAT和Bridge三种网络连接 在安装好了Linux镜像之后,如何连接物理机和虚拟机呢?这就需要网络连接,网络连接有三种:HostOnly.NAT.Bridge,它们都可用于Gu ...
- Linux内核参数配置
Linux在系统运行时修改内核参数(/proc/sys与/etc/sysctl.conf),而不需要重新引导系统,这个功能是通过/proc虚拟文件系统实现的. 在/proc/sys目录下存放着大多数的 ...
- linux内核调优参考
对于新部署的机器,需要做一些基本的调优操作,以更改一些默认配置带来的性能问题 1 修改打开文件数 root@mysql:/data/tools/db# vim /etc/security/limits ...
- linux内核参数注释与优化
目录 1.linux内核参数注释 2.两种修改内核参数方法 3.内核优化参数生产配置 参数解释由网络上收集整理,常用优化参数对比了网上多个实际应用进行表格化整理,使查看更直观. 学习linux也有不少 ...
- Linux内核参数基础优化
web 服务负载均衡器常规网站服务器优化的基本配置: net.ipv4.tcp_fin_timeout =2 net.ipv4.tcp_tw_reuse =1 net.ipv4.tcp_tw_recy ...
- 利用端口映射解决:拥有公网IP有限,内网需要访问因特网
动态端口映射: 内网中的一台电脑要访问新浪网,会向NAT网关发送数据包,包头中包括对方(就是新浪网)IP.端口和本机IP.端口,NAT网关会把本机IP.端口替换成自己的公网IP.一个未使用的端口, ...
- (转)linux内核参数注释与优化
linux内核参数注释与优化 原文:http://blog.51cto.com/yangrong/1321594 http://oldboy.blog.51.cto.com/2561410/13364 ...
- Centos内核调优参考
net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_keepalive_time = 600 net.i ...
- linux笔记(1)
1)useradd+用户名 添加一个普通用户2)passwd+密码 为用户加密码3)su - 用户名 切换用户4)whoami 查看当前用户是什么5)$符号是普通用户#是超级用户6)mkdir /da ...
随机推荐
- Elasticsearch索引的操作,利用kibana(如何创建/删除一个es的索引?)
我们已经通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射.现在我们需要对这个建立索引的过程做更多的控制:我们想要确保这个索引有数量适中的主分 ...
- Coursera公开课-Machine_learing:编程作业2
第三周编程作业:Logistic Regression 代码包在gitlab上:https://gitlab.com/luntai/Machine_Learning
- dedecms:解析Robots.txt 协议标准
Robots.txt 是存放在站点根目录下的一个纯文本文件.虽然它的设置很简单,但是作用却很强大.它可以指定搜索引擎蜘蛛只抓取指定的内容,或者是禁止搜索引擎蜘蛛抓取网站的部分或全部内容. 下面我们就来 ...
- Caffe FCN:可视化featureMaps和Weights(C++)、获取FCN结果
为何不使用C++版本FCN获取最后的分割掩模,何必要使用python呢!因此需要获取网络最后层的featureMaps,featureMaps的结果直接对应了segmentation的最终结果,可以直 ...
- Vue项目在IE浏览器报错polyfill-eventsource added missing EventSource to window
已经安装了babel-polyfill,依然报错.
- C#---EF映射MySQL
使用EF CodeFirst连接MySql数据库 如何使用EF CodeFirst连接MySql数据库? 我们这篇文章介绍怎么使用EF连接MySql 作者的环境 VS2017.Win10.MySql5 ...
- Centos初始化硬盘分区、挂载
刚刚买了一台服务器,刚买的服务器的数据盘都是需要自己来分区的,下面就记录一下操作. 通过命令fdisk-l查看硬盘信息 可以看到有两块硬盘/dev/vda和/dev/vdb,启动vda是系统盘vdb是 ...
- 前端领域的BEM到底是什么
前端领域的BEM到底是什么 BEM - Block Element Modfier(块元素编辑器) BEM方法确保每一个参加了同一网站开发项目的人,基于一套代码规范去开发,这样非常有利于团队成员理解彼 ...
- HTML 符号实体
带有实体名称的 ASCII 实体 结果 描述 实体名称 实体编号 " quotation mark " " ' apostrophe ' ' & ...
- sysbench测试阿里云ECS云磁盘的IOPS,吞吐量
测试阿里云ECS 对象:在aliyun上买了一个ECS附加的云盘,使用sysbench测试云盘的IOPS和吞吐量 sysbench prepare 准备文件,10个文件,1个1G [root@iZwz ...