網絡地址轉換(NAT,Network Address Translation)被廣泛應用於各種類型Internet接入方式和備種類型的網絡中。原因很簡單,NAT不僅完美地解決了lP地址不足的問題,而且還能夠有效地避免來自網絡外部的***,隱藏並保護網絡內部的計算機。NAT的實現方式有三種,即靜態轉換Static Nat、動態轉換Dynamic Nat 和 端口多路複用OverLoad。
端口多路複用是指改變外出數據包的源端口並進行端口轉換,即端口地址轉換(PAT,Port AddressTranslation).採用端口多路複用方式。內部網絡的所有主機均可共享一個合法外部IP地址實現對Internet的訪問,從而可以最大限度地節約IP地址資源。同時,又可隱藏網絡內部的所有主機,有效避免來自internet的***。因此,目前網絡中應用最多的就是端口多路複用方式。
一、實驗配置拓撲圖
圖一 私有網段192.168.1.0/24通過Company路由器的PAT技術接入互連網
二、路由器的基本配置
路由器ISP的配置
ISP#sh startup-config
Using 582 bytes
!
version 12.4
service password-encryption
!
hostname ISP
!
!
enable secret 5 $1$mERr$Q1EnFeXJ8Ibdhx2QffKaQ.
enable password 7 083249401018
!
!
!
!
ip ssh version 1
!
!
interface FastEthernet0/0
no ip address
duplex auto
speed auto
shutdown
!
interface FastEthernet0/1
ip address 223.1.1.1 255.255.255.0
duplex auto
speed auto
!
interface Serial0/3/0
ip address 221.1.1.1 255.255.255.0
clock rate 56000
!
interface Serial0/3/1
no ip address
shutdown
!
interface Vlan1
no ip address
shutdown
!
ip classless
!
!
!
!
!
no cdp run
!
line con 0
line vty 0 4
login
!
!
end
路由器Company的配置
Company#sh startup-config
Using 643 bytes
!
version 12.4
service password-encryption
!
hostname Company
!
!
enable password 7 083249401018
!
!
!
!
ip ssh version 1
!
!
interface FastEthernet0/0
no ip address
duplex auto
speed auto
shutdown
!
interface FastEthernet0/1
ip address 192.168.1.1 255.255.255.0
ip nat inside
duplex auto
speed auto
!
interface Serial0/3/0
ip address 221.1.1.2 255.255.255.0
ip nat outside
!
interface Vlan1
no ip address
shutdown
!
ip nat inside source list 1 interface Serial0/3/0 overload
ip classless
ip route 0.0.0.0 0.0.0.0 221.1.1.1
!
!
access-list 1 permit 192.168.1.0 0.0.0.255
!
!
!
no cdp run
!
line con 0
line vty 0 4
login
!
!
end
在路由器Company上配置PAT的命令
Company(config)#ip route 0.0.0.0 0.0.0.0 221.1.1.1 \\配置默認路由
Company(config)#access-list 1 permit 192.168.1.0 0.0.0.255 \\配置一個標準訪問控制列表
Company(config)#ip nat inside source list 1 interface Serial0/3/0 overload \\啓用PAT私有IP地址的來源來自於ACL 1,使用serial0/3/0上的公共IP地址進行轉換,overload表示使用端口號進行轉換
Company(config)#int fa0/1
Company(config-if)#ip nat inside
Company(config-if)#int serial0/3/0
Company(config-if)#ip nat outside
三、校驗、查看PAT的配置及運行狀況
測試,又在實驗拓撲圖中添加了一臺服務器。
圖三
Company#sh ip nat translations
Pro Inside global Inside local Outside local Outside global
icmp 221.1.1.2:23 192.168.1.3:23 223.1.1.2:23 223.1.1.2:23
icmp 221.1.1.2:24 192.168.1.3:24 223.1.1.2:24 223.1.1.2:24
icmp 221.1.1.2:25 192.168.1.3:25 223.1.1.2:25 223.1.1.2:25
icmp 221.1.1.2:26 192.168.1.3:26 223.1.1.2:26 223.1.1.2:26
icmp 221.1.1.2:27 192.168.1.3:27 223.1.1.2:27 223.1.1.2:27
icmp 221.1.1.2:28 192.168.1.3:28 223.1.1.2:28 223.1.1.2:28
tcp 221.1.1.2:1025 192.168.1.3:1025 223.1.1.3:80 223.1.1.3:80
tcp 221.1.1.2:1026 192.168.1.3:1026 223.1.1.3:80 223.1.1.3:80
tcp 221.1.1.2:1027 192.168.1.3:1027 223.1.1.3:80 223.1.1.3:80
tcp 221.1.1.2:1028 192.168.1.3:1028 223.1.1.3:80 223.1.1.3:80
tcp 221.1.1.2:1029 192.168.1.3:1029 223.1.1.3:80 223.1.1.3:80
Company#sh ip nat statistics
Total translations: 11 (0 static, 11 dynamic, 11 extended)
Outside Interfaces: Serial0/3/0
Inside Interfaces: FastEthernet0/1
Hits: 77 Misses: 11
Expired translations: 0
Dynamic mappings:
IP NAT debugging is on
Company#
NAT: s=192.168.1.2->221.1.1.2, d=223.1.1.1[12]
NAT*: s=223.1.1.1, d=221.1.1.2->192.168.1.2[12]
NAT: s=192.168.1.2->221.1.1.2, d=223.1.1.1[13]
NAT*: s=223.1.1.1, d=221.1.1.2->192.168.1.2[13]
NAT: s=192.168.1.2->221.1.1.2, d=223.1.1.1[14]
NAT*: s=223.1.1.1, d=221.1.1.2->192.168.1.2[14]
NAT: s=192.168.1.2->221.1.1.2, d=223.1.1.1[15]
NAT*: s=223.1.1.1, d=221.1.1.2->192.168.1.2[15]
Company#no debug ip nat
IP NAT debugging is off
Company#