運維之思科篇——NAT基礎配置

一、 NAT(網絡地址轉換)

1 作用:通過將內部網絡的私有IP地址翻譯成全球唯一的公網IP地址,使內部網絡可以連接到互聯網等外部網絡上。

2 優點:

節省公有合法IP地址

處理地址重疊

增強靈活性

安全性

3NAT的缺點

延遲增大

配置和維護的複雜性

不支持某些應用,可以通過靜態NAT映射來避免

4NAT實現方式

1 靜態轉換

IP地址的對應關係是一對一,而且是不變的,藉助靜態轉換,能實現外部網絡對內部網絡中某些特設定服務器的訪問。

靜態NAT配置:

配置接口IP及路由

全局:

Ip nat inside source static 192.168.1.1 61.159.62.131

在內外接口上啓用NAT

進入出口配置:ip nat outside

進入入口配置:ip nat inside 

端口映射:

ip nat inside source static tcp 192.168.1.6 80 61.159.62.133 80 

2 動態轉換

IP地址的對應關係是不確定的,而是隨機的,所有被授權訪問互聯網的私有地址可隨機轉換爲任何指定的合法的外部IP地址。(內部網絡同時訪問Internet的主機數少於配置的合法地址中的IP個數時適用)

動態NAT的配置:

1.全局:access-list 1 permit 192.168.1.0 0.0.0.255

