实例

image.png

基本配置

  1. 首先进入系统视图,进入系统视图之后就可以配置路由器了
  2. system-view 回车
  3. Enter system view, return user view with Ctrl+Z.
  4. 修改路由器的名称
  5. [Huawei]sysname R2
  6. [R2]
  7. 配置接口
  8. [R2]interface Vlanif 1
  9. [R2-Vlanif1]
  10. [R2-Vlanif1]ip address 192.168.1.1 24
  11. 或者
  12. [R2-Vlanif1]ip address 192.168.1.1 255.255.255.0
  13. [R2-Vlanif1]
  14. 删除IP地址
  15. undo ip address
  16. 查看接口地址
  17. [R2-Vlanif1]display this
  18. [V200R003C00]
  19. #
  20. interface Vlanif1
  21. ip address 192.168.1.1 255.255.255.0
  22. #
  23. return
  24. [R2-Vlanif1]
  25. 退出接口继续其他的配置
  26. [R2-Vlanif1]quit
  27. [R2]
  28. 配置GigabitEthernet接口
  29. 进入GigabitEthernet接口
  30. [R2]interface GigabitEthernet 0/0/0
  31. [R2-GigabitEthernet0/0/0]
  32. 配置ip地址
  33. [R2-GigabitEthernet0/0/0]ip address 20.1.1.1 24
  34. Apr 19 2022 20:26:18-08:00 R2 %%01IFNET/4/LINK_STATE(l)[4]:The line protocol IP
  35. on the interface GigabitEthernet0/0/0 has entered the UP state.
  36. [R2-GigabitEthernet0/0/0]

配置路由器R1

  1. <Huawei>system-view
  2. Enter system view, return user view with Ctrl+Z.
  3. [Huawei]sys
  4. [Huawei]sysname R1
  5. [R1]
  6. [R1]interface GigabitEthernet 0/0/0
  7. [R1-GigabitEthernet0/0/0]ip add
  8. [R1-GigabitEthernet0/0/0]ip address 20.1.1.2 24
  9. Apr 19 2022 20:28:53-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
  10. on the interface GigabitEthernet0/0/0 has entered the UP state.
  11. [R1-GigabitEthernet0/0/0]
  12. [R1-GigabitEthernet0/0/0]ping 20.1.1.1
  13. PING 20.1.1.1: 56 data bytes, press CTRL_C to break
  14. Reply from 20.1.1.1: bytes=56 Sequence=1 ttl=255 time=90 ms
  15. Reply from 20.1.1.1: bytes=56 Sequence=2 ttl=255 time=20 ms
  16. Reply from 20.1.1.1: bytes=56 Sequence=3 ttl=255 time=20 ms
  17. Reply from 20.1.1.1: bytes=56 Sequence=4 ttl=255 time=30 ms
  18. Reply from 20.1.1.1: bytes=56 Sequence=5 ttl=255 time=20 ms
  19. --- 20.1.1.1 ping statistics ---
  20. 5 packet(s) transmitted
  21. 5 packet(s) received
  22. 0.00% packet loss
  23. round-trip min/avg/max = 20/36/90 ms
  24. [R1-GigabitEthernet0/0/0]
  25. [R1-GigabitEthernet0/0/0]quit
  26. [R1]inter
  27. [R1]interface g
  28. [R1]interface GigabitEthernet 0/0/1
  29. [R1-GigabitEthernet0/0/1]
  30. [R1-GigabitEthernet0/0/1]ip address 20.1.2.2 24
  31. Apr 19 2022 20:31:35-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP
  32. on the interface GigabitEthernet0/0/1 has entered the UP state.
  33. [R1-GigabitEthernet0/0/1]

