CISCO路由器NAT功能的配置案例
NAT技術(shù)是路由器配置過程中常用的技術(shù),要怎樣去配置實現(xiàn)它的功能呢?它是怎樣進(jìn)行工作的呢?下面文章將給出你詳細(xì)的解答。
NAT(Network Address Translation)顧名思義就是網(wǎng)絡(luò)IP地址的轉(zhuǎn)換。NAT的出現(xiàn)是為了解決IP日益短缺的問題,將多個內(nèi)部地址映射為少數(shù)幾個甚至一個公網(wǎng)地址。這樣,就可以讓我們內(nèi)部網(wǎng)中的計算機(jī)通過偽IP訪問INTERNET的資源。
設(shè)置NAT功能的路由器至少要有一個內(nèi)部端口(Inside),一個外部端口(Outside)。
內(nèi)部端口連接的網(wǎng)絡(luò)用戶使用的是內(nèi)部IP地址(非法IP);外部端口連接的是外部的網(wǎng)絡(luò),使用電信部門分配給我們的IP地址。一般來說,內(nèi)部端口應(yīng)使用ETHERNET 端口,外部端口使用SERIAL 端口。另外,想要使用NAT功能,路由器的IOS必須支持NAT功能。
NAT設(shè)置可以分為靜態(tài)地址轉(zhuǎn)換、動態(tài)地址轉(zhuǎn)換、復(fù)用動態(tài)地址轉(zhuǎn)換。以下設(shè)置以Cisco路由器為例。
1.靜態(tài)地址轉(zhuǎn)換
靜態(tài)地址轉(zhuǎn)換將內(nèi)部本地地址與內(nèi)部合法地址進(jìn)行一對一地轉(zhuǎn)換,且需要指定和哪個合法地址進(jìn)行轉(zhuǎn)換。如果內(nèi)部網(wǎng)絡(luò)有WWW服務(wù)器或FTP服務(wù)器等可以為外部用戶提供服務(wù),則這些服務(wù)器的IP地址必須采用靜態(tài)地址轉(zhuǎn)換,以便外部用戶可以使用這些服務(wù)。
2.動態(tài)地址轉(zhuǎn)換
動態(tài)地址轉(zhuǎn)換也是將內(nèi)部本地地址與內(nèi)部合法地址一對一地轉(zhuǎn)換,但是動態(tài)地址轉(zhuǎn)換是從內(nèi)部合法地址池中動態(tài)地選擇一個未使用的地址來對內(nèi)部本地地址進(jìn)行轉(zhuǎn)換的。
3.復(fù)用動態(tài)地址轉(zhuǎn)換
復(fù)用動態(tài)地址轉(zhuǎn)換首先是一種動態(tài)地址轉(zhuǎn)換,但是它可以允許多個內(nèi)部本地地址共用一個內(nèi)部合法地址。對只申請到少量IP地址但卻經(jīng)常同時有多個用戶上外部網(wǎng)絡(luò)的情況,這種轉(zhuǎn)換極為有用。
PAT(Port Address Translation)也稱為NAPT,就是將多個內(nèi)部地址映射為一個公網(wǎng)地址,但以不同的協(xié)議端口號與不同的內(nèi)部地址相對應(yīng)。這種方式常用于撥號上Internet網(wǎng)。
以下是以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
當(dāng)然,我們也可以采用PAT技術(shù),但PAT 技術(shù)不太適合指定TCP/UDP端口的應(yīng)用,如電視會議等。因此,如果使用PAT技術(shù),也應(yīng)當(dāng)使用NAT+PAT,這樣才不至于功能受限。
【編輯推薦】