三层交换机路由配置⽬的:
1.⽤三层交换机配置静态路由实现不同vlan间通信
2.rip动态路由配置
3.ospf动态路由配置
4.默认路由配置
拓扑图:
步骤:
1.配置静态路由
⼀:给两台pc设置IP、掩码和⽹关
pc0:192.168.1.2 255.255.255.0
pc1:192.168.2.2 255.255.255.0
⼆:给两台三层交换机划分vlan、注意:两台交换机连线处vlan可以不同。
s0:
enable
configure terminal
vlan 2
exit
vlan 3
exit
interface fa0/1
switchport access vlan 2 —–主机划分到vlan2
interface fa0/2
switchport access vlan 3
interface vlan 2
ip address 192.168.1.1 255.255.255.0
interface vlan 3
ip address 192.168.3.1 255.255.255.0
vlan 4
exit
vlan 3
exit
interface fa0/1
switchport access vlan 3
interface fa0/2
switchport access vlan 4 ——-主机划分到vlan4
interface vlan 3
ip address 192.168.3.2 255.255.255.0
interface vlan 4
ip address 192.168.2.1 255.255.255.0
三、配置静态路由和开启路由功能。配置静态路由命令为ip route ⽬的IP⽹络号 掩码 下⼀跳地址
s0:
enable
configure terminal
ip route 192.168.2.0 255.255.255.0 192.168.3.2 ——配置静态路由,⽬的地址是⽹段,还可以是具体某⼀IP,但是掩码必须为255.255.255.255,表⽰标志唯⼀的IP。
ip routing
s1:
enable
configure terminal
ip route 192.168.1.0 255.255.255.0 192.168.3.1 ——配置静态路由,⽬的地址是⽹段
ip routing
交换机 路由器
2.rip动态路由配置:删除静态路由⾥配置的静态路由,其它不变,然后配置rip
步骤:
s0:
enable
configure terminal
no ip route 192.168.2.2 255.255.255.0 192.168.3.2
router rip
network 192.168.1.0 ——宣告直连⽹络
network 192.168.3.0
s1:
enable
configure terminal
no ip route 192.168.1.2 255.255.255.0 192.168.3.1
router rip
network 192.168.2.0 ——宣告直连⽹络
network 192.168.3.0
3.ospf动态路由配置:删除静态路由⾥配置的静态路由,其它不变,然后配置rip
no ip route 192.168.2.2 255.255.255.0 192.168.3.2
router ospf 1 —–1是进程号
network 192.168.1.0 0.0.0.255 area 0 ——宣告直连⽹络,掩码为反掩码
network 192.168.3.0 0.0.0.255 area 0
s1:
enable
configure terminal
no ip route 192.168.1.2 255.255.255.0 192.168.3.1
router rip
network 192.168.2.0 0.0.0.255 area 0 ——宣告直连⽹络
network 192.168.3.0 0.0.0.255 area 0
4.默认路由配置:删除静态路由⾥配置的静态路由,其它不变,然后配置默认路由
s0:
enable
configure terminal
no ip route 192.168.2.2 255.255.255.0 192.168.3.2
ip route 0.0.0.0 0.0.0.0 192.168.3.2
s1:
enable
configure terminal
no ip route 192.168.1.2 255.255.255.0 192.168.3.1
ip route 0.0.0.0 0.0.0.0 192.168.3.1
注:
1.删除vlan⾥的IP要⽤no ip address,⽤no ip address 具体IP 掩码 是⽆效的
2.路由器是基于端⼝的,三层交换机是基于vlan的。建议做是实验对⽐。