Example for Configuring IPv4 Static Routes
You can configure IPv4 static routes to interconnect any two devices on an IPv4 network.
Networking Requirements
Figure 3-3 shows the IP addresses and masks of interfaces and hosts. It is required that any two hosts in Figure 3-3 communicate through static routes.
Precautions
When configuring an IPv4 static route, specify a next-hop address if the outbound interface is of the broadcast type.
Configuration Roadmap
The configuration roadmap is as follows:
Configure IPv4 addresses for interfaces on each router.
Configure an IPv4 static route and a default route on each router.
Configure the IPv4 default gateway on each host so that any two hosts communicate with each other.
Data Preparation
To complete the configuration, you need the following data:
Default route with 1.1.4.2 as the next hop on Device A
Static route to 1.1.1.0 with 1.1.4.1 as the next hop on Device B
Static route to 1.1.3.0 with 1.1.4.6 as the next hop on Device B
Default route with 1.1.4.5 as the next hop on Device C
Default gateways of PC1, PC2, and PC3
Procedure
- Configure an IP address for each interface. For configuration details, see Configuration Files in this section.
- Configure static routes.
# Configure an IPv4 default route on Device A.
[~DeviceA] ip route-static 0.0.0.0 0.0.0.0 1.1.4.2 [*DeviceA] commit
# Configure two IPv4 static routes on Device B.
[~DeviceB] ip route-static 1.1.1.0 255.255.255.0 1.1.4.1 [*DeviceB] ip route-static 1.1.3.0 255.255.255.0 1.1.4.6 [*DeviceB] commit
# Configure an IPv4 default route on Device C.
[~DeviceC] ip route-static 0.0.0.0 0.0.0.0 1.1.4.5 [*DeviceC] commit
- Configure a default gateway for each host.
Configure the default gateways of PC1, PC2, and PC3 as 1.1.1.1, 1.1.2.1, and 1.1.3.1 respectively.
- Verify the configuration.
# Check the IP routing table of Device A.
[~DeviceA] display ip routing-table Route Flags: R - relay, D - download to fib, T - to vpn-instance, B - black hole route ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 12 Routes : 12 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 Static 60 0 RD 1.1.4.2 GigabitEthernet1/0/0 1.1.1.0/24 Direct 0 0 D 1.1.1.1 GigabitEthernet2/0/0 1.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet2/0/0 1.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet2/0/0 1.1.4.0/30 Direct 0 0 D 1.1.4.1 GigabitEthernet1/0/0 1.1.4.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet1/0/0 1.1.4.2/32 Direct 0 0 D 1.1.4.2 GigabitEthernet1/0/0 1.1.4.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet1/0/0 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.
[~DeviceA] ping 1.1.3.1 PING 1.1.3.1: 56 data bytes, press CTRL_C to break Reply from 1.1.3.1: bytes=56 Sequence=1 ttl=254 time=62 ms Reply from 1.1.3.1: bytes=56 Sequence=2 ttl=254 time=63 ms Reply from 1.1.3.1: bytes=56 Sequence=3 ttl=254 time=63 ms Reply from 1.1.3.1: bytes=56 Sequence=4 ttl=254 time=62 ms Reply from 1.1.3.1: bytes=56 Sequence=5 ttl=254 time=62 ms --- 1.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
# Run the tracert command to verify the connectivity.
[~DeviceA] tracert 1.1.3.1 traceroute to 1.1.3.1(1.1.3.1), max hops: 30 ,packet length: 40 1 1.1.4.2 31 ms 32 ms 31 ms 2 1.1.4.6 62 ms 63 ms 62 ms
Configuration Files
Device A configuration file
# sysname DeviceA # interface GigabitEthernet1/0/0 undo shutdown ip address 1.1.4.1 255.255.255.252 # interface GigabitEthernet2/0/0 undo shutdown ip address 1.1.1.1 255.255.255.0 # ip route-static 0.0.0.0 0.0.0.0 1.1.4.2 # return
Device B configuration file
# sysname DeviceB # interface GigabitEthernet1/0/0 undo shutdown ip address 1.1.4.2 255.255.255.252 # interface GigabitEthernet2/0/0 undo shutdown ip address 1.1.4.5 255.255.255.252 # interface GigabitEthernet3/0/0 undo shutdown ip address 1.1.2.1 255.255.255.0 # ip route-static 1.1.1.0 255.255.255.0 1.1.4.1 ip route-static 1.1.3.0 255.255.255.0 1.1.4.6 # return
Device C configuration file
# sysname DeviceC # interface GigabitEthernet1/0/0 undo shutdown ip address 1.1.4.6 255.255.255.252 # interface GigabitEthernet2/0/0 undo shutdown ip address 1.1.3.1 255.255.255.0 # ip route-static 0.0.0.0 0.0.0.0 1.1.4.5 # return