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 ...
随机推荐
- Android 自己搭建一个直播系统吧
服务端用 SRS(Simple Rtmp Server),在这里下载simple-rtmp-server需要Linux系统最好是Ubuntu,装个Ubuntu虚拟机就行了在Linux里,解压缩SRS ...
- Jupyter(Ipython) Notebook 入门
upyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 一般用来编写漂亮的交互式文档. 文学编程的读者不是机器,而是人. 我们 ...
- VC使用CryptoAPI计算MD5
// md5.h #include <tchar.h> #include <wincrypt.h> // 计算Hash,成功返回0,失败返回GetLastError() // ...
- 4xx错误的本质:服务器已经接收到请求
4xx错误的本质:服务器已经接收到请求, 路径错误! { URL: http://10.100.138.32:8046/3-0/app/account/maxin } { status code: 4 ...
- CAD创建一个新的图形文件
static void linea(void) { AcDbDatabase *pDb = new AcDbDatabase(true, false); AcGePoint3d pickPoint; ...
- CVPR2016 Paper list
CVPR2016 Paper list ORAL SESSIONImage Captioning and Question Answering Monday, June 27th, 9:00AM - ...
- 4.Linux的进程
4.1 Linux的进程 4.1.1 进程的概述 有关进程的一些基本概念: 1.什么是进程: 当程序被触发后,执行者的权限与属性.程序的程序代码与所需的数据都会被加载到内存中,操作系统并给予这个内存内 ...
- JAVA学习总结-常用数据结构
java中集合框架其实就是数据结构的实现的封装; 参考资料:任小龙教学视频 1,什么是数据结构? 数据结构是计算机存储,组织数据的方式; 数据结构是指相互之间存在一种或多种特定关系的数据元素的集合; ...
- 机器学习中jupyter lab的安装方法以及使用的命令
安装JupyterLab使用pip安装: pip install jupyterlab# 必须将用户级目录添加 到环境变量才能启动pip install --userbinPATHjupyter la ...
- Java基础学习总结(41)——JPA常用注解
JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. JPA由EJB 3.0软件专 ...