本次配置,我们来搭建一个简单的局域网。
涉及RIP协议,划分VLAN、单臂路由、DHCP服务
步骤的分步在之前的博客也有详细配置。
VLAN1 | PC1 | PC4 |
VLAN2 | PC2 | PC5 |
VLAN3 | PC3 | PC6 |
R1 | G0/0 | 10.10.2.1 | 255.255.255.0 |
G0/1 | 10.10.1.2 | 255.255.255.0 | |
R2 | G0/0 | 10.10.2.2 | 255.255.255.0 |
G0/1 | 10.10.3.1 | 255.255.255.0 | |
R3 | G0/0 | 10.10.3.2 | 255.255.255.0 |
G0/1 | 10.10.4.2 | 255.255.255.0 | |
S1 | VLAN 1 | 10.10.1.3 | 255.255.255.0 |
gateway | 10.10.1.2 | ||
S2 | VLAN 1 | 10.10.4.3 | 255.255.255.0 |
gateway | 10.10.4.2 |
Switch>enable
Switch(config)#hostname S3
S3(config)#vlan 10
S3(config-vlan)#vlan 20
S3(config-vlan)#vlan 30
S3(config-vlan)#exit
S3(config)#interface fastEthernet 0/1
S3(config-if)#switchport mode access
S3(config-if)#switchport access vlan 10
S3(config-if)#exit
S3(config)#interface fastEthernet 0/2
S3(config-if)#switchport mode access
S3(config-if)#switchport access vlan 20
S3(config-if)#exit
S3(config)#interface fastEthernet 0/3
S3(config-if)#switchport mode access
S3(config-if)#switchport access vlan 30
S3(config-if)#exit
S3(config)#interface fastEthernet 0/4
S3(config-if)#switchport mode trunk
S3(config-if)#switchport trunk allowed vlan all
Switch>enable
Switch#configure
Switch(config)#hostname S4
S4(config)#vlan 10
S4(config-vlan)#vlan 20
S4(config-vlan)#vlan 30
S4(config-vlan)#exit
S4(config)#interface fastEthernet 0/1
S4(config-if)#switchport mode access
S4(config-if)#switchport access vlan 10
S4(config-if)#exit
S4(config)#interface fastEthernet 0/2
S4(config-if)#switchport mode access
S4(config-if)#switchport access vlan 20
S4(config-if)#exit
S4(config)#interface fastEthernet 0/3
S4(config-if)#switchport mode access
S4(config-if)#switchport access vlan 30
S4(config-if)#exit
S4(config)#interface fastEthernet 0/4
S4(config-if)#switchport mode trunk
S4(config-if)#switchport trunk allowed vlan all
Switch#enable
Switch#configure
S1#Hostname S1
S1(config)#vlan 10
S1(config-vlan)#vlan 20
S1(config-vlan)#vlan 30
S1(config-vlan)#exit
S1(config)#interface vlan 1
S1(config-if)#ip address 10.10.1.3 255.255.255.0
S1(config-if)#no shutdown
S1(config-if)#exit
S1(config)#interface fastEthernet 0/1
S1(config-if)#switchport mode trunk
S1(config-if)#switchport trunk allowed vlan all
S1(config-if)#exit
S1(config)#ip default-gateway 10.10.1.2
S1(config)#interface gigabitEthernet 0/1
S1(config-if)#switchport mode trunk
S1(config-if)#no shutdown
Switch>enable
Switch#configure
Switch(config)#hostname S2
S2(config)#interface vlan 1
S2(config-if)#ip address 10.10.4.3 255.255.255.0
S2(config-if)#no shutdown
S2(config-if)#exit
S2(config)#interface gigabitEthernet 0/1
S2(config-if)#no shutdown
S2(config-if)#exit
S2(config)#ip default-gateway 10.10.4.2
Router>enable
Router#configure
Router(config)#hostname R1
R1(config)#interface gigabitEthernet 0/1
R1(config-if)#ip address 10.10.1.2 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface gigabitEthernet 0/0
R1(config-if)#ip address 10.10.2.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#network 10.10.1.0
R1(config-router)#network 10.10.2.0
R1(config-router)#no auto-summary
R1(config-router)#passive-interface g0/1
Router>enable
Router#configure
Router(config)#hostname R2
R2(config)#interface g0/0
R2(config-if)#ip address 10.10.2.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface g0/1
R2(config-if)#ip address 10.10.3.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#router rip
R2(config-router)#version 2
R2(config-router)#network 10.10.2.0
R2(config-router)#network 10.10.3.0
R2(config-router)#no auto-summary
R2(config-router)#exit
Router>enable
Router#configure
Router(config)#hostname R3
R3(config)#interface g0/0
R3(config-if)#ip address 10.10.4.2 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#interface g0/1
R3(config-if)#ip address 10.10.3.2 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#router rip
R3(config-router)#version 2
R3(config-router)#network 10.10.3.0
R3(config-router)#network 10.10.4.0
R3(config-router)#no auto-summary
R3(config-router)#exit
S1、S2、R1、R2、R3任意两个都是通的,而S3和S4不会任何设备通:两者之间并没有配置接口信息,若要通,可配置相应的IP到VLAN1上,或者单独划个VLAN配置IP,目前来说,S3和S4并没有必要配置接口IP的必要
配置之前,我们首先预设地址到各个PC,来验证我们连通性
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#network 10.10.10.0
R1(config-router)#network 10.10.20.0
R1(config-router)#network 10.10.30.0
R1(config-router)#no auto-summary
R1(config-router)#exit
R1(config)#interface gigabitEthernet 0/1
R1(config-if)#no ip address
R1(config-if)#exit
R1(config)#interface g0/1.10
R1(config-subif)#encapsulation dot1Q 10
R1(config-subif)#ip address 10.10.10.1 255.255.255.0
R1(config-subif)#exit
R1(config)#interface gigabitEthernet 0/1.20
R1(config-subif)#encapsulation dot1Q 20
R1(config-subif)#ip address 10.10.20.1 255.255.255.0
R1(config-subif)#exit
R1(config)#interface gigabitEthernet 0/1.30
R1(config-subif)#encapsulation dot1Q 30
R1(config-subif)#exit
此时,我们去ping VLAN之间的任意两台主机,发现 还是不通。这是什么原因?我们配置完后最容易忽略掉一个细节,配完单臂路由后,VLAN之间就已经进入里逻辑接口,而路由器的一个接口就是一个网段,要跨越网段发送数据,就需要网关,所以,我们要为同一VLAN下的PC添加网关,此时的网关就是单臂路由对应的网段
PC1 | 10.10.10.1 |
PC2 | 10.10.20.1 |
PC3 | 10.10.30.1 |
PC4 | 10.10.10.1 |
PC5 | 10.10.20.1 |
PC6 | 10.10.30.1 |
PC1 ping PC4
PC1 ping PC2
OK,已经完成了单臂路由的配置,接下我们最后配置DHCP服务
R1(config)#ip dhcp pool 1
R1(dhcp-config)#network 10.10.10.0 255.255.255.0
R1(dhcp-config)#default-router 10.10.10.1
R1(dhcp-config)#exit
R1(config)#ip dhcp pool 2
R1(dhcp-config)#net
R1(dhcp-config)#network 10.10.20.0 255.255.255.0
R1(dhcp-config)#default-router 10.10.20.1
R1(dhcp-config)#exit
R1(config)#ip dhcp pool 3
R1(dhcp-config)#network 10.10.30.0 255.255.255.0
R1(dhcp-config)#default-router 10.10.30.1
R1(dhcp-config)#exit
R1(config)#ip dhcp excluded-address 10.10.10.1 10.10.10.5
R1(config)#ip dhcp excluded-address 10.10.20.1 10.10.20.5
R1(config)#ip dhcp excluded-address 10.10.30.1 10.10.30.5
OK,一次获取IP即可
这就是小型局域网的配置了。当然还可以加入其他的动态协议进去,或者介入防火墙等设置,我们之后在来配置