Example for Configuring IPv4 Static Routes
Networking Requirements
Servers on different network segments are connected using several Switches. Every two servers on different network segments can communicate with each other without using dynamic routing protocols.
Configuration Roadmap
The configuration roadmap is as follows:
- Create VLANs, add interfaces to the VLANs, and assign IPv4 addresses to VLANIF interfaces so that directly-connected interfaces can communicate with each other.
- Configure the IPv4 default gateway on each server, and configure IPv4 static routes and default routes on each Switch so that servers on different network segments can communicate with each other.
Procedure
- Create VLANs and add interfaces to the VLANs.
<HUAWEI> system-view [~HUAWEI] sysname SwitchA [*HUAWEI] commit [~SwitchA] vlan 10 [*SwitchA-vlan10] quit [*SwitchA] vlan 30 [*SwitchA-vlan30] quit [*SwitchA] interface 10ge 1/0/1 [*SwitchA-10GE1/0/1] port link-type trunk [*SwitchA-10GE1/0/1] port trunk allow-pass vlan 10 [*SwitchA-10GE1/0/1] quit [*SwitchA] interface 10ge 1/0/2 [*SwitchA-10GE1/0/2] port default vlan 30 [*SwitchA-10GE1/0/2] quit [*SwitchA] commit
The configurations of SwitchB and SwitchC are similar to that of SwitchA, and are not provided here.
- Assign IPv4 addresses to the VLANIF interfaces.
[~SwitchA] interface vlanif 10 [*SwitchA-Vlanif10] ip address 10.1.4.1 30 [*SwitchA-Vlanif10] quit [*SwitchA] interface vlanif 30 [*SwitchA-Vlanif30] ip address 10.1.1.1 24 [*SwitchA-Vlanif30] quit [*SwitchA] commit
The configurations of SwitchB and SwitchC are similar to that of SwitchA, and are not provided here.
- Configure servers.
Set the Server1 default gateway to 10.1.1.1, the Server2 default gateway to 10.1.2.1, and the Server3 default gateway to 10.1.3.1.
- Configure static routes.
# Configure an IPv4 default route on SwitchA.
[~SwitchA] ip route-static 0.0.0.0 0.0.0.0 10.1.4.2 [*SwitchA] commit
# Configure two IPv4 static routes on SwitchB.
[~SwitchB] ip route-static 10.1.1.0 255.255.255.0 10.1.4.1 [*SwitchB] ip route-static 10.1.3.0 255.255.255.0 10.1.4.6 [*SwitchB] commit
# Configure an IPv4 default route on SwitchC.
[~SwitchC] ip route-static 0.0.0.0 0.0.0.0 10.1.4.5 [*SwitchC] commit
- Verify the configuration.
# Check the IP routing table on SwitchA.
[~SwitchA] display ip routing-table Proto: Protocol Pre: Preference Route Flags: R - relay, D - download to fib, T - to vpn-instance ------------------------------------------------------------------------------ Routing Table: _public_ Destinations : 10 Routes : 10 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 Static 60 0 RD 10.1.4.2 Vlanif10 10.1.1.0/24 Direct 0 0 D 10.1.1.1 Vlanif30 10.1.1.1/32 Direct 0 0 D 127.0.0.1 Vlanif30 10.1.4.0/30 Direct 0 0 D 10.1.4.1 Vlanif10 10.1.4.1/32 Direct 0 0 D 127.0.0.1 Vlanif10 10.1.4.2/32 Direct 0 0 D 10.1.4.2 Vlanif10 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 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
# Run the ping command to verify the connectivity.
[~SwitchA] ping 10.1.3.1 PING 1.1.3.1: 56 data bytes, press CTRL_C to break Reply from 10.1.3.1: bytes=56 Sequence=1 ttl=254 time=62 ms Reply from 10.1.3.1: bytes=56 Sequence=2 ttl=254 time=63 ms Reply from 10.1.3.1: bytes=56 Sequence=3 ttl=254 time=63 ms Reply from 10.1.3.1: bytes=56 Sequence=4 ttl=254 time=62 ms Reply from 10.1.3.1: bytes=56 Sequence=5 ttl=254 time=62 ms --- 10.1.3.1 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 62/62/63 ms
Configuration Files
Configuration file of SwitchA
# sysname SwitchA # vlan batch 10 30 # interface Vlanif10 ip address 10.1.4.1 255.255.255.252 # interface Vlanif30 ip address 10.1.1.1 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 10 # interface 10GE1/0/2 port default vlan 30 # ip route-static 0.0.0.0 0.0.0.0 10.1.4.2 # return
Configuration file of SwitchB
# sysname SwitchB # vlan batch 10 20 40 # interface Vlanif10 ip address 10.1.4.2 255.255.255.252 # interface Vlanif20 ip address 10.1.4.5 255.255.255.252 # interface Vlanif40 ip address 10.1.2.1 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 10 # interface 10GE1/0/2 port link-type trunk port trunk allow-pass vlan 20 # interface 10GE1/0/3 port default vlan 40 # ip route-static 10.1.1.0 255.255.255.0 10.1.4.1 ip route-static 10.1.3.0 255.255.255.0 10.1.4.6 # return
Configuration file of SwitchC
# sysname SwitchC # vlan batch 20 50 # interface Vlanif20 ip address 10.1.4.6 255.255.255.252 # interface Vlanif50 ip address 10.1.3.1 255.255.255.0 # interface 10GE1/0/1 port link-type trunk port trunk allow-pass vlan 20 # interface 10GE1/0/2 port default vlan 50 # ip route-static 0.0.0.0 0.0.0.0 10.1.4.5 # return