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 ...
随机推荐
- win10 激活方法 (各版本)
很多人都在找Win10专业版永久密钥,其实win10激活码不管版本新旧都是通用的,也就是说一个win10专业版key,可以同时激活windows10专业版1809.1803.1709.1703.160 ...
- ZOJ1969-Hard to Believe, but True!
import re while True: x = raw_input() if(x == '0+0=0'): print 'True' break a,b,c = re.split('[+=]', ...
- 服务器上oracle的监听设置
1.查看本机的计算机名 2.修改etc/host 3.修改oracle的listener.ora(我服务器上的路径:) 4.修改tnsnames.ora(和上边文件一个目录)
- 自定义View(9)使用Renderscript 渲染特效。
1.渲染脚本官网 https://developer.android.com/guide/topics/renderscript/compute 2.高斯模糊 ScriptIntrinsicBlur ...
- hbuilder中的 http://www.w3.org/TR/html4/loose.dtd
<!-- This is the HTML 4.01 Transitional DTD, which includes presentation attributes and elements ...
- HTML 表单 存为EXCEL文件时 中文显示乱码
在做宣传品发放系统时,需求要把数据库查询的记录生成表单并转存excel文件. 在转存的EXCEL文件中文显示乱码,表格和其他字符正常,检查后发现是创建EXCEL文件打开模式不对 之前: myfile ...
- asp.net——登录界面
题目: 在页面中放入两个TextBox分别用于输入用户名和密码,一个显示文字用的Label,一个提交按钮Button.点击按钮提交用户名和密码,如果用户名都密码正确(比如用户名admin 密码abc1 ...
- Java&Xml教程(七)使用JDOM修改XML文件内容
JDOM提供了非常灵活的方式操作XML文件,使用JDOM非常简单而且代码简洁可读性强.前面我们学习了如何使用JDOM解析XML文件,本节介绍如何使用JDOM修改XML文件内容. 在这个教程中,我们准备 ...
- 注释及Scriptlet
1.显式注释 <!--xxxxxx-->,在正常页面上也看不出来,右键鼠标查看源代码可以看到 2.隐式注释 //xxxxx /*xxxxxx*/ <%--xxxxxxx--> ...
- TensorFlow: Could not load requested Qt binding.
使用Eclipse 引入tensorflow,出现 Could not load requested Qt binding. 问题 ImportError: Could not load reque ...