Router#en Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#int g0/0 Router(config-if)#ip address 192.168.1.1255.255.255.0 Router(config-if)#no sh // 将端口设为启用
Router(config-if)#
同时配置 g0/1 的端口
1 2 3 4 5 6 7 8
Router(config-if)#int g0/1 Router(config-if)#ip address 192.168.2.1255.255.255.0 Router(config-if)#no sh
Router(config-if)# %LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
此处 g0/1 配置完成后就直接连通了,这是因为PC的接口不需要手动启用,而另一个路由器还未配置完毕,接口需要在配置面板或者输入 no sh 来启用,要禁用的时候可以输入 shutdown
Ping statistics for192.168.2.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\>
根据操作给R2的g0/0配置192.168.1.2地址,给g0/1配置192.168.3.1地址
配置静态路由
在R1上,设置静态路由,让PC0可以访问到PC1
1 2 3 4
Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#ip route 192.168.3.0255.255.255.0192.168.1.2 // 目的网络 子网掩码 下一跳
Router(config)#do show run Building configuration...
Current configuration : 687 bytes ! version 15.1 no service timestamps log datetime msec no service timestamps debug datetime msec no service password-encryption ! hostname Router ! ! ! ! ! ! ! ! no ip cef no ipv6 cef ! ! ! ! license udi pid CISCO1941/K9 sn FTX152485P5- ! ! ! ! ! ! ! ! ! ! ! spanning-tree mode pvst ! ! ! ! ! ! interface GigabitEthernet0/0 ip address 192.168.1.1255.255.255.0 duplex auto speed auto ! interface GigabitEthernet0/1 ip address 192.168.2.1255.255.255.0 duplex auto speed auto ! interface Vlan1 no ip address shutdown ! ip classless ip route 192.168.3.0255.255.255.0192.168.1.2 ! ip flow-export version 9 ! ! ! ! ! ! ! ! line con 0 ! line aux 0 ! line vty 04 login ! ! ! end
Ping statistics for192.168.3.2: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 27ms, Average = 9ms
C:\>
动态路由
路由配置
给R1进行配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Router>en Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#int g0/0 Router(config-if)#ip address 192.168.1.1255.255.255.0 Router(config-if)#no sh
Router(config-if)# %LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up
Router(config-if)# Router(config-if)#int g0/1 Router(config-if)#ip address 192.168.2.1255.255.255.0 Router(config-if)#no sh
Router(config-if)# %LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
Router>en Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#int g0/0 Router(config-if)#ip addr 192.168.1.2255.255.255.0 Router(config-if)#no sh
Router(config-if)# %LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up
Router(config-if)#int g0/1 Router(config-if)#ip addr 192.168.3.1255.255.255.0 Router(config-if)#no sh
Router(config-if)# %LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
并给两个PC配置 192.168.2.2 与 192.168.3.2
路由协议
在两台路由器上启用ospf协议并公布自己的直连网段
在R1上配置
1 2 3 4 5 6
Router#conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)#route ospf 1 Router(config-router)#network 192.168.1.00.0.0.255 area 0 Router(config-router)#network 192.168.2.00.0.0.255 area 1 Router(config-router)#
在R2上配置
1 2 3 4 5
Router(config)#route ospf 1 Router(config-router)#network 192.168.1.0255.255.255.0 area 0 Router(config-router)#network 192.168.3.0255.255.255.0 area 0 00:11:30: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.2.1 on GigabitEthernet0/0from LOADING to FULL, Loading Done2 Router(config-router)#
Router(config-router)#do show run Building configuration...
Current configuration : 751 bytes ! version 15.1 no service timestamps log datetime msec no service timestamps debug datetime msec no service password-encryption ! hostname Router ! ! ! ! ! ! ! ! ip cef no ipv6 cef ! ! ! ! license udi pid CISCO1941/K9 sn FTX15246BJO- ! ! ! ! ! ! ! ! ! ! ! spanning-tree mode pvst ! ! ! ! ! ! interface GigabitEthernet0/0 ip address 192.168.1.2255.255.255.0 duplex auto speed auto ! interface GigabitEthernet0/1 ip address 192.168.3.1255.255.255.0 duplex auto speed auto ! interface Vlan1 no ip address shutdown ! router ospf 1 log-adjacency-changes network 192.168.1.00.0.0.255 area 0 network 192.168.3.00.0.0.255 area 2 ! ip classless ! ip flow-export version 9 ! ! ! ! ! ! ! ! line con 0 ! line aux 0 ! line vty 04 login ! ! ! end
Ping statistics for192.168.3.2: Packets: Sent = 4, Received = 3, Lost = 1 (25% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
C:\>
在R1上查看邻居
1 2 3 4 5
Router#show ip ospf ne
Neighbor ID Pri State Dead Time Address Interface 192.168.3.11 FULL/BDR 00:00:35192.168.1.2 GigabitEthernet0/0 Router#