zhouandtao 发表于 2018-7-11 08:14:41

cisco DHCP功能实现多VLAN的IP地址自动分配

利用三层交换机自带的DHCP功能实现多VLAN的IP地址自动分配  (一) 配置方法一
  1.同时为多个VLAN的客户机分配地址
  2.VLAN内有部分地址采用手工分配的方式
  3.为客户指定网关、Wins服务器等
  4.VLAN 2的地址租用有效期限为1天,其它为3天
  5.按MAC地址为特定用户分配指定的IP地址
以下内容需要回复才能看到  最终配置如下:
  ip dhcp excluded-address 10.1.1.1 10.1.1.19 //不用于动态地址分配的地址
  ip dhcp excluded-address 10.1.1.240 10.1.1.254
  ip dhcp excluded-address 10.1.2.1 10.1.2.19
  !
  ip dhcp pool global //global是pool name, 由用户指定
  network 10.1.0.0 255.255.0.0 //动态分配的地址段
  domain-name client.com //为客户机配置域后缀
  dns-server 10.1.1.1 10.1.1.2 //为客户机配置dns服务器
  netbios-name-server 10.1.1.5 10.1.1.6 //为客户机配置wins服务器
  netbios-node-type h-node //为客户机配置节点模式(影响名称解释的顺利,如h-node=先通过wins服务
  器解释...)
  lease 3 //地址租用期限: 3天
  ip dhcp pool vlan1
  network 10.1.1.0 255.255.255.0 //本pool是global的子pool, 将从global pool继承domain-name等
  option
  default-router 10.1.1.100 10.1.1.101 //为客户机配置默认网关
  !
  ip dhcp pool vlan2 //为另一VLAN配置的pool
  network 10.1.2.0 255.255.255.0
  default-router 10.1.2.100 10.1.2.101
  lease 1
  !
  ip dhcp pool vlan1_john //总是为MAC地址为...的机器分配...地址
  host 10.1.1.21 255.255.255.0
  client-identifier 010050.bade.6384 //client-identifier=01加上客户机网卡地址
  !
  ip dhcp pool vlan1_tom
  host 10.1.1.50 255.255.255.0
  client-identifier 010010.3ab1.eac8
  相关的DHCP调试命令:
  no service dhcp //停止DHCP服务[默认为启用DHCP服务]
  sh ip dhcp binding //显示地址分配情况
  show ip dhcp conflict //显示地址冲突情况
  debug ip dhcp server {events | packets | linkage} //观察DHCP服务器工作情况
  如果DHCP客户机分配不到IP地址,常见的原因有两个。第一种情况是没有把连接客户机的端口设置为
  Portfast方式。MS客户机开机后检查网卡连接正常,Link是UP的,就开始发送DHCPDISCOVER请求,而此时
  交换机端口正在经历生成树计算,一般需要30-50秒才能进入转发状态。MS客户机没有收到DHCP SERVER的
  响应就会给网卡设置一个169.169.X.X的IP地址。解决的方法是把交换机端口设置为Portfast方式:
  CatOS(4000/5000/6000): set spantree portfast mod_num/port_num enable; IOS(2900/3500):
  interface ... ; spanning-tree portfast
  (二) 配置方法二
  一台3550EMI交换机,划分三个vlan
  vlan2 为服务器所在网络,命名为server,IP地址段为192.168.2.0,子网掩码:255.255.255.0,网
  关:192.168.2.1,域服务器为windows 2000 advance server,同时兼作DNS服务器,IP地址为192.168.2.10
  vlan3为客户机1所在网络,IP地址段为192.168.3.0,子网掩码:255.255.255.0,网关:192.168.3.1命名为
  work01
  vlan4为客户机2所在网络,命名为work02,IP地址段为192.168.4.0,子网掩码:255.255.255.0,网
  关:192.168.4.1,
  3550作DHCP服务器,端口1-8划到VLAN 2,端口9-16划分到VLAN 3,端口17-24划分到VLAN 4.
  DHCP服务器实现功能:
  各VLAN保留2-10的IP地址不分配置,例如:192.168.2.0的网段,保留192.168.2.2至192.168.2.10的IP地址
  段不分配.
  安全要求:
  VLAN 3和VLAN 4 不允许互相访问,但都可以访问服务器所在的VLAN 2,
  默认访问控制列表的规则是拒绝所有包.
  配置命令及步骤如下:
  第一步:创建VLAN:
  Switch>en
  Switch#Vlan Database
  Switch(Vlan)>Vlan 2 Name server
  Switch(Vlan)>Vlan 3 Name work01
  Switch(vlan)>Vlan 4 Name work02
  第二步:设置VLAN IP地址:
  Switch#Config T
  Switch(Config)>Int Vlan 2
  Switch(Config-vlan)Ip Address 192.168.2.1 255.255.255.0
  Switch(Config-vlan)No Shut
  Switch(Config-vlan)>Int Vlan 3
  Switch(Config-vlan)Ip Address 192.168.3.1 255.255.255.0
  Switch(Config-vlan)No Shut
  Switch(Config-vlan)>Int Vlan 4
  Switch(Config-vlan)Ip Address 192.168.4.1 255.255.255.0
  Switch(Config-vlan)No Shut
  Switch(Config-vlan)Exit
  /*注意:由于此时没有将端口分配置到VLAN2,3,4,所以各VLAN会DOWN掉,待将端口分配到各VLAN后,VLAN会起来*/
  第三步:设置端口全局参数
  Switch(Config)Interface Range Fa 0/1 - 24
  Switch(Config-if-range)Switchport Mode Access
  Switch(Config-if-range)Spanning-tree Portfast
  第四步:将端口添加到VLAN2,3,4中
  /*将端口1-8添加到VLAN 2*/
  Switch(Config)Interface Range Fa 0/1 - 8
  Switch(Config-if-range)Switchport Access Vlan 2
  /*将端口9-16添加到VLAN 3*/
  Switch(Config)Interface Range Fa 0/9 - 16
  Switch(Config-if-range)Switchport Access Vlan 3
  /*将端口17-24添加到VLAN 4*/
  Switch(Config)Interface Range Fa 0/17 - 24
  Switch(Config-if-range)Switchport Access Vlan 4
  Switch(Config-if-range)Exit
  /*经过这一步后,各VLAN会起来*/
  第五步:配置3550作为DHCP服务器
  /*VLAN 2可用地址池和相应参数的配置,有几个VLAN要设几个地址池*/
  Switch(Config)Ip Dhcp Pool Test01
  /*设置可分配的子网*/
  Switch(Config-pool)Network 192.168.2.0 255.255.255.0
  /*设置DNS服务器*/
  Switch(Config-pool)Dns-server 192.168.2.10
  /*设置该子网的网关*/
  Switch(Config-pool)Default-router 192.168.2.1
  /*配置VLAN 3所用的地址池和相应参数*/
  Switch(Config)Ip Dhcp Pool Test02
  Switch(Config-pool)Network 192.168.3.0 255.255.255.0
  Switch(Config-pool)Dns-server 192.168.2.10
  Switch(Config-pool)Default-router 192.168.3.1
  /*配置VLAN 4所用的地址池和相应参数*/
  Switch(Config)Ip Dhcp Pool Test03
  Switch(Config-pool)Network 192.168.4.0 255.255.255.0
  Switch(Config-pool)Dns-server 192.168.2.10
  Switch(Config-pool)Default-router 192.168.4.1
  第六步:设置DHCP保留不分配的地址
  Switch(Config)Ip Dhcp Excluded-address 192.168.2.2 192.168.2.10
  Switch(Config)Ip Dhcp Excluded-address 192.168.3.2 192.168.3.10
  Switch(Config)Ip Dhcp Excluded-address 192.168.4.2 192.168.4.10
  第七步:启用路由
  /*路由启用后,各VLAN间主机可互相访问*/
  Switch(Config)Ip Routing
  第八步:配置访问控制列表
  Switch(Config)access-list 103 permit ip 192.168.2.0 0.0.0.255 192.168.3.0 0.0.0.255
  Switch(Config)access-list 103 permit ip 192.168.3.0 0.0.0.255 192.168.2.0 0.0.0.255
  Switch(Config)access-list 103 permit udp any any eq bootpc
  Switch(Config)access-list 103 permit udp any any eq tftp
  Switch(Config)access-list 103 permit udp any eq bootpc any
  Switch(Config)access-list 103 permit udp any eq tftp any
  Switch(Config)access-list 104 permit ip 192.168.2.0 0.0.0.255 192.168.4.0 0.0.0.255
  Switch(Config)access-list 104 permit ip 192.168.4.0 0.0.0.255 192.168.2.0 0.0.0.255
  Switch(Config)access-list 104 permit udp any eq tftp any
  Switch(Config)access-list 104 permit udp any eq bootpc any
  Switch(Config)access-list 104 permit udp any eq bootpc any
  Switch(Config)access-list 104 permit udp any eq tftp any
  第九步:应用访问控制列表
  /*将访问控制列表应用到VLAN 3和VLAN 4,VLAN 2不需要*/
  Switch(Config)Int Vlan 3
  Switch(Config-vlan)ip access-group 103 out
  Switch(Config-vlan)Int Vlan 4
  Switch(Config-vlan)ip access-group 104 out
  第十步:结束并保存配置
  Switch(Config-vlan)End
  Switch#Copy Run Start
页: [1]
查看完整版本: cisco DHCP功能实现多VLAN的IP地址自动分配