分享

Cisco路由器上配置DHCP全程详解

 昵称7497926 2011-08-18
    配置DHCP服务器实例网络环境:一台2811路由,一台2950交换机,一台3560交换机,三台自动获取IP地址的PC。
划分三个vlan1,vlan2,vlan3。拓扑如下
        
   配置命令及步骤如下:
  
  第一步:配置路由成为DHCP服务器  
 
    1、设置地址池 /*有几个VLAN要设几个地址池,我们有3个vlan所以要设3个地址池*/
 
    /*第一个地址池*/
       Switch(Config)#ip dhcp pool test01
       /*建立地址池,test01为名称~~名字可自己设置
 
       Switch(Config-pool)#network 192.168.1.0 255.255.255.0
       /*此处为设置要分配的子网,可根据自己喜好设置
 
       Switch(Config-pool)#Default-router 192.168.1.254       
       /*此处为设置上面分配子网IP的网关,此处和下面要设置的vlan ip相关联,你想让哪个vlan分配什么IP子网段
         就要把vlan的IP地址设成该子网的网关
 
       Switch(Config-pool)#lease 30
       /*租期为30天,可自己改
       Switch(Config-pool)#exit
 
    /*第二个地址池*/
       Switch(Config)#ip dhcp pool test02
       Switch(Config-pool)#network 192.168.2.0 255.255.255.0
       Switch(Config-pool)#Default-router 192.168.2.254
       Switch(Config-pool)#lease 30
       Switch(Config-pool)#exit
       /*同上
 
    /*第三个地址池*/
       Switch(Config)#ip dhcp pool test03
       Switch(Config-pool)#network 192.168.3.0 255.255.255.0
       Switch(Config-pool)#Default-router 192.168.3.254
       Switch(Config-pool)#lease 30
       Switch(Config-pool)#exit
       /*同上
 
 
   PS:Switch(Config-pool)#domain-name XXXX              
       /*此命令是为客户机配置域后缀,XX为域后缀~比如yonghu.com,这里不使用该命令
 
       Switch(Config-pool)#Dns-server x.x.x.x             
       /*这是设置DNS服务器地址,我们在这里不使用该命令
 
       Switch(Config-pool)#netbios-name-server x.x.x.x   
       /*为客户机配置wins服务器地址,我们在这里不使用该命令

       Switch(Config-pool)#netbios-node-type h-node      
       /*为客户机配置h节点模式,我们在这里不使用该命令

       Switch(Config-pool)#ip dhcp pool XXX              
       /*此命令为在当前地址池下创建一个子地址池,这个子地址池将继承域后缀、DNS服务器、 
       wins服务器等可继承的参数 ,一个地址池可以设置多个子池,这样可以减少很多麻烦,我们在这里不使用该命令
 

    2、设置DHCP保留不分配的地址 /*可以理解为设置不分配的IP地址,这里可以根据环境情况来设置,也可不设置,在此我只是举例以说明命令作用*/
      
       Switch(Config)Ip Dhcp Excluded-address 192.168.1.2 192.168.1.10
       /* ip 192.168.1.2至192.168.1.10这9个IP地址服务器不分配出去
 
       Switch(Config)Ip Dhcp Excluded-address 192.168.2.2 192.168.2.10
       /*同上 192.168.2.2至192.168.2.10不分配

       Switch(Config)Ip Dhcp Excluded-address 192.168.3.2 192.168.3.10
       /*同上 192.168.3.2至192.168.3.10不分配
 
       PS:一般要把网关地址设成不分配~~比如我们刚才设的子网网关192.168.1.254
 
    3、设置连接端口IP
       Switch(Config)#fastEthernet 0/4
       Switch(Config-if)#switchport address 192.168.4.2 255.255.255.0
       Switch(Config-if)#no shutdown
       Switch(Config-if)#exit
  
    4、配置路由表
       Switch(Config)#ip route 192.168.1.0 255.255.255.0 192.168.4.1 
       /*要送到192.168.1.0网段的数据发往192.168.4.1 ip地址
 
       Switch(Config)#ip route 192.168.2.0 255.255.255.0 192.168.4.1              
       Switch(Config)#ip route 192.168.3.0 255.255.255.0 192.168.4.1  
       Switch(Config)#ip route 192.168.4.0 255.255.255.0 192.168.4.1       
       Switch(Config)#exit
       Switch#show ip route
       /*会看到路由表上已经更新:
 
      
    PS:这里使用的时静态路由~~但是本人推荐用动态路由~这里只是因为需要设置的IP段比较少所以才选用静态路由设置
        但是一般情况下是不会选择静态路由的,特别是IP段特别多得时候,不然设置很麻烦~所以推荐使用动态路由!命令如下
        Switch(Config)#router rip
        Switch(Config-router)#network x.x.x.x    /* x.x.x.x为地址段~~如192.168.1.0 
       
    5、开启DHCP服务
       Switch(Config)#Service Dhcp
       Switch(Config)#ip dhcp relay information option     
       /*这个命令现在很少使用了,个人感觉可有可无,因为已经
         设置helper-address了(下面的三层交换机里设置),但是保险起见打吧- -
 
  第二步:配置三层交换机3560
 
    1、创建VLAN:
       Switch>en
       Switch#configure terminal
       Switch(config)#vlan 2
       Switch(config-vlan)#vlan 3
       Switch(config-vlan)#exit
 
    2、设置vlan的IP 以及相关参数
       Switch(config)#interface vlan 1
       Switch(config-if)#ip add 192.168.1.254 255.255.255.0
       Switch(config-if)#ip helper-address 192.168.4.2
       Switch(config-if)#no shutdown
       Switch(config-if)#exit
       Switch(config)#interface vlan 2
       Switch(config-if)#ip add 192.168.2.254 255.255.255.0      //IP地址要和DHCP设置子网的网关一样,
       Switch(config-if)#ip helper-address 192.168.4.2             否则PC无法获取IP地址且无法通信    
       Switch(config-if)#no shutdown
       Switch(config-if)#exit
       Switch(config)#interface vlan 3
       Switch(config-if)#ip address 192.168.3.254 255.255.255.0
       Switch(config-if)#ip helper-address 192.168.4.2          //此处为设置指定dhcp服务器的地址,
       Switch(config-if)#no shutdown                              表示通过Ethernet0向该服务器发送DHCP请求包
                                                           
    3、设置各个连接端口参数
       Switch(Config)#Interface  fastEthernet 0/4
       Switch(Config)#switchport trunk encapsulation dot1q      //二层交换机和三层不一样,必须先设置数据封装格式
       Switch(Config)#switchport mode trunk                     //对应二层交换机,形成trunk口实现多vlan通信  
       Switch(Config)#Interface  fastEthernet 0/1
       Switch(config-if)#no switchport                          //使端口开启三层功能,可以理解为变成路由端口
       Switch(config-if)#ip address 192.168.4.1 255.255.255.0
       Switch(config-if)#no shutdown
       Switch(config-if)#exit
       Switch(config)#ip  routing                              //开启路由功能
    
     4、设置路由表
        Switch(Config)#router rip                               //进入动态路由模式
        Switch(Config-router)#network 192.168.1.0               //自动学习 192.168.1.0网段地址
        Switch(Config-router)#network 192.168.2.0               //同上
        Switch(Config-router)#network 192.168.3.0
        Switch(Config-router)#network 192.168.4.0 
        Switch(Config-router)#exit    
      /*配置动态路由后,记得要在特权模式下查看路由表,确保要学的IP地址都已学到     
    
  第三步:配置二层交换机2950
 
    1、创建VLAN:
       Switch1>en
       Switch1#configure terminal
       Switch1(config)#vlan 2
       Switch1(config-vlan)#vlan 3
       Switch1(config-vlan)#exit
 
    2、设置端口全局参数
       Switch1(Config)#Interface Range fastEthernet 0/1 - 3    
       /*注意:哪些端口连接PC就设置哪个端口,如果设置的端口是连接交换机或者路由的就有可能造成环路
      
       Switch1(Config-if-range)#switchport mode access 
       /*此处把端口设成为portfast模式~即不在不再使用STP的算法,也就是说端口从堵塞直接变为转发
                   
    3、将端口添加到VLAN2,3中(PS:所有端口默认VLAN1~~这个都知道吧~~)
       Switch1(Config)#interface  fastethernet 0/2 
       Switch1(Config)#switchport access Vlan 2
       Switch1(Config)interface  fastethernet 0/3 
       Switch1(Config-if-range)#switchport access vlan 3
 
    4、将F0/4端口设成trunk模式
       Switch1(Config)#interface  fastethernet 0/4
       Switch1(Config)#switchport mode trunk
 
  第四步:设置PC机
   
      1、 这步很简单只要吧PC 设成自动获取IP就好,如下图
 
        
 
      2、更新DHCP
     
        打开开始菜单>运行>输入CMD然后回车,出现命令窗口>输入ipconfig/renew,然后你就可以看到服务器分给这台PC的ip地址了:
 
          
    PS:到这里就结束了~~本章讲得是用路由做DHCP~但其实只要有三层交换机就可以了~~不需要用路由~~在三层交换机做DHCP中继和在路由上配置命令是一样的!
 
本文来自 右手书画 的个人图书馆 转载请说明出去:http://www.360doc.com/showWeb/0/0/141403048.aspx
 
       

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多