思科CCNA認(rèn)證之 NAT 子網(wǎng)地址轉(zhuǎn)換原理與配置詳解
本文講述了思科CCNA認(rèn)證之 NAT 子網(wǎng)地址轉(zhuǎn)換。分享給大家供大家參考,具體如下:
NAT 網(wǎng)絡(luò)地址轉(zhuǎn)換
全稱(chēng):Network Address Translation
為什么需要NAT?
因?yàn)楣W(wǎng)
IP(IPv4)地址緊缺,內(nèi)容地址通過(guò)NAT轉(zhuǎn)換成一個(gè)公有地址去訪問(wèn)公網(wǎng)資源;
如下圖展示:

私有地址列表
- A類(lèi): 10.0.0.0/8
- B類(lèi): 172.16.0.0/16
- C類(lèi): 192.168.1.0/24
| 名詞 | 解釋 |
|---|---|
| 內(nèi)部本地 | 轉(zhuǎn)換之前內(nèi)部原地址的名字 |
| 外部本地 | 轉(zhuǎn)換之前目標(biāo)主機(jī)的名字 |
| 內(nèi)部全局 | 轉(zhuǎn)換之后內(nèi)部主機(jī)的名字 |
| 外部全局 | 轉(zhuǎn)換之后外部目標(biāo)主機(jī)的名字 |

NAT的三種類(lèi)型
1、靜態(tài)NAT
將
內(nèi)部本地地址與內(nèi)部全局地址進(jìn)行一對(duì)一的明確轉(zhuǎn)換。這種方法主要用在內(nèi)部網(wǎng)絡(luò)中有對(duì)外提供服務(wù)的服務(wù)器,如WEB、占獨(dú)寶貴的合法IP地址。即如果某個(gè)合法IP地址已經(jīng)被NAT靜態(tài)地址轉(zhuǎn)換定義,即使該地址當(dāng)前沒(méi)有被使用,也不能被用作其他的地址轉(zhuǎn)換。
配置:
Router(config)#ip nat inside source static local-ip globl-ip
- Establishes static translation between an inside local address and an inside global address
Router(config)#ip nat inside
- Marks the interface as connected to the inside
Router(config)#ip nat outside
- Marks the interface as connected to the outside
Router(config)#show ip nat translations
- Displays active translations
案例:
如下圖:

2、動(dòng)態(tài)NAT
動(dòng)態(tài)地址轉(zhuǎn)換也是將內(nèi)部本地地址與內(nèi)部全局地址進(jìn)行一對(duì)一的轉(zhuǎn)換。但是是從內(nèi)部全局地址池中動(dòng)態(tài)的選擇一個(gè)未使用的地址對(duì)內(nèi)部本地地址進(jìn)行轉(zhuǎn)換。該地址是由未被使用的地址組成的地址池中在定義時(shí)排在最前面的一個(gè)。當(dāng)數(shù)據(jù)傳輸完畢后,路由器將把使用完的內(nèi)部全局地址放回到地址池中,以供其他內(nèi)部本地地址進(jìn)行轉(zhuǎn)換。但是在改地址被使用時(shí),不能用改地址再進(jìn)行一次轉(zhuǎn)換。
配置:
Router(config)#ip nat poll name start-ip end-ip {netmask netmask | prefix-length prefix-length}
- Defines a pool of global addresses to be allocated as needed
Router(config)#access-list access-list-number permit source [source-wildcard]
- Defines a standard IP ACL permitting those inside local addresses that are to be translated
Router(config)#ip nat inside source list access-list-number pool name
- Establishes dynameic source translation, specifying the ACL that was defined in the previous step
Router(config)#show ip nat translations
- Displays active translations
案例:

3、端口復(fù)用(PAT)
- 服用地址轉(zhuǎn)換也稱(chēng)為端口地址轉(zhuǎn)換(Port Address Translation, PAT),首先是一種動(dòng)態(tài)地址轉(zhuǎn)換,路由器將通過(guò)幾率地址、應(yīng)用程序端口等唯一標(biāo)示一個(gè)轉(zhuǎn)換。通過(guò)這種轉(zhuǎn)換,可以使多個(gè)內(nèi)部本地地址同時(shí)與同一個(gè)內(nèi)部全局地址進(jìn)行轉(zhuǎn)換并對(duì)外部網(wǎng)絡(luò)進(jìn)行訪問(wèn)。很多只申請(qǐng)到少量IP地址甚至只有一個(gè)合法IP、地址,卻京城有很多用戶同時(shí)要求上午的情況,這轉(zhuǎn)換方式非常有用;
- 理想狀態(tài)下,一個(gè)單一的IP地址可以使用的端口為4000個(gè)
配置:
Router(config)#access-list access-list-number permit source source-wildcard
- Defines a standard IP ACL that will permit the inside local addresses that are to be translated
Router(config)#ip nat inside source list access-list-number interface interface overload
- Establishes dynameic source translation, specifying the ACL that was defined in the previous step
Router(config)#show ip nat translations
- Displays active translations
案例:

