range参数:设置用于分配的IP地址池
option subnet-mask参数:设置客户机的子网掩码
option routers参数:设置客户机的默认网关地址
三、配置步骤
1.使用 DHCP 动态的给 PC 机分配 IP 地址
① eNSP实验拓扑图如下
注:配置完“Cloud”之后才能用串口线连接
<Huawei>undo terminal monitor <Huawei>system-view [L2-SW1]user-interface console 0[L2-SW1-ui-console0]idle-timeout 0 0[L2-SW1-ui-console0]quit [L2-SW1]vlan batch 10 20 100[L2-SW1]interface Ethernet 0/0/1 [L2-SW1-Ethernet0/0/1]port link-type access[L2-SW1-Ethernet0/0/1]port default vlan 10[L2-SW1-Ethernet0/0/1]quit[L2-SW1]interface Ethernet 0/0/2 [L2-SW1-Ethernet0/0/2]port link-type access[L2-SW1-Ethernet0/0/2]port default vlan 20[L2-SW1-Ethernet0/0/2]quit[L2-SW1]interface Ethernet 0/0/3 [L2-SW1-Ethernet0/0/3]port link-type access[L2-SW1-Ethernet0/0/3]port default vlan 100[L2-SW1-Ethernet0/0/3]quit[L2-SW1]interface Ethernet 0/0/4 [L2-SW1-Ethernet0/0/4]port link-type access[L2-SW1-Ethernet0/0/4]port default vlan 100[L2-SW1-Ethernet0/0/4]quit[L2-SW1]interface GigabitEthernet0/0/1[L2-SW1-GigabitEthernet0/0/1]port link-type trunk[L2-SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20 100[L2-SW1-GigabitEthernet0/0/1]quit
<Huawei>undo terminal monitor <Huawei>system-view [Huawei]sysname L3-SW2[L3-SW2]user-interface console 0[L3-SW2-ui-console0]idle-timeout 0 0[L3-SW2-ui-console0]quit[L3-SW2]vlan batch 10 20 100[L3-SW2]interface GigabitEthernet0/0/1[L3-SW2-GigabitEthernet0/0/1]port link-type trunk[L3-SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20 100[L3-SW2-GigabitEthernet0/0/1]quit[L3-SW2]interface Vlanif 10 [L3-SW2-Vlanif10]ip address 192.168.10.1 255.255.255.0 [SW2-Vlanif20]un sh[L3-SW2]interface Vlanif 20 [L3-SW2-Vlanif20]ip address 192.168.20.1 255.255.255.0 [SW2-Vlanif20]un sh[L3-SW2]interface Vlanif 100[L3-SW2-Vlanif100]ip address 192.168.100.1 255.255.255.0 [SW2-Vlanif20]un sh[SW2-Vlanif100]int g0/0/1[SW2-GigabitEthernet0/0/1]port link-type trunk [SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan all
[L3-SW2]dhcp enable##开启DHCP功能[L3-SW2]interface Vlanif 10##配置虚接口ip , 选择dhcp中继模式 , 请求指向dhcp服务器ip[L3-SW2-Vlanif10]dhcp select relay[L3-SW2-Vlanif10]dhcp relay server-ip 192.168.100.100 [L3-SW2-Vlanif10]quit[L3-SW2]interface Vlanif 20 [L3-SW2-Vlanif20]dhcp select relay [L3-SW2-Vlanif20]dhcp relay server-ip 192.168.100.100 [L3-SW2-Vlanif20]quit[L3-SW2]interface Vlanif 100 [L3-SW2-Vlanif100]dhcp select relay [L3-SW2-Vlanif100]dhcp relay server-ip 192.168.100.100[L3-SW2-Vlanif100]quit
②虚拟机
[root@xjj ~]# yum -y install dhcp已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile软件包 12:dhcp-4.2.5-58.el7.centos.x86_64 已安装并且是最新版本无须任何处理[root@xjj ~]# cd /etc/dhcp/##dhcp的配置文件是/etc/dhcp/dhcpd.conf[root@xjj dhcp]# lsdhclient.ddhclient-exit-hooks.ddhcpd6.confdhcpd.confscripts[root@xjj dhcp]# less dhcpd.conf##查看一下内容[root@xjj ~]# cd /usr/share/doc/dhcp-4.2.5/到该目录下去寻找dhcp配置模板[root@xjj dhcp-4.2.5]# ls##“dhcpd.conf.example”dhcpd6.conf.exampledhcpd.conf.exampleldap[root@xjj dhcp-4.2.5]# cp dhcpd.conf.example /etc/dhcp/dhcpd.conf##将模板覆盖到/etc/dhcp/dhcpd.conf中cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y[root@xjj ~]# cd /etc/dhcp/##回到/etc/dhcp目录下[root@xjj dhcp]# lsdhclient.ddhclient-exit-hooks.ddhcpd6.confdhcpd.confscripts[root@xjj dhcp]# less dhcpd.conf##查看配置文件并进行下一步编辑
推荐阅读