您的位置:首页 > 其它

cisco路由器NAT地址转换

2010-02-08 08:37 417 查看
很久没有接触NAT地址转换了,我记得有一次在笔试一个做系统集成的公司,其中有一道题就是NAT与PAT的区别。当时对网络基本就没概念,所以只是简单说了一个NAT是地址转换,PAT是端口转换之类的笼统的话。以下的话抄自百度。

PAT叫端口地址转换,NAT是网络地址转换,由RFC 1631定义。
PAT可以看做是NAT的一部分。
在NAT时,考虑一种情形,就是只有一个Public IP,而内部有多个Private IP,这个时候NAT就要通过映射UDP和TCP端口号来跟踪记录不同的会话,比如用户A、B、C同时访问CSDN,则NAT路由器会将用户A、B、C访问分别映射到1088、1098、23100(举例而已,实际上是动态的),此时实际上就是PAT了。
由上面推论,PAT理论上可以同时支持(65535 - 1024)= 64511个连接会话。但实际使用中由于设备性能和物理连接特性是不能达到的,CISCO的路由器NAT功能中每个Public IP最多能有效地支持大约4000个会话。

PAT普遍应用于接入设备中,它可以将中小型的网络隐藏在一个合法的IP地址后面。PATT与动态地址NAT不同,它将内部连接映射到外部网络中的一个单独的IP地址上,同时在该地址上加上一个由NAT设备选定的TCP端口号。也就是采用port multiplexing 技术,或改变外出数据的源port的技术将多个内部ip地址映射到同一个外部地址。

实例思路:
用小凡实现,3个3725路由器,2个PC机。路由器1模拟互联网,路由器2模拟企业的边界路由器,路由器3模拟企业内部交换机。各设备的连接与IP设置详见下图:



具体配置思路:
R1路由器取F1/1的IP为172.30.1.1 ,命令为no sw 第二步为ip add 172.30.1.1.
R2路由器取F1/1的IP为172.30.1.2,F1/2为172.16.1.1,并定义1口为外网口,2口为内网口,写入两个路由至172.16.3.0与172.16.4.0,如果不写路由,则这两个网段无法与外部连接。
R3路由器作交换机,划分三个VLAN,启用VLAN间路由(ip routing)。写入一条静态路由至R2。

下面是具体配置:
R1#sh run
Building configuration...
Current configuration : 1110 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R1
!
boot-start-marker
boot-end-marker
!
no aaa new-model
memory-size iomem 5
ip cef
!
multilink bundle-name authenticated
!
interface FastEthernet0/0
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet1/0
!
interface FastEthernet1/1
no switchport
ip address 172.30.1.1 255.255.255.0
!
interface FastEthernet1/2
!
interface FastEthernet1/3
!
interface FastEthernet1/4
!
interface Vlan1
no ip address
!
ip http server
no ip http secure-server
!
!
control-plane
!
line con 0
exec-timeout 0 0
line aux 0
line vty 0 4
login
!
!
end
R1#
===============
R2#sh run
Building configuration...
Current configuration : 1476 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R2
!
boot-start-marker
boot-end-marker
!
!
no aaa new-model
memory-size iomem 5
ip cef
!
multilink bundle-name authenticated
!
interface FastEthernet0/0
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet1/0
!
interface FastEthernet1/1
no switchport
ip address 172.30.1.2 255.255.255.0
ip nat outside (定义它为外网口)
ip virtual-reassembly
!
interface FastEthernet1/2
no switchport
ip address 172.16.1.1 255.255.255.0
ip nat inside (定义它为内网口)
ip virtual-reassembly
!
interface FastEthernet1/3
!
interface FastEthernet1/4
!
interface FastEthernet1/5
!
interface Vlan1
no ip address
!
ip route 172.16.3.0 255.255.255.0 172.16.1.2 (与R3的默认路由相回应,路由应该是一去一回的,否则网络是不会通的)
ip route 172.16.4.0 255.255.255.0 172.16.1.2
!
ip http server
no ip http secure-server
ip nat inside source list 1 interface FastEthernet1/1 overload
!
access-list 1 permit 172.16.3.0 0.0.0.255 (定义互联网访问控制,现在是两个网段都开通,等下将172.16.4.0段关闭,看NAT地址是否还生效?)
access-list 1 permit 172.16.4.0 0.0.0.255
!
control-plane
!
!
line con 0
exec-timeout 0 0
line aux 0
line vty 0 4
login
!
!
end
R2#
==========
R3#sh run
Building configuration...
Current configuration : 1312 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R3
!
boot-start-marker
boot-end-marker
!
no aaa new-model
memory-size iomem 5
ip cef
!
multilink bundle-name authenticated
!
interface FastEthernet0/0
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet1/0
!
interface FastEthernet1/1
!
interface FastEthernet1/2
no switchport
ip address 172.16.1.2 255.255.255.0
!
interface FastEthernet1/3
switchport access vlan 3
!
interface FastEthernet1/4
switchport access vlan 4
!
interface FastEthernet1/5
!
interface FastEthernet1/6
!
interface Vlan1
no ip address
!
interface Vlan3
ip address 172.16.3.254 255.255.255.0
!
interface Vlan4
ip address 172.16.4.254 255.255.255.0
!
ip route 0.0.0.0 0.0.0.0 172.16.1.1 (企业里,核心交换机一般都写条默认路由至企业的边界路由器或电信)
!
ip http server
no ip http secure-server
!
control-plane
!
line con 0
exec-timeout 0 0
line aux 0
line vty 0 4
login
!
end
R3#
============
验证,如果NAT地址转换不成功,两台PC机应该PING不通互联网的IP,因为它们与互联网这间并没有路由,当然NAT转换之后,它们与互联网是同一个网络,肯定是相通的。
VPCS 1 >ip 172.16.3.1 172.16.3.254 24
PC1 : 172.16.3.1 255.255.255.0 gateway 172.16.3.254
VPCS 1 >2
VPCS 2 >ip 172.16.4.1 172.16.4.254 24
PC2 : 172.16.4.1 255.255.255.0 gateway 172.16.4.254
VPCS 2 >ping 172.30.1.1
172.30.1.1 icmp_seq=1 timeout (正常,因为刚开始交换机没有MAC地址)
172.30.1.1 icmp_seq=2 timeout
172.30.1.1 icmp_seq=3 time=188.000 ms
172.30.1.1 icmp_seq=4 time=266.000 ms
172.30.1.1 icmp_seq=5 time=171.000 ms
VPCS 2 >1
VPCS 1 >ping 172.30.1.1
172.30.1.1 icmp_seq=1 time=203.000 ms
172.30.1.1 icmp_seq=2 time=234.000 ms
172.30.1.1 icmp_seq=3 time=140.000 ms
172.30.1.1 icmp_seq=4 time=219.000 ms
172.30.1.1 icmp_seq=5 time=203.000 ms
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息