2.全局:ip nat pool nsd 210.13.114.113 210.13.114.118 netmask 255.255.255.248(定義地址池名稱爲nsd,地址池IP範圍210.13.114.113 210.13.114.118

3.全局:ip nat inside source list 1 pool nsd

4.進入出口配置:ip nat outside

進入入口配置:ip nat inside 

動態轉換NAT配置步驟

1.配置ACL,用於限定可以做地址轉換的內網範圍

2.配置電信給予的地址池

3.設置ACL和地址池的映射關係,匹配做地址轉換的數據流

4.指定內外部接口

 

3 端口多路複用(PAT

通過改變外出數據包的源IP地址和源端口並進行端口轉換,內部網絡的所有主機均可共享一個合法IP地址實現互聯網的訪問,節約IP

PAT的配置:

4.全局:ip nat inside source list 1 interface f0/1 overload

5NAT三種實現方式的區別:

靜態轉換的對應關係一對一且不變,並且沒有節約公用IP,只隱藏了主機的真實地址。

動態轉換雖然在一定情況下節約了公用IP,但當內部網絡同時訪問Internet的主機數大於合法地址池中的IP數量時就不適用了。

端口多路複用可以使所有內部網絡主機共享一個合法的外部IP地址,從而最大限度地節約IP地址資源。

二、 查看NAT轉換條目

1、特權:show  ip  nat  translations顯示當前NAT轉換表項

三、 清除NAT轉換條目

1、特權: clear ip nat translation * 清除NAT轉換表項中的所有所條目

注:靜態NAT條目不會被清除

四、 NAT常見問題

ACL阻止轉換後的流量

進行地址轉換的ACL不全

overload參數漏配

不對稱路由問題

動態地址池IP地址範圍配置錯誤

動態地址池與靜態轉換地址重疊

Insideoutside接口配置錯誤

五、 顯示每個轉換的數據包

特權:debug  ip  nat 

Undebug all

S表示源地址

D表示目的地址

192.168.1.2->61.159.62.130表示將192.168.1.2轉換爲61.159.62.130

Nslookup www.tedu.com

Clear ip nat translation *

動態NAT配置步驟

1、配置ACL,用於限定可以做地址轉換的內網範圍

R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

2、配置合法地址池

R1(config)#ip nat pool mylan 201.1.1.2 201.1.1.8 netmask 255.255.255.0

3、設置ACL和地址池的映射關係

R1(config)#ip nat inside source list 1 pool mylan

4、指定內部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations    查看NAT轉換表

R1#clear ip nat translation * 清除動態轉換的NAT

將內網服務器發佈到互聯網,可以採用靜態NAT

1、配置將哪個內網IP映射爲哪個合法地址

R1(config)#ip nat inside source static 192.168.1.100 201.1.1.9

2、指定內部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations

NAT:將一個網絡的地址轉換成另一個網絡地址

端口映射

當互聯網用戶訪問發佈的IP地址+端口號,才能找到相應的內網服務器

1、清除上一步的靜態映射

R1(config)#no ip nat inside source static 192.168.1.100 201.1.1.9

2、映射192.168.1.10080端口到201.1.1.980端口

R1(config)#ip nat inside source static tcp 192.168.1.100 80 201.1.1.9 80 

3、將192.168.1.101DNS服務發佈到互聯網

R1(config)#ip nat inside source static udp 192.168.1.101 53 201.1.1.9 53 

4、指定內部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations

5、內網增加一臺server3ip地址是192.168.1.101,網關指向192.168.1.1。在services選項卡中選擇左側的DNS,右側namewww.tedu.cnAddress201.1.1.1,點擊add,設置DNS ServiceOn的狀態

6、在互聯網服務器上添加它使用的DNS服務器是201.1.1.9,然後運行命令行工具,輸入nslookup www.tedu.cn

PAT:如果外網地址只有一個,配置在路由器的外端口上了,那麼可以讓內網所有的地址都轉換成外網端口的地址,進行互聯網訪問

1、清除前面所做的動態轉換

R1#clear ip nat translation *

R1(config)#no ip nat inside source list 1 

R1(config)#no ip nat pool mylan

2、定義ACL,限制可以進行PAT轉換的內網地址

R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

3、配置ACL和路由器外端口的映射

R1(config)#ip nat inside source list 1 interface fastEthernet 0/1 overload 

4、指定內部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations

調試(相當於是在路由器上進行抓包)

R1#debug ip nat 

R1#undebug all     關閉所有存在的抓包操作

最後的綜合實驗

1IP地址

server2: 192.168.1.10

pc2: 192.168.2.10

pc3: 192.168.3.10

pc4: 192.168.4.10

server1: 201.1.2.10

ms1:

f0/24: 172.16.0.1  255.255.0.0

vlan1: 192.168.1.1

vlan2: 192.168.2.1

vlan3: 192.168.3.1

vlan4: 192.168.4.1

router1:

f0/0: 172.16.0.2  255.255.0.0

f0/1: 201.1.1.1

router2: 

f0/0 : 201.1.1.2

f0/1 : 201.1.2.1

2、配置vlan

sw1-sw4配置vlan,並將端口加入到指定VLAN

與三層交換機相邊的端口配置中繼

ms1配置vlan,開啓三層交換

3、配置路由

ms1配置缺省路由

ip route 0.0.0.0 0.0.0.0 172.16.0.2

router1配置路由

ip route 0.0.0.0 0.0.0.0 201.1.1.2

ip route 192.168.0.0 255.255.0.0 172.16.0.1

正式筆記:

  1. 案例1:配置靜態NAT
  2. 案例2:配置端口映射
  3. 案例3:配置動態NAT
  4. 案例4PAT配置
  5. 案例5:辦公區Internet的訪問

1 案例1:配置靜態NAT

1.1 問題

隨着接入Internet的計算機數量的不斷猛增,IP地址資源也就愈加顯得捉襟見肘。事實上,除了中國教育和科研計算機網(CERNET)外,一般用戶幾乎申請不到整段的CIP地址。在其他ISP那裏,即使是擁有幾百臺計算機的大型局域網用戶,當他們申請IP地址時,所分配的地址也不過只有幾個或十幾個IP地址。顯然,這樣少的IP地址根本無法滿足網絡用戶的需求。

  • R1上配置靜態NAT使192.168.1.1轉換爲61.159.62.131192.168.1.2轉換爲61.159.62.132,實現外部網絡訪問。

1.2 方案

藉助於NAT,私有(保留)地址的"內部"網絡通過路由器發送數據包時,私有地址被轉換成合法的IP地址,一個局域網只需使用少量IP地址(甚至是1個)即可實現私有地址網絡內所有計算機與Internet的通信需求。

這種通過使用少量的公有IP 地址代表較多的私有IP 地址的方式,將有助於減緩可用IP地址空間的枯竭。而且還能夠有效地避免來自網絡外部的攻擊,隱藏並保護網絡內部的計算機。

網絡拓撲如圖-1所示:

http://pdf7.tarena.com.cn/tts8_source/ttsPage/LINUX/NSD_V05/CISCO/DAY05/CASE/01/index.files/image001.png

圖-1

1.3 步驟

實現此案例需要按照如下步驟進行。

步驟一:通用配置

1)配置R1端口IP地址,以及默認路由

  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip address 192.168.1.254 255.255.255.0
  3. tarena-R1(config-if)#no shutdown
  4. tarena-R1(config-if)#interface f0/1
  5. tarena-R1(config-if)#ip address 61.159.62.129 255.255.255.248
  6. tarena-R1(config-if)#no shutdown
  7. tarena-R1(config-if)#exit
  8. tarena-R1(config)#ip route 0.0.0.0 0.0.0.0 f0/1

2)配置R2端口IP地址

