Cisco简单配置(七)—组建一个简单局域网

本文档详述了如何搭建一个包含RIP协议、VLAN划分、单臂路由及DHCP服务的简单局域网。通过配置交换机S1、S2、S3、S4以及路由器R1、R2、R3的IP地址和接口,实现了不同VLAN间的通信。同时,通过R1的单臂路由配置,解决了VLAN间互通问题,并通过DHCP服务为PC分配IP地址。
摘要由CSDN通过智能技术生成

本次配置,我们来搭建一个简单的局域网。

涉及RIP协议,划分VLAN、单臂路由、DHCP服务

步骤的分步在之前的博客也有详细配置。

搭建拓扑图

VLAN划分
VLAN1PC1PC4
VLAN2PC2PC5
VLAN3PC3PC6
IP编址
R1G0/010.10.2.1255.255.255.0
G0/110.10.1.2255.255.255.0
R2G0/010.10.2.2255.255.255.0
G0/110.10.3.1255.255.255.0
R3G0/010.10.3.2255.255.255.0
G0/110.10.4.2255.255.255.0
S1VLAN 110.10.1.3255.255.255.0
gateway10.10.1.2
S2VLAN 110.10.4.3255.255.255.0
gateway10.10.4.2

配置交换机S3、S4:划分VLAN

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

配置S1、S2:端口放行VLAN、默认网关

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

配置R1、R2、R3:接口IP、RIP协议

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的必要

 

 R1上配置单臂路由:VLAN之间可以互通

配置之前,我们首先预设地址到各个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添加网关,此时的网关就是单臂路由对应的网段

PC110.10.10.1
PC210.10.20.1
PC310.10.30.1
PC410.10.10.1
PC510.10.20.1
PC610.10.30.1

连通性测试 

PC1 ping PC4

 PC1 ping PC2

 OK,已经完成了单臂路由的配置,接下我们最后配置DHCP服务

配置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

PC获取IP

 OK,一次获取IP即可

 这就是小型局域网的配置了。当然还可以加入其他的动态协议进去,或者介入防火墙等设置,我们之后在来配置

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值