Switch(config-if)#
Vlan设置范围:1---4094
在全局模式下配置vlan
Switch#conft
Switch(config)#vlan10
Switch(config-vlan)#namevlan10
Switch(config-vlan)#vlan20
Switch(config-vlan)#namevlan20
Vlan名称可以自行定义
Switch#showvlan 查看vlan配置信息
vlan10配置192.168.10.1/24的ip地址
Switch#conft
Switch(config)#vlan10
Switch(config-vlan)#namevlan10
Switch(config-vlan)#exit
Switch(config)#interfacevlan 10
Switch(config-if)#ipaddress 192.168.10.1 255.255.255.0
Switch(config-if)#end
Switch#copyrunning-config startup-config
配置ip地址的命令格式: ipaddress {ip-address} {netmask}
测试常用端口类型 Access/ trunk
将此端口设置为vlan10的access口
Switch(config-if)#switchportmode access
Switch(config-if)#switchportaccess vlan 10
Switch(config-if)#
将此端口设置为vlan10的trunk口
Switch(config-if)#switchporttrunk encapsulation dot1q
Switch(config-if)#switchportmode trunk
Switch(config-if)#switchporttrunk allowed vlan 10
当一个端口允许多个vlan通过时,trunk allowed vlan中要添加各条vlan信息
Switch(config-if)#switchporttrunk encapsulation dot1q
Switch(config-if)#switchportmode trunk
Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#switchporttrunk allowed vlan 10,50,60
Switch(config-if)#switchporttrunk allowed vlan add 20 (remove删除)
Switch(config-if)#switchporttrunk allowed vlan add 30
Switch(config-if)#switchporttrunk allowed vlan add 40
Switch(config-if)#switchporttrunk native vlan 1
Switch(config-if)#noshutdown
Switch(config-if)#end
Switch#copyrunning-config startup-config
此端口为vlan10 vlan20 vlan30 vlan40的trunk口,defaultvlan 1经过此端口时不会带上标签。
当一个端口允许多个vlan通过时,trunk allowed vlan中要添加各条vlan信息
Switch(config-if)#switchporttrunk encapsulation dot1q
Switch(config-if)#switchportmode trunk
Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#switchporttrunk allowed vlan 10,50,60
Switch(config-if)#switchporttrunk allowed vlan add 20 (remove删除)
Switch(config-if)#switchporttrunk allowed vlan add 30
Switch(config-if)#switchporttrunk allowed vlan add 40
Switch(config-if)#switchporttrunk native vlan 1
Switch(config-if)#noshutdown
Switch(config-if)#end
Switch#copyrunning-config startup-config
此端口为vlan10 vlan20 vlan30 vlan40的trunk口,defaultvlan 1经过此端口时不会带上标签。
光端口配置
Switch(config)#interfacegigabitEthernet 0/25
Switch(config-if)#switchport mode access
Switch(config-if)#switchportaccess vlan 10
Switch(config-if)#noshutdown
Switch(config-if)#end
Switch#copyrunning-config startup-config
注意:
由于思科的交换机只自动识别自己品牌的光模块,所以如果用其他品牌的光模块,需在配置模式下输入一下两条命令,开启兼容性。
serviceunsupported-transceiver
noerrdisable detect cause gbic-invalid
命令输入完成后保存设置重启设备 。
配置一个dhcp给vlan10内的主机分配地址
Switch(config)#servicedhcp
Switch(config)#ipdhcp pool vlan10
Switch(dhcp-config)#network192.168.10.0 255.255.255.0
Switch(dhcp-config)#default-router192.168.10.1
Switch(dhcp-config)#dns-server192.168.10.2
Switch(dhcp-config)#lease3 20 20 (天/小时/分钟)(缺省为1天)
Switch(dhcp-config)#exit
Switch(config)#ip dhcp excluded-address 192.168.10.1192.168.10.19
Switch(config)#
ipdhcp excluded-address 排除某些地址,禁止被动态分配
DHCP设置是针对全局的,不是定义在某个接口上的。
DHCP调试命令
Switch(config)#noservice dhcp 关闭dhcp服务
Switch#showip dhcp binding 查看dhcp分配情况
思科作DHCP server给AP分地址
在server中设置Option43、Option60字段信息。
Switch(config)#ipdhcp pool vlan20
Switch(dhcp-config)#network192.168.1.0 255.255.255.0
Switch(dhcp-config)#default-router192.168.1.1
Switch(dhcp-config)#option43 hex 0106 0104 c0a8 01e4
Switch(dhcp-config)#option60 hex xxxx xxxx xxxx (AC回的offer包中的信息)
Switch(dhcp-config)#lease 1
Switch(dhcp-config)#end
Switch#copyrunning-config startup-config
DHCPrelay功能可以汇聚处于不同广播域的客户端的DHCP请求,转发给DHCP服务器,并发送DHCP服务器的响应给各个客户端,也就是起到了DHCP报文在各个网段的转发功能。Cisco的设备需要启用ip helper-address命令,来实现此功能。•配置了ip helper-address命令之后的交换机在中继DHCP请求时的工作过程如下:
(1)DHCP客户端发送请求,由于没有IP地址,所以自己的源IP地址为0.0.0.0,而且也不知道目的DHCP服务器的地址,所以广播255.255.255.255。该数据报文中还包括源mac地址和目的mac地址(全F)。
(2)当交换机接收到该数据包的时候,它就用自己的接口地址来取代源地址0.0.0.0,并且用ip helper-address命令置顶的地址来取代目的地址255.255.255.255。
(3)当DHCP服务器接收到交换机转发过来的DHCP请求包时,它会做出响应,并且由交换机把数据包转发回客户端。
DHCPrelay 配置
Switch(config)#vlan100
Switch(config-vlan)#namevlan100
Switch(config-vlan)#intvlan 100
Switch(config-if)#ip helper-address 192.168.1.228
Switch(config-if)#exit
Switch(config)#servicedhcp
Switch(config)#ipdhcp relay information trust-all
Switch(config)#end
Switch#copyrunning-config startup-config
DHCPrelay功能测试实例:
AClan端口开启dhcpserver
dhcpserver1:192.168.20.10---192.168.20.100/24的地址,网关为192.168.20.1。
dhcpserver2:192.168.30.10---192.168.30.100/24的地址,网关为192.168.30.1。
AClan端口地址为192.168.1.228•正确配置交换机和AC使AP获得相应地址并上线。
![思科交换机基本配置](http://p2.ttnews.xyz/loading.gif)
Cisco3560G配置
interfaceGigabitEthernet0/1 interface Vlan10
switchportaccess vlan 10 ipaddress 192.168.1.1 255.255.255.0
switchportmode access
!
interfaceGigabitEthernet0/2 interface Vlan20
switchport access vlan 20 ip address 192.168.20.1255.255.255.0
switchport mode access ip helper-address192.168.1.228
!
interfaceGigabitEthernet0/3 interface Vlan30
switchport access vlan 30 ip address 192.168.30.1255.255.255.0
switchport mode access ip helper-address192.168.1.228
iprouting service dhcp
ip dhcp relay information trust-all
AC配置
瘦AP端口地址:192.168.1.228 255.255.255.0
瘦AP端口DHCP:
dhcpserver1:192.168.20.10---192.168.20.100/24的地址,网关为192.168.20.1。
dhcpserver2:192.168.30.10---192.168.30.100/24的地址,网关为192.168.30.1。
静态路由:
目的地址 0.0.0.0
子网掩码 0.0.0.0
下一跳 192.168.1.1
Switch(config)#iprouting (全局路由)思科默认不开启
Switch(config)#iproute 192.168.2.0 255.255.255.0 192.168.1.1 (静态路由格式:目的地址 子网掩码 下一跳)
静态路由测试实例
AP通过dhcp方式上线,集中转发正常广播SSID•AC开启2个虚接口,STA连接vif1,Vif1属于vlan1地址192.168.10.1/24,vif2属于vlan2地址192.168.20.1/24
3560G1端口与AC的vif2相连,地址为192.168.20.2/24
3560G2端口与PC相连,地址为192.168.30.1/24
PC的地址为192.168.30.1/24网关为192.168.30.1
测试要求:STA正常获得地址并且与PC通信。
Cisco3560G配置
interfaceVlan20
ipaddress 192.168.20.2 255.255.255.0
interfaceVlan30
ipaddress 192.168.30.1 255.255.255.0
iproute 192.168.10.0 255.255.255.0 192.168.20.1
iprouting
interfaceGigabitEthernet0/1
switchport access vlan 20
switchport mode access
interfaceGigabitEthernet0/2
switchport access vlan 30
switchport mode access
AC开启2个虚接口vif1、vif2,vif1开启dhcpserver功能,给STA分配地址,同时将vif1的地址设置为网关。
同时配置静态路由
目的地址 192.168.30.0
子网掩码 255.255.255.0
下一跳: 192.168.20.2
![思科交换机基本配置](http://p2.ttnews.xyz/loading.gif)
在三层交换机上划分三个VLAN,VLAN10 VLAN20 VLAN30,其管理地址分别为192.168.10.1,192.168.20.1,192.168.1.226,瘦AP通过DHCP的方式获得地址,解析到交换机的地址。
AC配置:
AP通过cisco获得地址,通过option43字段信息找到AC并关联上线。
AC设置缺省路由,下一跳指向与lan口相连的cisco端口地址。
AC开启vif与radius服务器能够正常通信。
瘦AP模板
AP下发相同的模板,STA正常关联后经过802.1x认证。
关联成功后,查看无线终端列表,将未关联的AP信号加强,使STA漫游至与这台AP关联。
STA开启抓包,在发生切换时应该能抓到reassociation的重关联报文。
閱讀更多 弱電寶 的文章