下面我们来对配置DHCP的内容进行一下阐述。对于其过程的步骤以及方法,命令和代码都进行了细致的阐述。

对于DHCP来说,它是一个非常强大的协议。在网络中,它的地位非常重要,可以集中管理IP的调配。那么对于这个协议的相关内容,我们今天主要讲解一下配置DHCP的知识。

配置DHCP代码详解(dhcp配置详细步骤)  配置DHCP 第1张

网络环境:一台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,默认访问控制列表的规则是拒绝所有包。

配置DHCP命令及步骤如下:

第一步:创建VLAN:

  1. Switch>en
  2. Switch#VlanDatabase
  3. Switch(Vlan)>Vlan2Nameserver
  4. Switch(Vlan)>Vlan3Namework01
  5. Switch(vlan)>Vlan4Namework02

第二步:设置VLAN IP地址:

  1. Switch#ConfigT
  2. Switch(Config)>IntVlan2
  3. Switch(Config-vlan)IpAddress192.168.2.1255.255.255.0
  4. Switch(Config-vlan)NoShut
  5. Switch(Config-vlan)>IntVlan3
  6. Switch(Config-vlan)IpAddress192.168.3.1255.255.255.0
  7. Switch(Config-vlan)NoShut
  8. Switch(Config-vlan)>IntVlan4
  9. Switch(Config-vlan)IpAddress192.168.4.1255.255.255.0
  10. Switch(Config-vlan)NoShut
  11. Switch(Config-vlan)Exit
  12. /*注意:由于此时没有将端口分配置到VLAN2,3,4,所以各VLAN会DOWN掉,待将端口分配到各VLAN后,VLAN会起来*/

第三步:设置端口全局参数

  1. Switch(Config)InterfaceRangeFa0/1-24
  2. Switch(Config-if-range)SwitchportModeAccess
  3. Switch(Config-if-range)Spanning-treePortfast
  4. 第四步:将端口添加到VLAN2,3,4中
  5. /*将端口1-8添加到VLAN2*/
  6. Switch(Config)InterfaceRangeFa0/1-8
  7. Switch(Config-if-range)SwitchportAccessVlan2
  8. /*将端口9-16添加到VLAN3*/
  9. Switch(Config)InterfaceRangeFa0/9-16
  10. Switch(Config-if-range)SwitchportAccessVlan3
  11. /*将端口17-24添加到VLAN4*/
  12. Switch(Config)InterfaceRangeFa0/17-24
  13. Switch(Config-if-range)SwitchportAccessVlan4
  14. Switch(Config-if-range)Exit
  15. /*经过这一步后,各VLAN会起来*/

第五步:用3550配置DHCP服务器

  1. /*VLAN2可用地址池和相应参数的配置,有几个VLAN要设几个地址池*/
  2. Switch(Config)IpDhcpPoolTest01
  3. /*设置可分配的子网*/
  4. Switch(Config-pool)Network192.168.2.0255.255.255.0
  5. /*设置DNS服务器*/
  6. Switch(Config-pool)Dns-server192.168.2.10
  7. /*设置该子网的网关*/
  8. Switch(Config-pool)Default-router192.168.2.1
  9. /*配置VLAN3所用的地址池和相应参数*/
  10. Switch(Config)IpDhcpPoolTest02
  11. Switch(Config-pool)Network192.168.3.0255.255.255.0
  12. Switch(Config-pool)Dns-server192.168.2.10
  13. Switch(Config-pool)Default-router192.168.3.1
  14. /*配置VLAN4所用的地址池和相应参数*/
  15. Switch(Config)IpDhcpPoolTest03
  16. Switch(Config-pool)Network192.168.4.0255.255.255.0
  17. Switch(Config-pool)Dns-server192.168.2.10
  18. Switch(Config-pool)Default-router192.168.4.1

第六步:配置DHCP保留不分配的地址

  1. Switch(Config)IpDhcpExcluded-address192.168.2.2192.168.2.10
  2. Switch(Config)IpDhcpExcluded-address192.168.3.2192.168.3.10
  3. Switch(Config)IpDhcpExcluded-address192.168.4.2192.168.4.10

第七步:启用路由

  1. /*路由启用后,各VLAN间主机可互相访问*/
  2. Switch(Config)IpRouting

第八步:配置访问控制列表

  1. Switch(Config)access-list103permitip192.168.2.00.0.0.255192.168.3.00.0.0.255
  2. Switch(Config)access-list103permitip192.168.3.00.0.0.255192.168.2.00.0.0.255
  3. Switch(Config)access-list103permitudpanyanyeqbootpc
  4. Switch(Config)access-list103permitudpanyanyeqtftp
  5. Switch(Config)access-list103permitudpanyeqbootpcany
  6. Switch(Config)access-list103permitudpanyeqtftpany
  7. Switch(Config)access-list104permitip192.168.2.00.0.0.255192.168.4.00.0.0.255
  8. Switch(Config)access-list104permitip192.168.4.00.0.0.255192.168.2.00.0.0.255
  9. Switch(Config)access-list104permitudpanyeqtftpany
  10. Switch(Config)access-list104permitudpanyeqbootpcany
  11. Switch(Config)access-list104permitudpanyeqbootpcany
  12. Switch(Config)access-list104permitudpanyeqtftpany

第九步:应用访问控制列表

  1. /*将访问控制列表应用到VLAN3和VLAN4,VLAN2不需要*/
  2. Switch(Config)IntVlan3
  3. Switch(Config-vlan)ipaccess-group103out
  4. Switch(Config-vlan)IntVlan4
  5. Switch(Config-vlan)ipaccess-group104out

第十步:结束并保存配置

  1. Switch(Config-vlan)End
  2. Switch#CopyRunStart
转载请说明出处
知优网 » 配置DHCP代码详解(dhcp配置详细步骤)

发表评论

您需要后才能发表评论