不需要在R2上配置到企業內網的靜態路由,因爲NAT的存在,企業內部的地址都將被轉換、隱藏。

  1. tarena-R2(config)#interface f0/0
  2. tarena-R2(config-if)#ip address 61.159.62.130 255.255.255.248
  3. tarena-R2(config-if)#no shutdown
  4. tarena-R2(config-if)#interface f0/1
  5. tarena-R2(config-if)#ip address 192.168.2.254 255.255.255.0
  6. tarena-R2(config-if)#no shutdown

步驟二:靜態NAT配置

1)在R1上將192.168.1.1映射到61.159.62.131,將192.168.1.2映射到61.159.62.132

靜態映射有唯一對應的關係。

通過靜態NAT,可以把內網服務器發佈到外網。

  1. tarena-R1(config)#ip nat inside source static 192.168.1.1 61.159.62.131
  2. tarena-R1(config)#ip nat inside source static 192.168.1.2 61.159.62.132

2)在R1上配置NAT內、外端口

  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip nat inside
  3. tarena-R1(config-if)#interface f0/1
  4. tarena-R1(config-if)#ip nat outside

3)分別在兩臺PC機上測試到外網主機的通信

PC1測試如下所示:

  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

PC2的測試如下所示:

  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::200:CFF:FEEA:DE30
  4. IP Address......................: 192.168.1.2
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Request timed out.
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 0ms, Average = 0ms
  17. PC>

4)在R1上查看NAT轉換表

  1. tarena-R1#show ip nat translations
  2. Pro Inside global Inside local Outside local Outside global
  3. icmp 61.159.62.131:10 192.168.1.1:10 192.168.2.1:10 192.168.2.1:10
  4. icmp 61.159.62.131:11 192.168.1.1:11 192.168.2.1:11 192.168.2.1:11
  5. icmp 61.159.62.131:12 192.168.1.1:12 192.168.2.1:12 192.168.2.1:12
  6. icmp 61.159.62.131:9 192.168.1.1:9 192.168.2.1:9 192.168.2.1:9
  7. icmp 61.159.62.132:27 192.168.1.2:27 192.168.2.1:27 192.168.2.1:27
  8. icmp 61.159.62.132:28 192.168.1.2:28 192.168.2.1:28 192.168.2.1:28
  9. icmp 61.159.62.132:29 192.168.1.2:29 192.168.2.1:29 192.168.2.1:29
  10. icmp 61.159.62.132:30 192.168.1.2:30 192.168.2.1:30 192.168.2.1:30

2 案例2:配置端口映射

2.1 問題

通過端口映射技術將內部服務器發佈向Internet。

2.2 方案

在R1上配置端口映射將192.168.1.3的80端口映射爲61.159.62.133的80端口,將web服務器發佈到Internet。網絡拓撲如圖-2所示:

http://pdf7.tarena.com.cn/tts8_source/ttsPage/LINUX/NSD_V05/CISCO/DAY05/CASE/01/index.files/image002.png

圖-2

2.3 步驟

實現此案例需要按照如下步驟進行。

步驟一:通用配置

1)在案例一基礎上取消靜態轉換條目,在192.168.1.0網絡新增一臺web服務器IP爲192.168.1.3。將192.168.1.3的80端口映射爲61.159.62.133的80端口

  1. tarena-R1(config)#no ip nat inside source static 192.168.1.1 61.159.62.131
  2. tarena-R1(config)#no ip nat inside source static 192.168.1.2 61.159.62.132
  3. tarena-R1 (config)#ip nat inside source static tcp 192.168.1.3 80 61.159.62.133 80

步驟二:PC3上訪問web服務器進行驗證

1)外部主機PC4上訪問61.159.62.133進行驗證,如圖-3所示

http://pdf7.tarena.com.cn/tts8_source/ttsPage/LINUX/NSD_V05/CISCO/DAY05/CASE/01/index.files/image003.png

-3

3 案例3:配置動態NAT

3.1 問題

  • R1通過動態NAT實現企業內網192.168.1.0/24轉換爲公網地址61.159.62.131-61.159.62.134,訪問192.168.2.1

3.2 方案

網絡拓撲如圖-4所示:

http://pdf7.tarena.com.cn/tts8_source/ttsPage/LINUX/NSD_V05/CISCO/DAY05/CASE/01/index.files/image004.png

圖-4

3.3 步驟

實現此案例需要按照如下步驟進行。

步驟一:動態NAT配置

1)刪除案例2中的端口映射

  1. tarena-R1 (config)#no ip nat inside source static tcp 192.168.1.3 80 61.159.62.133 80

2)在R1上配置ACL

  1. tarena-R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

3)在R1上配置可轉換的公網IP地址池

地址池是向ISPInternet服務提供商,如電信、聯通)申請得到的,內網主機(上一步ACL中所包含的IP地址)到外網的訪問,內網地址將被動態的、隨機的轉換爲這些合法地址。

  1. tarena-R1(config)#ip nat pool natpool 61.159.62.131 61.159.62.134 netmask 255.255.255.248

4)關聯ACL和公網的IP地址池

  1. tarena-R1(config)#ip nat inside source list 1 pool natpool

5)在R1上配置NAT內、外端口

  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip nat inside
  3. tarena-R1(config-if)#interface f0/1
  4. tarena-R1(config-if)#ip nat outside

6)分別在兩臺PC機上測試到外網主機的通信

PC1測試如下所示:

  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

PC2測試如下所示:

  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.2
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms

7)在R1上查看NAT轉換表

轉換表中的對應關係是動態的,如192.168.1.1被轉換爲61.159.62.131,但是下一次對外網的訪問很有可能被轉換爲其他地址。

  1. tarena-R1#show ip nat translations
  2. Pro Inside global Inside local Outside local Outside global
  3. icmp 61.159.62.131:1362192.168.1.1:1362 192.168.2.1:1362 192.168.2.1:1362
  4. icmp 61.159.62.131:1392192.168.1.1:1392 192.168.2.1:1392 192.168.2.1:1392
  5. icmp 61.159.62.131:1393192.168.1.1:1393 192.168.2.1:1393 192.168.2.1:1393
  6. icmp 61.159.62.131:1394192.168.1.1:1394 192.168.2.1:1394 192.168.2.1:1394
  7. icmp 61.159.62.132:13 192.168.1.2:13 192.168.2.1:13 192.168.2.1:13
  8. icmp 61.159.62.132:14 192.168.1.2:14 192.168.2.1:14 192.168.2.1:14
  9. icmp 61.159.62.132:15 192.168.1.2:15 192.168.2.1:15 192.168.2.1:15
  10. icmp 61.159.62.132:16 192.168.1.2:16 192.168.2.1:16 192.168.2.1:16

4 案例4PAT配置

4.1 問題

R1配置PAT端口多路複用使企業內網192.168.1.0/24複用f0/1端口的IP,實現外部網絡的訪問。

4.2 方案

網絡拓撲如圖-5所示:

http://pdf7.tarena.com.cn/tts8_source/ttsPage/LINUX/NSD_V05/CISCO/DAY05/CASE/01/index.files/image005.png

圖-5

4.3 步驟

實現此案例需要按照如下步驟進行。

步驟一:基於端口的PAT配置限制

1)刪除案例3中動態NAT配置

  1. tarena-R1(config)#no ip nat inside source list 1
  2. tarena-R1(config)#no ip nat pool natpool
  3. tarena-R1(config)#no access-list 1

2)在R1上配置ACL

  1. tarena-R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

3)關聯ACL和路由器連接互聯網的端口

該命令最後加上的overload表示複用。

  1. tarena-R1(config)#ip nat inside source list 1 interface f0/1 overload

4)在R1上配置NAT內、外端口

  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip nat inside
  3. tarena-R1(config-if)#interface f0/1
  4. tarena-R1(config-if)#ip nat outside

5)分別在兩臺PC機上測試到外網主機的通信

PC1測試如下所示:

  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

PC2測試如下所示:

  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.2
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

6)在R1上查看NAT轉換表

  1. tarena-R1#show ip nat translations
  2. Pro Inside global Inside local Outside local Outside global
  3. icmp 61.159.62.129:2029192.168.1.1:2029 192.168.2.1:2029 192.168.2.1:2029
  4. icmp 61.159.62.129:2030192.168.1.1:2030 192.168.2.1:2030 192.168.2.1:2030
  5. icmp 61.159.62.129:2031192.168.1.1:2031 192.168.2.1:2031 192.168.2.1:2031
  6. icmp 61.159.62.129:2032192.168.1.1:2032 192.168.2.1:2032 192.168.2.1:2032
  7. icmp 61.159.62.129:2033192.168.1.1:2033 192.168.2.1:2033 192.168.2.1:2033
  8. icmp 61.159.62.129:2034192.168.1.1:2034 192.168.2.1:2034 192.168.2.1:2034
  9. icmp 61.159.62.129:2035192.168.1.1:2035 192.168.2.1:2035 192.168.2.1:2035

輸出結果顯示,所有的內網IP地址在訪問外網前均被轉換成了路由器端口的IP地址。

5 案例5:辦公區Internet的訪問

5.1 問題

在R1配置PAT端口多路複用使企業內網192.168.1.0/24複用f0/1端口的IP,實現外部網絡的訪問。

5.2 方案

網絡拓撲如圖-6所示:

http://pdf7.tarena.com.cn/tts8_source/ttsPage/LINUX/NSD_V05/CISCO/DAY05/CASE/01/index.files/image006.png

圖-6

5.3 步驟

實現此案例需要按照如下步驟進行。

步驟一:在SM1劃分vlan2、vlan3、vlan4 並給SM1配置虛端口IP並開啓路由功能,1-4接口開啓trunk

1)創建vlan並設置管理IP,開啓路由功能,並把相應的接口劃分到vlan下

  1. SM1 (config)ip routing
  2. SM1 (config)#vlan 2
  3. SM1 (config-vlan)#vlan 3
  4. SM1 (config-vlan)#vlan 4
  5. SM1 (config-vlan)#
  6. SM1 (config-vlan)#exit
  7. SM1 (config)#interface vlan 1
  8. SM1 (config-if)#ip address 192.168.1.254 255.255.255.0
  9. SM1 (config-if)#eixt
  10. SM1 (config-if)#no shutdown
  11. SM1 (config-if)#exit
  12. SM1 (config)#interface vlan 2
  13. SM1 (config-if)#ip address 192.168.2.254 255.255.255.0
  14. SM1 (config-if)#no shutdown
  15. SM1 (config-if)#exit
  16. SM1 (config)#interface vlan 3
  17. SM1 (config-if)#ip address 192.168.3.254 255.255.255.0
  18. SM1 (config-if)#no shutdown
  19. SM1 (config-if)#exit
  20. SM1 (config)#interface vlan 4
  21. SM1 (config-if)#ip address 192.168.4.254 255.255.255.0
  22. SM1 (config-if)#no shutdown
  23.  
  24. sw2(config)#vlan 2
  25. sw2(config-vlan)#exit
  26. sw2(config)#interface fastEthernet 0/1
  27. sw2(config-if)#switchport access vlan 2
  28.  
  29. sw3(config)#vlan 3
  30. sw3(config-vlan)#exit
  31. sw3(config)#interface fastEthernet 0/1
  32. sw3(config-if)#switchport access vlan 3
  33.  
  34. sw4(config)#vlan 4
  35. sw4(config-vlan)#exit
  36. sw4(config)#interface fastEthernet 0/1
  37. sw4(config-if)#switchport access vlan 4

2)交換機之間所連接的接口開啓trunk

  1. SM1(config)#interface range f0/1 - 4
  2. SM1 (config-if-range)#switchport trunk encapsulation dot1q
  3. SM1 (config-if-range)#switchport mode trunk
  4.  
  5. sw1(config)#interface fastEthernet 0/3
  6. sw1(config-if)#switchport mode trunk
  7.  
  8. sw2(config)#interface fastEthernet 0/3
  9. sw2(config-if)#switchport mode trunk
  10.  
  11. sw3(config)#interface fastEthernet 0/3
  12. sw3(config-if)#switchport mode trunk
  13.  
  14. sw4(config)#interface fastEthernet 0/3
  15. sw4(config-if)#switchport mode trunk