NAT試驗(yàn)
按照下圖中的網(wǎng)絡(luò)拓?fù)溥M(jìn)行配置:

同樣server和PC均使用路由來(lái)代替,需要一下配置:
no ip routing
ip default-gateway xxx.xxx.xxx.xxx
注:如果沒(méi)有配置no ip routing,則默認(rèn)網(wǎng)關(guān)的配置不生效;
下面進(jìn)行配置:
Server配置:
R2>en
R2#conf t
R2(config)#hostname Server
Server(config)#int f 0/0
Server(config-if)#ip add 192.168.1.100 255.255.255.0
Server(config-if)#no sh
Server(config-if)#exit
Server(config)#no ip routing
Server(config)#ip default-gateway 192.168.1.254
Server(config)#line vty 0 4
Server(config-line)#pass
Server(config-line)#password sijiayong
服務(wù)器配置了vty,等下需要測(cè)試telnet連接;
PC配置:
R1>en
R1#conf t
R1(config)#hostname PC
PC(config)#int f 0/0
PC(config-if)#ip add 192.168.1.1 255.255.255.0
PC(config-if)#no sh
PC(config-if)#exit
PC(config)#no ip routing
PC(config)#ip default-gateway 192.168.1.254
路由配置:
R3>en
R3#conf t
Router(config)#hostname Gateway
Gateway(config)#int f 0/0
Gateway(config-if)#ip add 192.168.1.254 255.255.255.0
Gateway(config-if)#no sh
Gateway(config-if)#exit
Gateway(config)#int s 1/0
Gateway(config-if)#ip add 10.0.0.1 255.255.255.0
Gateway(config-if)#no sh
Gateway(config-if)#exit
Gateway(config)#ip route 0.0.0.0 0.0.0.0 10.0.0.2
Gateway(config)#access-list 1 permit 192.168.1.0 0.0.0.255
Gateway(config)#ip nat inside source list 1 interface s1/0 overload
Gateway(config)#int f 0/0
Gateway(config-if)#ip nat inside
Gateway(config-if)#int s 1/0
Gateway(config-if)#ip nat outside
Gateway(config-if)#end
模擬外網(wǎng)配置:
R4>en
R4#conf t
R4(config)#hostname Internet
Internet(config)#int s 0/0
Internet(config-if)#ip add 10.0.0.2 255.255.255.0
Internet(config-if)#no sh
這樣配置,服務(wù)器和PC就都可以訪問(wèn)外網(wǎng)地址10.0.0.2。
測(cè)試:
PC#ping 10.0.0.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/25/76 ms
Server#ping 10.0.0.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/15/40 ms
驗(yàn)證通過(guò);
實(shí)驗(yàn)要求2:
要求公網(wǎng)能夠通過(guò)
10.0.0.3的公網(wǎng)地址,連接到服務(wù)器Server,也就是能夠telnet連接到服務(wù)器;
這樣只需要配置路由器,吧10.0.0.3映射到192.168.1.100地址上即可;
配置如下:
Gateway(config)#ip nat inside source static 192.168.1.100 10.0.0.3
這個(gè)映射的配置,就可以了,通過(guò)10.0.0.1的公網(wǎng)進(jìn)行測(cè)試ping和telnet。
Internet#ping 10.0.0.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/27/80 ms
Internet#telnet 10.0.0.3
Trying 10.0.0.3 ... Open
User Access Verification
Password:
Server>exit
[Connection to 10.0.0.3 closed by foreign host]
測(cè)試通過(guò);
但同時(shí)發(fā)現(xiàn)有個(gè)危險(xiǎn),這種配置,是把Server服務(wù)器整個(gè)暴露在公網(wǎng)上,存在安全隱患;
常規(guī)工作中,一般只需要對(duì)公網(wǎng)暴露一個(gè)或者兩個(gè)端口,一般都是
Http的80端口和SSH的22端口,這樣更能夠保障服務(wù)器的安全;
本次以開(kāi)放telnet的23端口進(jìn)行測(cè)試;
首先要?jiǎng)h除掉當(dāng)前的nat配置,然后在進(jìn)行端口映射;
配置如下:
Gateway(config)#no ip nat inside source static 192.168.1.100 10.0.0.3
Gateway(config)#ip nat inside source static tcp 192.168.1.100 23 10.0.0.3 8080
這里對(duì)外暴露的是8080端口,映射到內(nèi)網(wǎng)地址的192.168.1.100的23端口上,下面進(jìn)行telnet測(cè)試。
Internet#telnet 10.0.0.3 8080
Trying 10.0.0.3, 8080 ... Open
User Access Verification
Password:
Server>exit
[Connection to 10.0.0.3 closed by foreign host]
測(cè)試通過(guò),至此,配置完成;
相關(guān)文章
思科CCNA認(rèn)證學(xué)習(xí)筆記(十五)思科ACL、NAT配置命令總結(jié)
這篇文章主要介紹了思科CCNA認(rèn)證ACL、NAT配置命令,總結(jié)分析了思科ACL、NAT的概念、原理、配置命令及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-03-09
思科CCNA學(xué)習(xí)筆記之NAT網(wǎng)絡(luò)地址轉(zhuǎn)換原理與實(shí)現(xiàn)方法圖文詳解
這篇文章主要介紹了思科CCNA學(xué)習(xí)筆記之NAT網(wǎng)絡(luò)地址轉(zhuǎn)換原理與實(shí)現(xiàn)方法,結(jié)合圖文與實(shí)例形式詳細(xì)分析了思科NAT網(wǎng)絡(luò)地址轉(zhuǎn)換的相關(guān)原理、實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可2020-02-12在Cisco IOS上限制NAT的單用戶連接數(shù)的方法
這篇文章主要為大家介紹了從技術(shù)手段,詳細(xì)的向大家介紹了IOS如何去利用NAT單用戶限制用戶的連接數(shù),那么我們要怎么去操作呢?相信看完此文會(huì)對(duì)你有所幫助2014-09-26- NAT也就是我們常說(shuō)的地址轉(zhuǎn)換,這是每臺(tái)路由器必備的功能,今天我們就以思科路由器,為大家介紹NAT的基礎(chǔ)知識(shí),方便大家在設(shè)置路由器時(shí)心中有數(shù),NAT屬接入廣域網(wǎng)技術(shù),是2012-12-09
思科CCNA認(rèn)證EIGRP——增強(qiáng)型內(nèi)部網(wǎng)關(guān)路由協(xié)議詳解
這篇文章主要介紹了思科CCNA認(rèn)證EIGRP——增強(qiáng)型內(nèi)部網(wǎng)關(guān)路由協(xié)議,詳細(xì)總結(jié)分析了EIGRP增強(qiáng)型內(nèi)部網(wǎng)關(guān)路由協(xié)議的具體概念、原理、使用方法與操作注意事項(xiàng),需要的朋友可以參2020-03-10
思科CCNA路由器配置——PAP與CHAP認(rèn)證配置實(shí)驗(yàn)詳解
這篇文章主要介紹了思科CCNA路由器PAP與CHAP認(rèn)證配置實(shí)驗(yàn),結(jié)合實(shí)例形式分析了思科路由器PAP與CHAP認(rèn)證配置具體步驟、配置命令與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-03-04
思科CCNA路由器配置——OSPF基于區(qū)域的MD5認(rèn)證實(shí)驗(yàn)詳解
這篇文章主要介紹了思科CCNA路由器OSPF基于區(qū)域的MD5認(rèn)證實(shí)驗(yàn),結(jié)合實(shí)例形式詳細(xì)分析了思科CCNA OSPF基于區(qū)域的MD5認(rèn)證具體步驟、配置命令與相關(guān)操作注意事項(xiàng),需要的朋友可2020-03-03
思科CCNA路由器配置——基于區(qū)域的OSPF簡(jiǎn)單認(rèn)證配置實(shí)驗(yàn)詳解
這篇文章主要介紹了思科CCNA基于區(qū)域的OSPF簡(jiǎn)單認(rèn)證配置實(shí)驗(yàn),結(jié)合實(shí)例形式分析了思科路由器配置區(qū)域OSPF認(rèn)證的具體步驟、配置命令與相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-03-03思科CCNA認(rèn)證學(xué)習(xí)筆記(十四)VLAN虛擬局域網(wǎng)原理與配置分析
這篇文章主要介紹了思科CCNA認(rèn)證VLAN虛擬局域網(wǎng)原理與配置,總結(jié)分析了VLAN虛擬局域網(wǎng)相關(guān)概念、原理、配置步驟、操作命令與使用注意事項(xiàng),需要的朋友可以參考下2020-02-21思科CCNA認(rèn)證學(xué)習(xí)筆記(十三)EIGRP協(xié)議的工作過(guò)程及配置操作分析
這篇文章主要介紹了思科CCNA認(rèn)證EIGRP協(xié)議的工作過(guò)程及配置操作,總結(jié)分析了思科CCNA認(rèn)證EIGRP協(xié)議的原理、工作過(guò)程、配置命令及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-02-21





