拓扑图如图所示:
1.先给pc设置IP地址和网关以及子网掩码:
2.给三层交换机配置vlan、划分vlan以及给接口配置vlanif地址:
sy
sys SW1 #更改名字
vlan batch 10 100 #创建vlan
int g0/0/24
port linl-type access
port default vlan 100
int g0/0/1
port link-type access
port default vlan 10
quit
int vlanif10
ip add 192.168.10.254 24
int vlanif100
ip add 192.168.1.2 24 #接口划分vlan
sy
sys SW2 #更改名字
vlan batch 10 100 #创建vlan
int g0/0/24
port linl-type access
port default vlan 100
int g0/0/1
port link-type access
port default vlan 10
quit
int vlanif10
ip add 172.16.10.254 24
int vlanif100
ip add 172.16.1.2 24 #接口划分vlan
3.路由器接口划分IP地址
sy
sysname R1
int g0/0/0
ip add 192.168.1.1 24
int g0/0/1
ip add 172.16.1.1 24
4.使用display ip int brief 检查接口是否配置正确
5.配置动态路由:
SW1:
ospf 1 router-id 1.1.1.1
area 0
network 192.168.1.0 0.0.0.255
network 192.168.10.0 0.0.0.255 #写直连网段
R1:
ospf 1 router-id 2.2.2.2
area 0
network 192.168.1.0 0.0.0.255
network 172.16.1.0 0.0.0.255
SW2:
ospf 1 router-id 3.3.3.3
area 0
network 172.16.1.0 0.0.0.255
network 172.16.10.0 0.0.0.255
6.使用display ospf peer brief 检查邻居关系是否建立成功,SW1有一个邻居,R1有两个邻居,SW2有一个邻居【状态为Full即为邻居关系建立成功】
7.进行ping通测试:
如上图所示,即代表pc1可以ping通pc2
另:
设置动态路由的那个地方,也可以换成设置静态路由,例如R1的静态路由:
ip route-static 192.168.10.0 24 192.168.1.2
ip route-static 172.16.10.0 24 172.16.1.2
其他两台设备类似
最后进行ping测试,也能得出pc1能ping通pc2