深入解析思科EI、華為數通方向你需要掌握的技術——動態NAT

網絡地址轉換NAT-動態NAT的使用範圍和配置

什麼是動態NAT?

使用公有地址池,並以先到先得的原則分配這些地址。當具有私有 IP 地址的主機請求訪問 Internet 時,動態 NAT 從地址池中選擇一個未被其它主機佔用的 IP 地址一對一的轉化。

當數據會話結束後,路由器會釋放掉公有IP地址回到地址池,以提供其他內部私有IP地址的轉換。當同一時刻地址池中地址被NAT轉換完畢,則其他私有地址不能夠被NAT轉換。

使用範圍:

一般是我們公司內網中有設備需要去訪問我們公網,我們就必須要做一個NAT地址轉換,把我們私網的IP地址轉換成我們公網的IP地址,這時,就需要使用動態NAT了,使用地址池中的公網地址進行IP地址轉換,去訪問我們的公網,下文是一個例子。

(描述實驗的要求)

1. 使用網絡拓撲圖給的地址網段配置各路由器PC機的IP地址和接口地址

2. 使用ospf路由協議使得全網互通(除公網ISP)

3. 使用PAT端口複用使得內網可以同時訪問公網服務器

拓撲:

深入解析思科EI、華為數通方向你需要掌握的技術——動態NAT

分析難點以及完成的思路

優先配置各PC機和路由器的地址,其次在路由器配置路由協議使得內網全網互通,最後在邊界路由器做動態NAT,並且在邊界路由器配置默認路由並下發給內網各路由器,全部指向邊界路由器,注意動態NAT和PAT端口複用的區別,端口複用配置命令的關鍵詞overload,還有進出口的選擇,我們做動態NAT不需要加overload。

配置命令

1. 配置ISP、PC機和路由器的IP地址接口地址和網關地址。

2. 如果使用路由器代替PC或者server,需要加上“no ip routing”在全局配置模式下。

PC1:

PC1(config)#no ip routing

PC1(config-if)#interface Ethernet0/0

PC1(config-if)#ip address 192.168.1.1 255.255.255.0


PC1(config)#ip default-gateway 192.168.1.254


PC2:

PC2(config)#no ip routing

PC2(config-if)#interface Ethernet0/0

PC2(config-if)#ip address 192.168.1.2 255.255.255.0


PC2(config)#ip default-gateway 192.168.1.254


PC3:

PC3(config)#no ip routing

PC3(config-if)#interface Ethernet0/0

PC3(config-if)#ip address 192.168.3.1 255.255.255.0


PC3(config)#ip default-gateway 192.168.3.254


Sever:

server(config)#no ip routing

server(config-if)#interface Ethernet0/0

server(config-if)#ip address 192.168.2.1 255.255.255.0


server(config)#ip default-gateway 192.168.2.254


ISP:

ISP(config)#interface Serial2/0

ISP(config-if)#ip address 200.1.1.100 255.255.255.0


R1:(配置接口IP地址,使用OSPF路由協議,通告直連網段)

R1(config-if)#interface Ethernet0/0

R1(config-if)#ip address 192.168.1.254 255.255.255.0


R1(config-if)#interface Ethernet0/1

R1(config-if)#ip address 10.1.1.1 255.255.255.0


R1(config)#router ospf 1

R1(config-router)#router-id 1.1.1.1

R1(config-router)#network 10.1.1.0 0.0.0.255 area 0

R1(config-router)#network 192.168.1.0 0.0.0.255 area 0


R2:(配置接口IP地址,使用OSPF路由協議,通告直連網段)

R2(config-if)#interface Ethernet0/1

R2(config-if)#ip address 192.168.2.254 255.255.255.0


R2(config-if)#interface Ethernet0/0

R2(config-if)#ip address 10.1.1.2 255.255.255.0


R2(config-if)#interface Ethernet0/2

R2(config-if)#ip address 10.1.2.1 255.255.255.0


R2(config)#router ospf 1

R2(config-router)#router-id 2.2.2.2

R2(config-router)#network 10.1.1.0 0.0.0.255 area 0

R2(config-router)#network 10.1.2.0 0.0.0.255 area 0

R2(config-router)#network 192.168.2.0 0.0.0.255 area 0


R3:(配置接口IP地址,使用OSPF路由協議,通告直連網段)

R3(config-if)#interface Ethernet0/1

R3(config-if)#ip address 192.168.3.254 255.255.255.0


R3(config-if)#interface Ethernet0/0

R3(config-if)#ip address 10.1.3.1 255.255.255.0


R3(config)#router ospf 1

R3(config-router)#router-id 3.3.3.3

R3(config-router)#network 10.1.3.0 0.0.0.255 area 0

R3(config-router)#network 192.168.3.0 0.0.0.255 area 0


R4:(配置接口IP地址,使用OSPF路由協議,通告直連網段)

R4(config-if)#interface Ethernet0/0

R4(config-if)#ip address 10.1.2.2 255.255.255.0


R4(config-if)#interface Ethernet0/1

R4(config-if)#ip address 10.1.3.2 255.255.255.0


R4(config-if)#interface Serial2/0

R4(config-if)#ip address 200.1.1.2 255.255.255.0


R4(config)#router ospf 1

R4(config-router)#router-id 4.4.4.4

R4(config-router)#network 10.1.2.0 0.0.0.255 area 0

R4(config-router)#network 10.1.3.0 0.0.0.255 area 0

R4(config-router)#default-information originate ----------公網IP地址無法在內網中出現,故下發一條默認路由,為內網設

備提供到達公網IP地址的路徑


3. 使用拓撲給的唯一地址在邊界路由器(R4)配置動態NAT,劃出一段地址池,根據拓撲中給出的信息是從200.1.1.1到200.1.1.100是可以使用的地址,作為我們的地址池進行綁定,並給出可以上網的網段信息,可以使用訪問控制列表進行過濾。

R4(config)#ip nat pool zsl 200.1.1.10 200.1.1.12 netmask 255.255.255.0

R4(config)#ip nat inside source list 1 pool zsl

R4(config)#ip route 0.0.0.0 0.0.0.0 200.1.1.100

R4(config)#access-list 1 permit 192.168.0.0 0.0.255.255

我們在地址池中選取了三個有效地址,但我們內網中有四臺設備需要上網,這時我們可以看一下動態NAT的缺點,採取先到先得的方式進行地址分配,所以我們這個實驗可以看到至少有一臺設備是無法ping通的。如果需要ping通,那麼必須要等待有一臺設備將他的公網地址釋放,才可以讓另一臺設備使用,所以動態NAT是非常浪費我們公網地址的,接下來我們來測試一下這個實驗。


PC1#ping 200.1.1.100

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 200.1.1.100, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 4/210/1016 ms


PC2#ping 200.1.1.100

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 200.1.1.100, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 10/211/1016 ms


Server#ping 200.1.1.100

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 200.1.1.100, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 9/210/1014 ms


PC3#ping 200.1.1.100

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 200.1.1.100, timeout is 2 seconds:

UUUUU

Success rate is 0 percent (0/5)

總結:

1)不要把inside和outside應用的接口弄錯。

2)動態NAT映射表條目存在一定生存時間,時間超過時轉換條目將會被自動刪除。一對一的動態NAT超時時間為10分鐘(600秒);只有等待將使用後的地址釋放之後,才可以給別的設備進行使用,這是動態NAT的一個機制。


學網絡,就在IE-LAB

國內高端網絡工程師培養基地


CCNA新版電子書免費領√

華為HCIA學習資料免費領√

CCNP/HCIP資料包免費領√


分享到:


相關文章: