注:在華為模擬器(eNSP)上做的實驗
其中,在內網實驗:Vlan/DHCP/VWeb/HTTP,在外網實驗:動態PAT/靜態NAT
一、拓撲結構
1. 核心設備與連接
設備 | 接口 | 連接對象 | VLAN/IP | 角色 |
LSW2/LSW3 | Ethernet 0/0/1-2 | PC1/PC4 | VLAN10/VLAN20 | 用戶VLAN劃分 |
Ethernet 0/0/3 | DHCP中繼 | VLAN ALL | ||
Ethernet 0/0/4 | AR5 | VLAN8 | Telnet | |
LSW4 | GE-0/0/1 | DHCP中繼(三層交換機)? | VLAN ALL | 網關/路由核心 |
GE-0/0/2-4 | AR1、Server1、Server2 | VLAN100 | DHCP、HPPT、DNS | |
DHCP中繼(三層交換機) | GE-0/0/1 | LSW4 | VLAN ALL | 連接服務器區域 |
Ethernet 0/0/2-3 | LSW2、LSW3 | VLAN ALL | ||
Ethernet 0/0/4 | AR2 | VLAN9 | 連接邊界路由器 | |
AR2邊界路由器 | GE-0/0/0(192.168.200.1) | DHCP中繼 | VLAN9 | 連接內網 |
GE-0/0/1(55.0.0.1) | AR4 | 連接外網 |
2. IP地址
SW1網關
vlan10:192.168.10.1 24?
vlan20:192.168.20.1 24
vlan100:192.168.100.1 24
vlan8:192.168.8.1 24 ?
vlan9:192.168.200.2 24?
DHCP接口:192.168.100.2
DNS:192.168.100.3
HPPT:192.168.100.4
Telnet接口:192.168.8.254 24
Lsw3:vlan8接口:192.168.8.2 24
Client3:56.0.0.2 24
Client1:192.168.20.253 24
二、配置邏輯
? 1.其中的DHCP中繼工作流程
?2.其中的NAT、PAT原理
? ? ? ?NAT/PAT核心作用:1.解決IPv4地址枯竭:將私有IP(如?192.168.x.x
)映射為公有IP訪問互聯網。2.隱藏內網拓撲:外部網絡只能看到NAT設備的公網IP,無法直接訪問內網主機。
? ? ? ?i. 動態NAT:只轉換IP地址,沒有節省地址。路由器的 NAT地址轉換表由內網設備上公網
的數據流觸發形成的。
ii. 動態PAT:轉換IP地址和端口,節省公網IP地址。路由器的 NAT地址轉換表由內網設備
上公網的數據流觸發形成的。
iii. 靜態NAT:只轉換IP地址,沒有節省地址。路由器的 NAT地址轉換表由管理員手工固定。
iv. 靜態PAT:轉換IP地址和端口,節省公網IP地址。路由器的 NAT地址轉換表由管理員手工固定。
三、內網設備配置(Vlan、DHCP、Telnet、HPPT、DNS)
LSW3/LSW2交換機:
vlan batch 10 20 8
interface Eth0/0/1
port link-type access
port default vlan 10
interface Eth0/0/2
port link-type access
port default vlan 20
interface Eth0/0/3 # 連接DHCP中繼port link-type trunkport trunk allow-pass vlan all
interface Eth0/0/4
port link-type access
???????port default vlan 8
interface vlan 8 # 連接Telnet
ip address 129.168.8.2 24
user-interface vty 0 4
authentication-mode aaa
quit
aaa
local-user huawei password cipher huawei #用戶密碼都是:huawei
local-user huawei sservice-type telnet
local-user huawei privilege level 15 #設置最高權限15 #其中user privilege level 15,為整個鏈路全設置權限15
ip route-static 0.0.0.0 0 192.168.8.1? ? ?#網關用默認路由
- ? ?LSW1:
vlan batch 10 20 100 200 8 9
port-group group-member g0/0/0 to g0/0/3? ? ?#同時配置多個一樣接口時#或寫成port-group group-member g0/0/0 g0/0/2?g0/0/3?
port link-type trunk
port trunk allow-pass vlan all
quit
interface GigabitEthernet 0/0/4
port link-type access
port default vlan 9interface vlan 10
ip address 129.168.10.1 24
interface vlan 20
ip address 129.168.20.1 24
interface vlan 100
ip address 129.168.100.1 24
dhcp enable
interface vlan 10
dhcp select relay
dhcp relay server-ip 192.168.100.2
interface vlan 20
dhcp select relay
dhcp relay server-ip 192.168.100.2
interface vlan 8
ip address 129.168.8.1 24
interface vlan 9
ip address 129.168.200.2 24
quitip route-static 0.0.0.0 0 192.168.200.1
- LSW4 :
vlan 100
quit
port-group group-member g0/0/2 to g0/0/4
port link-type access
port default vlan 100
interface Ethernet 0/0/1
port link-type trunk
port trunk allow-pass vlan all
- AR1:
interface GigabitEthernet 0/0/0
undo shutdown
ip address 192.168.100.2 24
quit
dhcp enable
ip pool vlan10
network 192.168.10.0 mask 24
gateway-list 192.168.10.1
dns-list 192.168.100.3
ip pool vlan20
network 192.168.20.0 mask 24
gateway-list 192.168.20.1
dns-list 192.168.100.3
ip route-static 192.168.10.0 24 192.168.100.1
ip route-static 192.168.20.0 24 192.168.100.1
int g0/0/0
dhcp select global
- AR5:
interface GigabitEthernet 0/0/0
ip address 192.168.8.254 24
quit
ip route-static 0.0.0.0 0?192.168.8.1??
- ?Server2(DNS服務器)
- Server1(HPPT服務器),選文件夾(需要有文件)
?四、外網設備配置(動態PAT/靜態NAT)
- AR2:
interface GigabitEthernet 0/0/0
ip address 192.168.200.1 24
interface GigabitEthernet 0/0/1
ip address 55.0.0.1 24
quit
ip route-static 0.0.0.0 0.0.0.0 55.0.0.2
ip route-static 192.168.10.0 24 192.168.200.2
ip route-static 192.168.20.0 24 192.168.200.2
ip route-static 192.168.100.0 24 192.168.200.2
- ??AR4:
interface GigabitEthernet 0/0/0
ip address 55.0.0.2 24
interface GigabitEthernet 0/0/1
ip address 56.0.0.1 24
?1.?動態PAT配置(客戶端訪問客戶端情況下)。
#動態PAT方法1 出接口轉換(1對1)
acl 2000
rule 10 permit source 192.168.10.0 0.0.0.255
rule 20 permit source 192.168.20.0 0.0.0.255
quit
interface GigabitEthernet 0/0/1
nat outbound 2000
quit
dis nat session protocol icmp #查看nat轉換
#動態PAT方法2 地址池轉換(多對一)
acl 2000
rule 10 permit source 192.168.10.0 0.0.0.255
rule 20 permit source 192.168.20.0 0.0.0.255
quit
nat address-group 1 55.0.0.5 55.0.0.8
interface GigabitEthernet 0/0/1
nat outbound 2000 address-group 1 #如果后面加no-pat就成nat了.對比Cisco模擬器加overload成Pat
dis nat session protocol icmp #查看nat轉換
?2.?靜態NAT(外網服務器訪問內網服務器情況下)
#靜態NAT (1對1)
interface GigabitEthernet 0/0/1
nat static global 55.0.0.9 inside 192.168.100.3
?3.?靜態PAT(外網服務器訪問內網服務器情況下)
? ? ? (1)端口轉換端口(外網服務器訪問內網服務器情況下)
#靜態NAT (1對1) 正常寫會失敗,由于模擬器問題,端口不轉換
# interface GigabitEthernet 0/0/1
# nat static protocol tcp global 55.0.0.9 8888 inside 192.168.100.3 80#由于端口不轉換,于是我們直接寫80,不換端口寫
interface GigabitEthernet 0/0/1
nat static protocol tcp global 55.0.0.9 80 inside 192.168.100.4 80 # 55.0.0.9為公網地址 192.168.100.3為內網服務器地址
? ? ? ?(2)域名轉換端口,外網DNS服務器訪問內網服務器
? ? ? ? ? ? ? ? ?在(1)基礎上,把Client域名訪問器寫好,給Server3配置:
? ??
?五、實驗驗證步驟
1. 內網實驗:Vlan、DHCP、Telnet、HTTP、DNS
?(1)Vlan實驗連通性測試?,vlan20的Client分別去ping? vlan10 PC1、vlan20 PC4。(都通因為vlan間沒有設置ACL)
?? ? ??
?(2)1/2服務區域連通性測試
Client不支持DHCP,Client配置需要手動給地址、網關、域名,然后去ping DHCP、HPPT、DNS服務器
??? ? ??
? ? ? ? ?2/2 Client訪問HTTP服務(Web服務器)
? ??
?(3)DHCP、DNS驗證
在PC通過DHCP獲取IP,并點擊應用,然后在命令行查看是否獲取到
? ?? ? ?
?(4)Telnet服務驗證,AR5遠程連接LSW3(輸入用戶、密碼)
? ??
2.? 外網實驗:動態PAT/靜態NAT
(1) 內網Client1去訪問外網Client3,可以看出成功ping通,并在AR2看到PAT轉換。
? ? 動態PAT方法1 出接口轉換(1對1)? ? ? ? ? ? ? ? ? ? ? ?? ?動態PAT方法2 地址池轉換(多對一)
? ? ? ? ? ? ? ? ? ??
?(2)靜態NAT,外網Client3訪問內網Web服務器,抓包如下:
? ?(3)靜態PAT
? ? ? ? ? ?i. 端口轉換端口(外網服務器訪問內網服務器情況下):
? ? ? ? ?
? ? ? ? ? ?正常寫,結果失敗了,然后抓包(一個入口一個出口),可以看出端口沒轉換,還是8888? ? ? ? ? 端口,這是模擬器問題。
? ? ? ? ??
? ? ? ??
? ? ? ? ? ? ?于是直接寫80端口,不換端口寫,成功了
? ? ? ? ? ?
? ? ? ?ii.?域名轉換端口,外網DNS服務器訪問內網服務器
? ? ? ? ??
六、關鍵命令
???????ping [目標IP]? ? ? ? ? ? ? ? #測試連通性
undo info-center?enable? ? ? #關閉日志中心功能,防止消息覆蓋命令
display current-configuration? ? ?#顯示設備當前運行的所有配置(含全局、接口、協議等)
display this? ? ? ? ? ? ?#顯示當前配置視圖下的生效命令
display ip routing-table? ? ? ? ?#顯示設備IPv4路由表。
display user-interface? ? ? ? ? ? #顯示用戶登錄會話信息。
?display ip interface brief? ? ? ? ? #查看所有接口的IP狀態摘要。
dis nat session protocol icmp? ? ? #顯示基于ICMP協議的NAT會話表項。
save? ? ? ??#保存當前配置到啟動文件。
注意:eNSP設備需要先save保存再保存拓撲圖,有時需要多點一下回車鍵
建議:在思科Cisco、華為eNSP或H3C CloudLab中復現拓撲,重點關注中繼設備與路由器間的路由可達性及交換機Trunk口配置。實際配置時需注意不同廠商命令差異
?附:思科設備對應命令參考
功能 | 華為 eNSP 命令 | Cisco IOS 命令 | |
---|---|---|---|
關閉日志消息 | undo info-center enable | no logging console | |
查看運行配置 | display current-configuration | show running-config | |
查看當前視圖配置 | display this | show running-config | section <視圖> | |
查看路由表 | display ip routing-table | show ip route | |
查看用戶會話 | display user-interface | show users | |
查看接口IP摘要 | display ip interface brief | show ip interface brief | |
查看NAT會話 | display nat session protocol icmp | show ip nat translations protocol icmp | |
保存配置 | save | write memory ?或?copy run start | |
查看ARP表 | display arp | show arp | |
接口狀態診斷 | display interface GigabitEthernet0/0/1 | show interfaces GigabitEthernet0/1 |