一、组网需求
通过配置静态路由实现全网路由可达。
二、组网图
三、配置要点
●在设备各接口上配置地址。
●在设备上配置静态路由。
四、配置步骤
(1) 配置各接口的IP地址。
# Device A的配置。
Device A> enable
Device A# configure terminal
Device A(config)# interface gigabitethernet 0/0
Device A(config-if-GigabitEthernet 0/0)# ip address 1.1.1.1 255.255.255.0
Device A(config-if-GigabitEthernet 0/0)# exit
Device A(config)# interface gigabitethernet 0/2
Device A(config-if-GigabitEthernet 0/2)# ip address 1.1.12.1 255.255.255.0
Device A(config-if-GigabitEthernet 0/2)# exit
Device A(config)# interface gigabitethernet 0/3
Device A(config-if-GigabitEthernet 0/3)# ip address 1.1.13.1 255.255.255.0
Device A(config-if-GigabitEthernet 0/3)# exit
# Device B的配置。
Device B> enable
Device B# configure terminal
Device B(config)# interface gigabitethernet 0/0
Device B(config-if-GigabitEthernet 0/0)# ip address 1.1.2.1 255.255.255.0
Device B(config-if-GigabitEthernet 0/0)# exit
Device B(config)# interface gigabitethernet 0/1
Device B(config-if-GigabitEthernet 0/1)# ip address 1.1.12.2 255.255.255.0
Device B(config-if-GigabitEthernet 0/1)# exit
Device B(config)# interface gigabitethernet 0/3
Device B(config-if-GigabitEthernet 0/3)# ip address 1.1.23.2 255.255.255.0
Device B(config-if-GigabitEthernet 0/3)# exit
# Device C的配置。
Device C> enable
Device C# configure terminal
Device C(config)# interface gigabitethernet 0/0
Device C(config-if-GigabitEthernet 0/0)# ip address 1.1.3.1 255.255.255.0
Device C(config-if-GigabitEthernet 0/0)# exit
Device C(config)# interface gigabitethernet 0/1
Device C(config-if-GigabitEthernet 0/1)# ip address 1.1.13.3 255.255.255.0
Device C(config-if-GigabitEthernet 0/1)# exit
Device C(config)# interface gigabitethernet 0/2
Device C(config-if-GigabitEthernet 0/2)# ip address 1.1.23.3 255.255.255.0
Device C(config-if-GigabitEthernet 0/2)# exit
(2) 启动IPv4静态路由功能。
# Device A的配置。
Device A(config)# ip route 1.1.2.0 255.255.255.0 gigabitethernet 0/2 1.1.12.2
Device A(config)# ip route 1.1.3.0 255.255.255.0 gigabitethernet 0/3 1.1.13.3
# Device B的配置。
Device B(config)# ip route 1.1.1.0 255.255.255.0 gigabitethernet 0/1 1.1.12.1
Device B(config)# ip route 1.1.3.0 255.255.255.0 gigabitethernet 0/3 1.1.23.3
# Device C的配置。
Device C(config)# ip route 1.1.2.0 255.255.255.0 gigabitethernet 0/2 1.1.23.2
Device C(config)# ip route 1.1.1.0 255.255.255.0 gigabitethernet 0/1 1.1.13.1
五、验证配置结果
检查设备的路由表,确认有静态路由条目。
# Device A的路由表。
Device A# show ip route
Codes: C – Connected, L – Local, S – Static
R – RIP, O – OSPF, B – BGP, I – IS-IS
N1 – OSPF NSSA external type 1, N2 – OSPF NSSA external type 2
E1 – OSPF external type 1, E2 – OSPF external type 2
SU – IS-IS summary, L1 – IS-IS level-1, L2 – IS-IS level-2
IA – Inter area, * – candidate default
Gateway of last resort is no set
C 1.1.1.0/24 is directly connected, GigabitEthernet 0/0
C 1.1.1.1/32 is local host.
S 1.1.2.0/24 [1/0] via 1.1.12.2, GigabitEthernet 0/2
S 1.1.3.0/24 [1/0] via 1.1.13.3, GigabitEthernet 0/2
C 1.1.12.0/24 is directly connected, GigabitEthernet 0/2
C 1.1.12.1/32 is local host.
C 1.1.13.0/24 is directly connected, GigabitEthernet 0/3
C 1.1.13.1/32 is local host.
# Device B的路由表。
Device B# show ip route
Codes: C – Connected, L – Local, S – Static
R – RIP, O – OSPF, B – BGP, I – IS-IS
N1 – OSPF NSSA external type 1, N2 – OSPF NSSA external type 2
E1 – OSPF external type 1, E2 – OSPF external type 2
SU – IS-IS summary, L1 – IS-IS level-1, L2 – IS-IS level-2
IA – Inter area, * – candidate default
Gateway of last resort is no set
S 1.1.1.0/24 [1/0] via 1.1.12.1, GigabitEthernet 0/0
C 1.1.2.0/24 is directly connected, GigabitEthernet 0/0
C 1.1.2.1/32 is local host.
S 1.1.3.0/24 [1/0] via 1.1.23.3, GigabitEthernet 0/3
C 1.1.12.0/24 is directly connected, GigabitEthernet 0/1
C 1.1.12.2/32 is local host.
C 1.1.23.0/24 is directly connected, GigabitEthernet 0/3
C 1.1.23.2/32 is local host.
# Device C的路由表。
Device C# show ip route
Codes: C – Connected, L – Local, S – Static
R – RIP, O – OSPF, B – BGP, I – IS-IS
N1 – OSPF NSSA external type 1, N2 – OSPF NSSA external type 2
E1 – OSPF external type 1, E2 – OSPF external type 2
SU – IS-IS summary, L1 – IS-IS level-1, L2 – IS-IS level-2
IA – Inter area, * – candidate default
Gateway of last resort is no set
S 1.1.1.0/24 [1/0] via 1.1.13.1, GigabitEthernet 0/2
S 1.1.2.0/24 [1/0] via 1.1.23.2, GigabitEthernet 0/2
C 1.1.3.0/24 is directly connected, GigabitEthernet 0/0
C 1.1.3.1/32 is local host.
C 1.1.13.0/24 is directly connected, GigabitEthernet 0/1
C 1.1.13.3/32 is local host.
C 1.1.23.0/24 is directly connected, GigabitEthernet 0/2
C 1.1.23.3/32 is local host.
六、 配置文件
● Device A的配置文件。
!
interface gigabitethernet 0/0
ip address 1.1.1.1 255.255.255.
!
interface gigabitethernet 0/2
ip address 1.1.12.1 255.255.255.0
!
interface gigabitethernet 0/3
ip address 1.1.13.1 255.255.255.0
!
ip route 1.1.2.0 255.255.255.0 GigabitEthernet 0/2 1.1.12.2
ip route 1.1.3.0 255.255.255.0 GigabitEthernet 0/3 1.1.13.3
!
● Device B的配置文件。
!
interface gigabitethernet 0/0
ip address 1.1.2.1 255.255.255.0
!
interface gigabitethernet 0/1
ip address 1.1.12.2 255.255.255.0
!
interface gigabitethernet 0/3
ip address 1.1.23.2 255.255.255.0
!
ip route 1.1.1.0 255.255.255.0 GigabitEthernet 0/1 1.1.12.1
ip route 1.1.3.0 255.255.255.0 GigabitEthernet 0/3 1.1.23.3
!
● Device C的配置文件。
!
interface gigabitethernet 0/0
ip address 1.1.3.1 255.255.255.0
!
interface gigabitethernet 0/1
ip address 1.1.13.3 255.255.255.0
!
interface gigabitethernet 0/2
ip address 1.1.23.3 255.255.255.0
!
ip route 1.1.2.0 255.255.255.0 GigabitEthernet 0/2 1.1.23.2
ip route 1.1.1.0 255.255.255.0 GigabitEthernet 0/1 1.1.13.1
!
七、 常见错误
● 接口链路没有Up。
●接口没有配置地址。