10_01_23
网关:连接不同网段的中间人
路由器1
路由器0/0/0&网段1:192.168.1.1
路由器0/0/1&网段2:100.100.100.1
pc4
ip:100.100.100.100
掩码:255.255.255.0
网关:100.100.100.1
路由器配置:
<Huawei>sy
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 100.100.100.1 255.255.255.0
Oct 1 2023 13:23:39-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[0]:The line protocol
IP on the interface GigabitEthernet0/0/1 has entered the UP state.
pc1->pc4
PC>ping 100.100.100.1
Ping 100.100.100.1: 32 data bytes, Press Ctrl_C to break
From 100.100.100.1: bytes=32 seq=1 ttl=255 time=31 ms
From 100.100.100.1: bytes=32 seq=2 ttl=255 time=47 ms
From 100.100.100.1: bytes=32 seq=3 ttl=255 time=47 ms
From 100.100.100.1: bytes=32 seq=4 ttl=255 time=31 ms
From 100.100.100.1: bytes=32 seq=5 ttl=255 time=31 ms
--- 100.100.100.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 31/37/47 ms
不同网段间通讯,靠路由器转发,路由表依据判断。
查看路由器路由表
[Huawei]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
Destination/Mask Proto Pre Cost Flags NextHop Interface
100.100.100.0/24 Direct 0 0 D 100.100.100.1 GigabitEthernet
0/0/1
100.100.100.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
100.100.100.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 Direct 0 0 D 192.168.1.1 GigabitEthernet
0/0/0
192.168.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
只查看想要的ip的路由表
[Huawei]display ip routing-table 100.100.100.100
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
100.100.100.0/24 Direct 0 0 D 100.100.100.1 GigabitEthernet
0/0/1
-
多台路由器间通讯
pc1
ip:192.168.1.1
RA 0/0/0&网关:192.168.1.10
路由器1配置
0/0/0:192.168.1.10(1段网关)
0/0/1:192.168.2.1
code
[Huawei]sysname RA {更改路由器1的名字}
[RA]int g0/0/0 {0/0/0}
[RA-GigabitEthernet0/0/0]ip add 192.168.1.10 255.255.255.0
Oct 1 2023 13:48:09-08:00 RA %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[RA-GigabitEthernet0/0/0]
[RA]int g0/0/1 {0/0/1}
[RA-GigabitEthernet0/0/1]ip add 192.168.2.1 255.255.255.0
Oct 1 2023 13:49:47-08:00 RA %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
路由器2配置
0/0/0:192.168.2.10(2段网关)
0/0/1:192.168.3.1
code
<Huawei>sy
[Huawei]sysname RB
[RB]int g0/0/0
[RB-GigabitEthernet0/0/0]ip add 192.168.2.10 255.255.255.0
Oct 1 2023 13:53:02-08:00 RB %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
on the interface GigabitEthernet0/0/0 has entered the UP state.
[RB-GigabitEthernet0/0/0]q
[RB]int g0/0/1
[RB-GigabitEthernet0/0/1]ip add 192.168.3.1 255.255.255.0
Oct 1 2023 13:56:41-08:00 RB %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
on the interface GigabitEthernet0/0/1 has entered the UP state.
查看RA路由表,是否有去往192.168.3.10的路由
<RA>dis ip routing-table 192.168.3.10
<RA>
并没有前往的路由。
对RA添加静态路由,并查看有没有新添加路由表
[RA]ip route-static 192.168.3.0 255.255.255.0 192.168.2.10
//{(添加新路由表) 下一跳地址 }
[RA]display ip routing-table 192.168.3.10 //{(查看新路由表)}
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
192.168.3.0/24 Static 60 0 RD 192.168.2.10 GigabitEthernet
0/0/1
此时pc1依然无法ping通192.168.3.10,因为RB(路由器2)没有通往192.168.1.1的路由表。
pc1 dos code
PC>ping 192.168.3.10
Ping 192.168.3.10: 32 data bytes, Press Ctrl_C to break
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
From 192.168.1.1: Destination host unreachable
--- 190.168.1.10 ping statistics ---
5 packet(s) transmitted
0 packet(s) received
100.00% packet loss
查看路由器2
<RB>dis ip routing-table 192.168.1.1
<RB>
再为RB添加新路由,并查看路由表
[RB]ip route-static 192.168.1.0 255.255.255.0 192.168.2.1
[RB]dis ip routing-table 192.168.1.1
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
192.168.1.0/24 Static 60 0 RD 192.168.2.1 GigabitEthernet
0/0/0
再次测试pc1,能否ping通
PC>ping 192.168.3.10
Ping 192.168.3.10: 32 data bytes, Press Ctrl_C to break
From 192.168.3.10: bytes=32 seq=1 ttl=253 time=15 ms
From 192.168.3.10: bytes=32 seq=2 ttl=253 time=16 ms
From 192.168.3.10: bytes=32 seq=3 ttl=253 time=16 ms
From 192.168.3.10: bytes=32 seq=4 ttl=253 time=15 ms
From 192.168.3.10: bytes=32 seq=5 ttl=253 time=16 ms
--- 192.168.3.10 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 15/15/16 ms
圆满成功!!!