实验要求:
Router上配置DHCP服务器,PC机能自动获取到IP。
相关配置要求见图。
DHCP地址数据库设计为树型模式,树根是自动分配到所有网段的地址池,树枝是子网的地址池,分到的IP就相当于叶子(这个比喻不错)。
配置DHCP服务器的具体操作步骤如下:
Router: router> en router# conf t Enter configuration commands one per line. End with CNTL/Z. Router (config) #ip dhcp excluded-address 192.168.2.1 192.168.2.2
Router (config) #ip dhcp excluded-address 192.168.3.1 192.168.3.2//不用于动态地址分配的地址 route(config)# ip dhcp pool ipku //配置一个根地址池,IPku是地址池的名称,你可以采用有意义的字符串来表示 Router (dhcp-config) #network 192.168.0.0 255.255.0.0 //为所有客户机动态分配的地址段Router (dhcp-config) #domain-name Test.com //为客户机配置域后缀 Router (dhcp-config) #dns-server 192.168.1.1 //为客户机配置DNS服务器 Router (dhcp-config) #netbios-name-server 192.168.1.1 //为客户机配置wins服务器,没有可以不用配置 Router (dhcp-config) #lease 10 //地址租用期为10天,10天后地址被收回 Router (dhcp-config) #ip dhcp pool vlan1 //为VLAN1配置地址池,本池是ipku池的子池,将从ipku继承域后缀、DNS服务器、wins服务器等参数 Router (dhcp-config) #network 192.168.2.0 255.255.255.0 //VLAN1动态分配192.168.2这个网段内可以被分配的地址 Router (dhcp-config)#default-router 192.168.2.1 //为客户机配置默认的网关,即VLAN1的IP地址 Router (dhcp-config) #ip dhcp pool vlan2 //为VLAN2配置地址池,本池是global池的子池,将从global继承域后缀、DNS服务器、wins服务器等可继承的参数 Router (dhcp-config)#network 192.168.3.0 255.255.255.0 Router (dhcp-config) #default-router 192.168.3.1 //为客户机默认的网关,VLAN2的IP地址DHCP服务器就配置好了。 如何让PC机获得IP呢? 接下来配置单臂路由让Vlan之间通信。 Router(config)#inter fa0/0.1 //进入子接口 Router(config-subif)#encap dot1q vlan 1 //封装Vlan1 Router(config-subif)#ip add 192.168.2.2 255.255.255.0 Router(config-subif)#inter fa0/0.2 Router(config-subif)#encap dot1q vlan 2 Router(config-subif)#ip ad 192.168.3.2 255.255.255.0
Switch: Switch> en Switch# conf t Switch(config)#inter fa0/0 Switch(config-if)#switchport mode trunk //配置成Trunk,因为要允许多个Vlan通过 Switch(config-if)#no shut Switch(config-if)#inter fa0/1 Switch(config-if)#switchport mode access //配置成Access,并绑定Vlan1 Switch(config-if)#switch access vlan 1 Switch(config-if)#no shut Switch(config-if)#switchport mode access Switch(config-if)#swith access vlan 2 Switch(config-if)#no shut Switch(config-if)#inter vlan 1 //配置Vlan的IP Switch(config-if)#ip add 192.168.2.1 255.255.255.0 Switch(config-if)#inter vlan 2 Switch(config-if)#ip add 192.168.3.1 255.255.255.0
PC机: 在运行中用Cmd进入 MS-DOS 如果IP是自动获取,用 ipconfig /all //查看详细的配置 ipconfig /release //释放IP 变成0.0.0.0 ipconfig /renew //租得IP 结果:Ipconfig /all Ethernet adapter 本地连接:
Connection-specific DNS Suffix . : write Description . . . . . . . . . . . : NVIDIA nForce Networking Controller Physical Address. . . . . . . . . : 00-16-EC-1F-A8-0B Dhcp Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IP Address. . . . . . . . . . . . : 192.168.3.3 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.3.1 DHCP Server . . . . . . . . . . . : 192.168.3.2 DNS Servers . . . . . . . . . . . : 192.168.1.1 Lease Obtained. . . . . . . . . . : 2007年1月13日 17:37:09 Lease Expires . . . . . . . . . . : 2007年1月23日 17:37:09
可以在DHCP服务器上看到 sh ip dhcp binding //显示地址分配情况 Router(config)#do show ip dhcp binding Bindings from all pools not associated with VRF: IP address Client-ID/ Lease expiration Type Hardware address/ User name 192.168.2.66 0100.0c29.0a41.63 Jan 13 2007 05:50 PM Automatic 192.168.3.3 0100.16ec.1fa8.0b Jan 14 2007 05:37 PM Automatic Router(config)#
相关的DHCP调试命令: no service dhcp //停止DHCP服务[默认为启用DHCP服务] sh ip dhcp binding //显示地址分配情况 show ip dhcp conflict //显示地址冲突情况 debug ip dhcp server {events | packets | linkage} //观察DHCP服务器工作情况
实验到此结束。
出处:互联网 |