CISCO路由器NAT功能的配置案例
NAT技術是路由器配置過程中常用的技術,要怎樣去配置實現它的功能呢?它是怎樣進行工作的呢?下面文章將給出你詳細的解答。
NAT(Network Address Translation)顧名思義就是網絡IP地址的轉換。NAT的出現是為了解決IP日益短缺的問題,將多個內部地址映射為少數幾個甚至一個公網地址。這樣,就可以讓我們內部網中的計算機通過偽IP訪問INTERNET的資源。
設置NAT功能的路由器至少要有一個內部端口(Inside),一個外部端口(Outside)。
內部端口連接的網絡用戶使用的是內部IP地址(非法IP);外部端口連接的是外部的網絡,使用電信部門分配給我們的IP地址。一般來說,內部端口應使用ETHERNET 端口,外部端口使用SERIAL 端口。另外,想要使用NAT功能,路由器的IOS必須支持NAT功能。
NAT設置可以分為靜態地址轉換、動態地址轉換、復用動態地址轉換。以下設置以Cisco路由器為例。
1.靜態地址轉換
靜態地址轉換將內部本地地址與內部合法地址進行一對一地轉換,且需要指定和哪個合法地址進行轉換。如果內部網絡有WWW服務器或FTP服務器等可以為外部用戶提供服務,則這些服務器的IP地址必須采用靜態地址轉換,以便外部用戶可以使用這些服務。
2.動態地址轉換
動態地址轉換也是將內部本地地址與內部合法地址一對一地轉換,但是動態地址轉換是從內部合法地址池中動態地選擇一個未使用的地址來對內部本地地址進行轉換的。
3.復用動態地址轉換
復用動態地址轉換首先是一種動態地址轉換,但是它可以允許多個內部本地地址共用一個內部合法地址。對只申請到少量IP地址但卻經常同時有多個用戶上外部網絡的情況,這種轉換極為有用。
PAT(Port Address Translation)也稱為NAPT,就是將多個內部地址映射為一個公網地址,但以不同的協議端口號與不同的內部地址相對應。這種方式常用于撥號上Internet網。
以下是以2611路由器為例,配置清單如下:
Current configuration:
!
version 12.0
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname 2611
!
enable secret 5 $1$JIeG$UZJNjKhcptJXHPc/BP5GG0
enable password 2323ipro
!
ip subnet-zero
no ip source-route
no ip finger
!
!
!
interface Ethernet0/0
ip address 192.168.10.254 255.255.255.0 secondary
ip address 218.27.84.249 255.255.255.248
no ip directed-broadcast
ip accounting output-packets
no ip mroute-cache
no cdp enable
! #p#
interface Serial0/0
ip unnumbered Ethernet0/0
no ip directed-broadcast
ip accounting output-packets
ip nat outside
no ip mroute-cache
no fair-queue
no cdp enable
!
interface Ethernet0/1
ip address 192.168.2.254 255.255.255.0
no ip directed-broadcast
ip nat inside
no ip mroute-cache
no cdp enable
!
interface Virtual-TokenRing35
no ip address
no ip directed-broadcast
no ip mroute-cache
shutdown
ring-speed 16
!
router rip
redistribute connected
network 192.168.2.0
network 192.168.10.0
network 218.27.84.0
!
ip default-gateway 218.27.127.217
ip nat pool nat-pool 218.27.84.252 218.27.84.254 netmask 255.255.255.248
ip nat inside source list 1 pool nat-pool overload
ip nat inside source static 192.168.2.254 218.27.84.249
ip classless
ip route 0.0.0.0 0.0.0.0 Serial0/0
ip http server
ip http port 9091
ip ospf name-lookup
!
!
ip access-list extended filterin
permit tcp any host 218.27.84.249 eq www reflect httpfilter
access-list 1 permit 192.168.2.0 0.0.0.255
no cdp run
!
line con 0
transport input none
line aux 0
line vty 0 4
password routr
login
!
end
當然,我們也可以采用PAT技術,但PAT 技術不太適合指定TCP/UDP端口的應用,如電視會議等。因此,如果使用PAT技術,也應當使用NAT+PAT,這樣才不至于功能受限。
【編輯推薦】