配置路由器R3

  1. <Huawei>system-view
  2. Enter system view, return user view with Ctrl+Z.
  3. [Huawei]sys
  4. [Huawei]sysname R3
  5. [R3]
  6. [R3]interface GigabitEthernet 0/0/0
  7. [R3-GigabitEthernet0/0/0]ip address 20.1.2.1 24
  8. [R3-GigabitEthernet0/0/0]
  9. Apr 19 2022 20:32:56-08:00 R3 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP
  10. on the interface GigabitEthernet0/0/0 has entered the UP state.
  11. [R3-GigabitEthernet0/0/0]
  12. [R3-GigabitEthernet0/0/0]ping 20.1.2.2
  13. PING 20.1.2.2: 56 data bytes, press CTRL_C to break
  14. Reply from 20.1.2.2: bytes=56 Sequence=1 ttl=255 time=140 ms
  15. Reply from 20.1.2.2: bytes=56 Sequence=2 ttl=255 time=40 ms
  16. Reply from 20.1.2.2: bytes=56 Sequence=3 ttl=255 time=20 ms
  17. Reply from 20.1.2.2: bytes=56 Sequence=4 ttl=255 time=50 ms
  18. Reply from 20.1.2.2: bytes=56 Sequence=5 ttl=255 time=40 ms
  19. --- 20.1.2.2 ping statistics ---
  20. 5 packet(s) transmitted
  21. 5 packet(s) received
  22. 0.00% packet loss
  23. round-trip min/avg/max = 20/58/140 ms
  24. [R3-GigabitEthernet0/0/0]
  25. [R3]interface Vlanif 1
  26. Apr 19 2022 20:34:06-08:00 R3 %%01IFNET/4/IF_STATE(l)[1]:Interface Vlanif1 has t
  27. urned into UP state.
  28. [R3-Vlanif1]ip address 192.168.2.1 2
  29. Error: The specified IP address is invalid.
  30. [R3-Vlanif1]ip address 192.168.2.1 24
  31. Apr 19 2022 20:34:46-08:00 R3 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP
  32. on the interface Vlanif1 has entered the UP state.
  33. [R3-Vlanif1]ping 192.168.2.2
  34. PING 192.168.2.2: 56 data bytes, press CTRL_C to break
  35. Reply from 192.168.2.2: bytes=56 Sequence=1 ttl=128 time=110 ms
  36. Reply from 192.168.2.2: bytes=56 Sequence=2 ttl=128 time=20 ms
  37. Reply from 192.168.2.2: bytes=56 Sequence=3 ttl=128 time=10 ms
  38. Reply from 192.168.2.2: bytes=56 Sequence=4 ttl=128 time=20 ms
  39. Reply from 192.168.2.2: bytes=56 Sequence=5 ttl=128 time=30 ms
  40. --- 192.168.2.2 ping statistics ---
  41. 5 packet(s) transmitted
  42. 5 packet(s) received
  43. 0.00% packet loss
  44. round-trip min/avg/max = 10/38/110 ms
  45. [R3-Vlanif1]

查看配置:

  1. <R1>display current-configuration

保存配置:

  1. <R1>save
  2. The current configuration will be written to the device.
  3. Are you sure to continue? (y/n)[n]:y
  4. It will take several minutes to save configuration file, please wait.......
  5. Configuration file had been saved successfully
  6. Note: The configuration file will take effect after being activated

确认是否保存:

  1. <R1>dir
  2. Directory of flash:/
  3. Idx Attr Size(Byte) Date Time(LMT) FileName
  4. 0 drw- - Apr 19 2022 12:00:41 dhcp
  5. 1 -rw- 121,802 May 26 2014 09:20:58 portalpage.zip
  6. 2 -rw- 2,263 Apr 19 2022 12:21:01 statemach.efs
  7. 3 -rw- 828,482 May 26 2014 09:20:58 sslvpn.zip
  8. 4 -rw- 352 Apr 19 2022 12:39:21 private-data.txt
  9. 5 -rw- 583 Apr 19 2022 12:39:21 vrpcfg.zip
  10. 1,090,732 KB total (784,448 KB free)
  11. <R1> 看到 vrpcfg.zip 说明保存成功

设置静态路由

网络畅通的前提是:有去有回
路由器默认只知道直连的网段:没有直连的需要哦管理员添加静态路由

配置R2路由

  1. 查看路由
  2. <R2>display ip routing-table
  3. Route Flags: R - relay, D - download to fib
  4. ------------------------------------------------------------------------------
  5. Routing Tables: Public
  6. Destinations : 10 Routes : 10
  7. Destination/Mask Proto Pre Cost Flags NextHop Interface
  8. 20.1.1.0/24 Direct 0 0 D 20.1.1.1 GigabitEthernet
  9. 0/0/0
  10. 20.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
  11. 0/0/0
  12. 20.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
  13. 0/0/0
  14. 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
  15. 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
  16. 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
  17. 192.168.1.0/24 Direct 0 0 D 192.168.1.1 Vlanif1
  18. 192.168.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif1
  19. 192.168.1.255/32 Direct 0 0 D 127.0.0.1 Vlanif1
  20. 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
  21. Direct:直连
  22. <R2>
  23. 添加网络20.1.2.0 24的静态路由
  24. <R2>ip route-static 20.1.2.0 24 20.1.1.2
  25. 添加网络192.168.2.0 24的静态路由
  26. [R2]ip route-static 192.168.2.0 24 20.1.1.2

配置R1路由

  1. 添加网络192.168.1.0 24的静态路由
  2. <R2>ip route-static 192.168.1.0 24 20.1.1.1
  3. 添加网络192.168.2.0 24的静态路由
  4. [R2]ip route-static 192.168.2.0 24 20.1.2.1

