你是某公司的網絡管理者,公司辦公網需要接入網際網路,公司隻向 ISP 申請了一條專線,該專線配置設定了一個公司 IP 位址,配置實作全公司的主機都能通路外網。
技術原理
NAT 将網絡劃分為内部網絡和外部網絡兩部分,區域網路主機利用 NAT 通路網絡時,是将區域網路内部的本地位址轉換為全局位址(網際網路合法的 IP 位址)後轉發資料包;
NAT 分為兩種類型:NAT(網絡位址轉換)和 NAPT(網絡端口位址轉換 IP 位址對應一個全局位址)。
NAPT:使用不同的端口來映射多個内網 IP 位址到一個指定的外網 IP 位址,多對一。
NAPT 采用端口多路複用方式。内部網絡的所有主機均可共享一個合法外部 IP 位址實作對 Internet 的通路,進而可以最大限度地節約 IP 位址資源。同時,又可隐藏網絡内部的所有主機,有效避免來自 Internet 的攻擊。是以,目前網絡中應用最多的就是端口多路複用方式。
ISP(Internet Service Provider),網際網路服務提供商,即向廣大使用者綜合提供網際網路接入業務、資訊業務和增值業務的電信營運商。ISP是經國家主管部門準許的正式營運企業,享受國家法律保護。
實驗步驟
建立 Packet Tracer 拓撲圖
網絡端口位址轉換 NAPT 配置網絡端口位址轉換 NAPT 配置
(1)R1 為公司出口路由器,其與 ISP 路由器之間通過 V.35 電纜序列槽連接配接,DCE 端連接配接在 R1 上,配置其時鐘頻率 64000;
(2)配置 PC 機、伺服器及路由器接口 IP 位址;
(3)在各路由器上配置靜态路由協定,讓 PC 間能互相 Ping 通;
(4)在 R1 上配置 NAPT。
(5)在 R1 上定義内外網絡接口。
(6)驗證主機之間的互通性。
實驗裝置
PC 2 台;Server-PT 1 台;Switch_2950-24 1 台 Router-PT 2 台;直通線;交叉線;DCE序列槽線
PC1
192.168.1.2
255.255.255.0
192.168.1.1
PC2
192.168.1.3
Server
200.1.2.2
200.1.2.1
R1
en
conf t
host R1
int fa 0/0
ip address 192.168.1.1 255.255.255.0
no shutdown
int s 2/0
ip address 200.1.1.1 255.255.255.0
clock rate 64000
R2
host R2
ip address 200.1.1.2 255.255.255.0
ip address 200.1.2.1 255.255.255.0
exit
ip route 200.1.2.0 255.255.255.0 200.1.1.2
ip route 192.168.1.0 255.255.255.0 200.1.1.1
end
show ip route
CMD
ping 200.1.2.2 (success)
Web 浏覽器
http://200.1.2.2(success)
ip nat inside
ip nat outside
access-list 1 permit 192.168.1.0 0.0.0.255
ip nat pool jaking 200.1.1.3 200.1.1.3 netmask 255.255.255.0 #設定名稱為jaking的位址池,起始和終止IP都是200.1.1.3
ip nat inside source list 1 pool jaking overload (無 overload 表示多對多,有 overload 表示多對一)
show ip nat translations(無結果)
show ip nat translations(有 1 個結果)show ip nat translations(有 2 個結果)
實戰演練
Continue with configuration dialog? [yes/no]: n
Press RETURN to get started!
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R1
R1(config)#int fa 0/0
R1(config-if)#ip add 192.168.1.1 255.255.255.0
R1(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#int s 2/0
R1(config-if)#ip add 200.1.1.1 255.255.255.0
%LINK-5-CHANGED: Interface Serial2/0, changed state to down
R1(config-if)#clock rate 64000
R1(config-if)#
R2
Router(config)#host R2
R2(config)#int s 2/0
R2(config-if)#ip add 200.1.1.2 255.255.255.0
R2(config-if)#no shut
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
R2(config-if)#int fa 0/0
R2(config-if)#ip add 200.1.2.1 255.255.255.0
R2(config-if)#
R1(config-if)#exit
R1(config)#ip route 200.1.2.0 255.255.255.0 200.1.1.2
R2(config-if)#exit
R2(config)#ip route 192.168.1.0 255.255.255.0 200.1.1.1
R2(config)#end
R2#
%SYS-5-CONFIG_I: Configured from console by console
R2#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
S 192.168.1.0/24 [1/0] via 200.1.1.1
C 200.1.1.0/24 is directly connected, Serial2/0
C 200.1.2.0/24 is directly connected, FastEthernet0/0
PC>ipconfig
IP Address......................: 192.168.1.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1
PC>ping 200.1.2.2
Pinging 200.1.2.2 with 32 bytes of data:
Request timed out.
Reply from 200.1.2.2: bytes=32 time=24ms TTL=126
Reply from 200.1.2.2: bytes=32 time=25ms TTL=126
Reply from 200.1.2.2: bytes=32 time=20ms TTL=126
Ping statistics for 200.1.2.2:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 20ms, Maximum = 25ms, Average = 23ms
Reply from 200.1.2.2: bytes=32 time=23ms TTL=126
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Minimum = 20ms, Maximum = 25ms, Average = 23ms
IP Address......................: 192.168.1.3
Reply from 200.1.2.2: bytes=32 time=31ms TTL=126
Reply from 200.1.2.2: bytes=32 time=17ms TTL=126
Reply from 200.1.2.2: bytes=32 time=19ms TTL=126
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Minimum = 17ms, Maximum = 31ms, Average = 22ms
R1(config-if)#ip nat inside
R1(config-if)#ip nat outside
R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255
R1(config)#ip nat pool jaking 200.1.1.3 200.1.1.3 netmask 255.255.255.0
R1(config)#ip nat inside source list 1 pool jaking overload
R1(config)#end
R1#
R1#show ip nat translations
Pro Inside global Inside local Outside local Outside global
tcp 200.1.1.3:1026 192.168.1.2:1026 200.1.2.2:80 200.1.2.2:80
tcp 200.1.1.3:1024 192.168.1.3:1026 200.1.2.2:80 200.1.2.2:80
總結
至此,用思科模拟器進行網絡端口位址轉換 NAPT 配置完畢。