您好,登錄后才能下訂單哦!
導(dǎo)讀 | 本文檔詳細(xì)介紹網(wǎng)絡(luò)地址轉(zhuǎn)換 NAT 配置 |
理解 NAT 網(wǎng)絡(luò)地址轉(zhuǎn)換的原理及功能
掌握靜態(tài) NAT 的配置,實(shí)現(xiàn)局域網(wǎng)訪問(wèn)互聯(lián)網(wǎng)
你是某公司的網(wǎng)絡(luò)管理員,欲發(fā)布公司的 WWW 服務(wù)?,F(xiàn)要求將內(nèi)網(wǎng) Web 服務(wù)器 IP地址映射為全局 IP 地址,實(shí)現(xiàn)外部網(wǎng)絡(luò)可以訪問(wèn)公司內(nèi)部 Web 服務(wù)器。
網(wǎng)絡(luò)地址轉(zhuǎn)換 NAT(Network Address Translation),被廣泛應(yīng)用于各種類型 Internet 接入方式和各種類型的網(wǎng)絡(luò)中。原因很簡(jiǎn)單,NAT 不僅完美地解決了 IP 地址不足的問(wèn)題,而且還能夠有效地避免來(lái)自網(wǎng)絡(luò)外部的攻擊,隱藏并保護(hù)網(wǎng)絡(luò)內(nèi)部的計(jì)算機(jī)。默認(rèn)情況下,內(nèi)部 IP 地址是無(wú)法被路由到外網(wǎng)的,內(nèi)部主機(jī) 10.1.1.1 要與外部 Internet通信,IP 包到達(dá) NAT 路由器時(shí),IP 包頭的源地址 10.1.1.1 被替換成一個(gè)合法的外網(wǎng) IP,并在 NAT 轉(zhuǎn)發(fā)表中保存這條記錄。當(dāng)外部主機(jī)發(fā)送一個(gè)應(yīng)答到內(nèi)網(wǎng)時(shí),NAT 路由器收到后,查看當(dāng)前 NAT 轉(zhuǎn)換表,用 10.1.1.1 替換掉這個(gè)外網(wǎng)地址。NAT 將網(wǎng)絡(luò)劃分為內(nèi)部網(wǎng)絡(luò)和外部網(wǎng)絡(luò)兩部分,局域網(wǎng)主機(jī)利用 NAT 訪問(wèn)網(wǎng)絡(luò)時(shí),是將局域網(wǎng)內(nèi)部的本地地址轉(zhuǎn)換為全局地址(互聯(lián)網(wǎng)合法的 IP 地址)后轉(zhuǎn)發(fā)數(shù)據(jù)包;
NAT 分為兩種類型:NAT(網(wǎng)絡(luò)地址轉(zhuǎn)換)和 NAPT(網(wǎng)絡(luò)端口地址轉(zhuǎn)換 IP 地址對(duì)應(yīng)一個(gè)全局地址)。
靜態(tài) NAT:實(shí)現(xiàn)內(nèi)部地址與外部地址一對(duì)一的映射?,F(xiàn)實(shí)中,一般都用于服務(wù)器;
動(dòng)態(tài) NAT:定義一個(gè)地址池,自動(dòng)映射,也是一對(duì)一的。現(xiàn)實(shí)中,用得比較少;
NAPT:使用不同的端口來(lái)映射多個(gè)內(nèi)網(wǎng) IP 地址到一個(gè)指定的外網(wǎng) IP 地址,多對(duì)一。
新建 Packet Tracer 拓?fù)鋱D
(1)R1 為公司出口路由器,其與外部路由器之間通過(guò) V.35 電纜串口連接,DCE 端連接在 R1 上,配置其時(shí)鐘頻率 64000;
(2)配置 PC 機(jī)、服務(wù)器及路由器接口 IP 地址;
(3)在各路由器上配置靜態(tài)路由協(xié)議,讓 PC 間能相互 Ping 通;
(4)在 R1 上配置靜態(tài) NAT。
(5)在 R1 上定義內(nèi)外網(wǎng)絡(luò)接口。
(6)驗(yàn)證主機(jī)之間的互通性。
PC 1 臺(tái);Server-PT 1 臺(tái);Switch_2950-24 1 臺(tái);Router-PT 2 臺(tái);直連線;交叉線;DCE串口線 Server-PT 192.168.1.2 255.255.255.0 192.168.1.1 PC0 222.0.2.2 255.255.255.0 222.0.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 222.0.1.1 255.255.255.0 no shutdown clock rate 64000 R2 en conf t host R2 int s 2/0 ip address 222.0.1.2 255.255.255.0 no shut int fa 0/0 ip address 222.0.2.1 255.255.255.0 no shutdown R1 exit; ip route 222.0.2.0 255.255.255.0 222.0.1.2 R2 exit ip route 192.168.1.0 255.255.255.0 222.0.1.1 end show ip route PC0 CMD ping 192.168.1.2 (success) Web 瀏覽器 http://192.168.1.2 (success)
R1 int fa 0/0 ip nat inside int s 2/0 ip nat outside exit ip nat inside source static 192.168.1.2 222.0.1.3 end show ip nat translations PC0 Web 瀏覽器 http://222.0.1.3 (success)
R1 show ip nat translations
R1 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)#hostname 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 R1(config-if)# %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up R1(config-if)#int s 2/0 R1(config-if)#ip add 222.0.1.1 255.255.255.0 R1(config-if)#no shut %LINK-5-CHANGED: Interface Serial2/0, changed state to down R1(config-if)#clock rate 64000 R1(config-if)# R2 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 R2 R2(config)#int s 2/0 R2(config-if)#ip add 222.0.1.2 255.255.255.0 R2(config-if)#no shut %LINK-5-CHANGED: Interface Serial2/0, changed state to up R2(config-if)#int fa 0/0 R2(config-if)#ip add 222.0.2.1 255.255.255.0 R2(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 R2(config-if)# R1 R1(config-if)#exit R1(config)# R1(config)#ip route 222.0.2.0 255.255.255.0 222.0.1.2 R2 R2(config-if)#exit R2(config)# R2(config)#ip route 192.168.1.0 255.255.255.0 222.0.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 222.0.1.1 C 222.0.1.0/24 is directly connected, Serial2/0 C 222.0.2.0/24 is directly connected, FastEthernet0/0 R2# PC0 CMD ping 192.168.1.2 (success) PC>ipconfig IP Address......................: 222.0.2.2 Subnet Mask.....................: 255.255.255.0 Default Gateway.................: 222.0.2.1 PC>ping 192.168.1.2 Pinging 192.168.1.2 with 32 bytes of data: Request timed out. Reply from 192.168.1.2: bytes=32 time=19ms TTL=126 Reply from 192.168.1.2: bytes=32 time=18ms TTL=126 Reply from 192.168.1.2: bytes=32 time=23ms TTL=126 Ping statistics for 192.168.1.2: Packets: Sent = 4, Received = 3, Lost = 1 (25% loss), Approximate round trip times in milli-seconds: Minimum = 18ms, Maximum = 23ms, Average = 20ms PC>ping 192.168.1.2 Pinging 192.168.1.2 with 32 bytes of data: Reply from 192.168.1.2: bytes=32 time=26ms TTL=126 Reply from 192.168.1.2: bytes=32 time=26ms TTL=126 Reply from 192.168.1.2: bytes=32 time=22ms TTL=126 Reply from 192.168.1.2: bytes=32 time=23ms TTL=126 Ping statistics for 192.168.1.2: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 22ms, Maximum = 26ms, Average = 24ms PC> Web 瀏覽器 http://192.168.1.2 (success) R1 R1>en R1#conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)#int fa 0/0 R1(config-if)#ip nat inside R1(config-if)#int s 2/0 R1(config-if)#ip nat outside R1(config-if)#exit R1(config)#ip nat inside source static 192.168.1.2 222.0.1.3 R1(config)#end R1# %SYS-5-CONFIG_I: Configured from console by console R1#show ip nat translations Pro Inside global Inside local Outside local Outside global --- 222.0.1.3 192.168.1.2 --- --- R1# PC0 Web 瀏覽器 http://222.0.1.3 (success) CMD ping 222.0.1.3 PC>ipconfig IP Address......................: 222.0.2.2 Subnet Mask.....................: 255.255.255.0 Default Gateway.................: 222.0.2.1 PC>ping 222.0.1.3 Pinging 222.0.1.3 with 32 bytes of data: Reply from 222.0.1.3: bytes=32 time=21ms TTL=126 Reply from 222.0.1.3: bytes=32 time=22ms TTL=126 Reply from 222.0.1.3: bytes=32 time=23ms TTL=126 Reply from 222.0.1.3: bytes=32 time=23ms TTL=126 Ping statistics for 222.0.1.3: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 21ms, Maximum = 23ms, Average = 22ms
本文原創(chuàng)地址: https://www.linuxprobe.com/network-address-translation.html
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。