配置R3路由

  1. 添加网络192.168.1.0 24的静态路由
  2. <R2>ip route-static 192.168.1.0 24 20.1.2.2
  3. 添加网络20.1.1.0 24的静态路由
  4. [R2]ip route-static 20.1.1.0 24 20.1.2.2
  5. <R3>system-view
  6. Enter system view, return user view with Ctrl+Z.
  7. [R3]ip route-static 20.1.1.0 24 20.1.2.2
  8. [R3]ip route-static 192.168.1.0 24 20.1.2.2

结果验证

  1. Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break
  2. Request timeout!
  3. From 192.168.2.2: bytes=32 seq=2 ttl=125 time=47 ms
  4. From 192.168.2.2: bytes=32 seq=3 ttl=125 time=15 ms
  5. From 192.168.2.2: bytes=32 seq=4 ttl=125 time=31 ms
  6. From 192.168.2.2: bytes=32 seq=5 ttl=125 time=31 ms
  7. --- 192.168.2.2 ping statistics ---
  8. 5 packet(s) transmitted
  9. 4 packet(s) received
  10. 20.00% packet loss
  11. round-trip min/avg/max = 0/31/47 ms
  1. PC>tracert 192.168.2.2
  2. traceroute to 192.168.2.2, 8 hops max
  3. (ICMP), press Ctrl+C to stop
  4. 1 192.168.1.1 47 ms <1 ms 15 ms
  5. 2 20.1.1.2 63 ms 31 ms 31 ms
  6. 3 20.1.2.1 47 ms 31 ms 32 ms
  7. 4 192.168.2.2 46 ms 32 ms 47 ms
  8. PC>

实例

实例01

如下图所示,新增一台公网IP电脑
华为路由器的配置 - 图2
其地址分配如下
image.png
PC端设置如下:
image.png
AR1设置如下:

  1. // 进入系统
  2. <R1>system-view
  3. Enter system view, return user view with Ctrl+Z.
  4. // 进入接口1
  5. [R1]interface Vlanif 1
  6. // 设置IP地址
  7. [R1-Vlanif1]ip address 30.1.1.100 24
  8. // 查看接口是否设置成功
  9. [R1-Vlanif1]display this
  10. [V200R003C00]
  11. #
  12. interface Vlanif1
  13. ip address 30.1.1.100 255.255.255.0
  14. #
  15. return
  16. [R1-Vlanif1]
  17. // 退出
  18. [R1]quit
  19. [R1]quit
  20. // 保存
  21. <R1>save
  22. The current configuration will be written to the device.
  23. Are you sure to continue? (y/n)[n]:y
  24. It will take several minutes to save configuration file, please wait.........
  25. Configuration file had been saved successfully
  26. Note: The configuration file will take effect after being activated
  1. # 添加网络30.1.1.99 32的静态路由
  2. # 由于其跟路由器中的接口处于同一网段,故不用单独配置路由表

AR2设置如下:

  1. # 添加网络30.1.1.99 32的静态路由
  2. <R2>system-view
  3. Enter system view, return user view with Ctrl+Z.
  4. [R2]ip route-static 30.1.1.99 32 20.1.1.2
  5. // 测试
  6. [R2]ping 30.1.1.99
  7. PING 30.1.1.99: 56 data bytes, press CTRL_C to break
  8. Reply from 30.1.1.99: bytes=56 Sequence=1 ttl=127 time=30 ms
  9. Reply from 30.1.1.99: bytes=56 Sequence=2 ttl=127 time=30 ms
  10. Reply from 30.1.1.99: bytes=56 Sequence=3 ttl=127 time=30 ms
  11. Reply from 30.1.1.99: bytes=56 Sequence=4 ttl=127 time=30 ms
  12. Reply from 30.1.1.99: bytes=56 Sequence=5 ttl=127 time=40 ms
  13. --- 30.1.1.99 ping statistics ---
  14. 5 packet(s) transmitted
  15. 5 packet(s) received
  16. 0.00% packet loss
  17. round-trip min/avg/max = 30/32/40 ms
  18. [R2]

实例02

新增一个公网IP,为期配置防火墙,如下所示
image.png
image.png
AR1设置如下:

  1. [Huawei]vlan 2
  2. [Huawei-vlan10]int vlanif 2
  3. [Huawei-Vlanif10]ip address 88.1.1.1 24
  4. [Huawei-Vlanif10]int e0/0/0
  5. [Huawei-Ethernet0/0/0]port link-type access
  6. [Huawei-Ethernet0/0/0]port default vlan 2
  7. //查看
  8. R1]interface Vlanif 10
  9. [R1-Vlanif10]displ
  10. [R1-Vlanif10]display this
  11. [V200R003C00]
  12. #
  13. interface Vlanif10
  14. ip address 88.1.1.1 24
  15. #
  16. return
  17. [R1-Vlanif10]

防火墙设置

  1. [SRG]int g0/0/0
  2. [SRG-GigabitEthernet0/0/0]ip address 88.1.1.2 24