3)測試vlan之間的連通性

  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::290:21FF:FEC2:1A50
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7.  
  8. PC>ping 192.168.2.1
  9. Pinging 192.168.2.1 with 32 bytes of data:
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  13. Reply from 192.168.2.1: bytes=32 time=1ms TTL=12
  14. Ping statistics for 192.168.2.1:
  15. Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
  16. Approximate round trip times in milli-seconds:
  17. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  18.  
  19. PC>ping 192.168.3.1
  20. Pinging 192.168.3.1 with 32 bytes of data:
  21. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  22. Reply from 192.168.3.1: bytes=32 time=0ms TTL=127
  23. Reply from 192.168.3.1: bytes=32 time=0ms TTL=127
  24. Reply from 192.168.3.1: bytes=32 time=1ms TTL=127
  25. Ping statistics for 192.168.3.1:
  26. Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
  27. Approximate round trip times in milli-seconds:
  28. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  29.  
  30. PC>ping 192.168.4.1
  31. Pinging 192.168.4.1 with 32 bytes of data:
  32. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  33. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  34. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  35. Reply from 192.168.4.1: bytes=32 time=0ms TTL=127
  36. Ping statistics for 192.168.4.1:
  37. Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
  38. Approximate round trip times in milli-seconds:
  39. Minimum = 0ms, Maximum = 0ms, Average = 0ms

4)爲SM1與路由器連接的接口和路由器配置IP並啓用動態路由RIP協議.

  1. SM1(config)#interface fastEthernet 0/5
  2. SM1(config-if)#no switchport
  3. SM1(config-if)#ip add 192.168.5.1 255.255.255.0
  4. SM1(config-if)#no shutdown
  5. SM1(config-if)#exit
  6. SM1(config)#router rip
  7. SM1(config-router)#version 2
  8. SM1(config-router)#no auto-summary
  9. SM1(config-router)#network 192.168.1.0
  10. SM1(config-router)#network 192.168.2.0
  11. SM1(config-router)#network 192.168.3.0
  12. SM1(config-router)#network 192.168.4.0
  13. SM1(config-router)#network 192.168.5.0
  14.  
  15. Router(config)#interface fastEthernet 0/0
  16. Router(config-if)#ip address 192.168.5.2 255.255.255.0
  17. Router(config-if)#no shutdown
  18. Router(config-if)#exit
  19. Router(config)#interface fastEthernet 0/1
  20. Router(config-if)#ip address 61.159.62.129 255.255.255.248
  21. Router(config-if)#exit
  22. Router(config)#router rip
  23. Router(config-router)#version 2
  24. Router(config-router)#no auto-summary
  25. Router(config-router)#network 192.168.5.0

5)在路由器上配置默認路由併發布到RIP協議裏並在三成交換機SM1上查看路由表

  1. Router(config)#ip route 0.0.0.0 0.0.0.0 f0/1
  2. Router(config)#router rip
  3. Router(config-router)#default-information originate

SM路由表如下所示:

  1. SM1# show ip route
  2. Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
  3. D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
  4. N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
  5. E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
  6. i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
  7. * - candidate default, U - per-user static route, o - ODR
  8. P - periodic downloaded static route
  9. Gateway of last resort is 192.168.5.2 to network 0.0.0.0
  10. C 192.168.1.0/24 is directly connected, Vlan1
  11. C 192.168.2.0/24 is directly connected, Vlan2
  12. C 192.168.3.0/24 is directly connected, Vlan3
  13. C 192.168.4.0/24 is directly connected, Vlan4
  14. C 192.168.5.0/24 is directly connected, FastEthernet0/5
  15. R* 0.0.0.0/0 [120/1] via 192.168.5.2, 00:00:18, FastEthernet0/5

6)在路由器上配置PAT

  1. Router(config)#access-list 1 permit 192.168.4.0 0.0.0.255
  2. Router(config)#ip nat inside source list 1 interface f0/1
  3. Router(config)#interface fastEthernet 0/0
  4. Router(config-if)#ip nat inside
  5. Router(config-if)#exit
  6. Router(config)#interface fastEthernet 0/1
  7. Router(config-if)#ip nat outside

7)用192.168.4.0192.168.1.0測試網絡連通性

PC1

  1. PC>ping 61.159.62.130
  2. Pinging 61.159.62.130 with 32 bytes of data:
  3. Request timed out.
  4. Request timed out.
  5. Request timed out.
  6. Request timed out.
  7. Ping statistics for 61.159.62.130:
  8. Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

PC4

  1. PC>ping 61.159.62.130
  2.  
  3. Pinging 61.159.62.130 with 32 bytes of data:
  4.  
  5. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  6. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  7. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  8. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  9.  
  10. Ping statistics for 61.159.62.130:
  11. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  12. Approximate round trip times in milli-seconds:
  13. Minimum = 0ms, Maximum = 0ms, Average = 0ms

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章