Linux的DHCP服务配置及
一、DHCP概述及原理
二、配置命令步骤
1、设置DHCP配置文件
yum -y install dhcp //首先安装dhcp
cd /etc/dhcp
less dhcpd.conf //看一下dhcp配置文件,大多无内容
cd /usr/share/doc/dhcp-4.2.5 //dhcp配置文件参考模板
less dhcpd.conf.example //查看配置文件参考模板
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf //将模板文件复制到配置文件中
vim /etc/dhcp/dhcpd.conf //进入编辑dhcp配置文件
2、设置全局配置
default-lease-time 21600; //默认租约为 6 小时,单位为秒
max-lease-time 43200; //最大租约为 12 小时,单位为秒
option domain-name "gg.com"; //指定默认域名
option domain-name-servers 8.8.8.8; //指定 DNS 服务器地址
ddns-update-style none //禁用 DNS 动态更新
3、网段声明
作用于整个子网段,部分配置参数优先级高于全局配置参数
4yy 复制模板,p:下一行粘贴 网关一般时.1或者.254
subnet 192.168.80.0 netmask 255.255.255.0 {
//首先声明dhcp服务器分配网段的地址池以及子网掩码
range 192.168.100.10 192.168.100.20; //设置ip地址池
option routers 192.168.100.254; //指定默认网关
}
subnet 192.168.1.0 netmask 255.255.255.0 {
//其次声明其他网段以及子网
range 192.168.1.10 192.168.1.20; //设置ip地址池
option routers 192.168.1.254; //指定默认网关
}
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.10 192.168.2.20;
option routers 192.168.2.254;
}
4、host主机声明(给单机分配固定的IP地址)
host hostname {
//指定需要分配固定IP地址的客户机名称
hardware ethernet xx:xx:xx:xx:xx:xx; //指定该主机的MAC地址
fixed-address 192.168.71.88; //指定保留给该主机的IP地址
}
5、开启服务
systemctl start dhcpd //开启dhcp服务
systemctl stop firewalld //关闭防火墙
sentenforce 0 //关闭防火墙
netstat -naup | grep 67 //查看服务是否启动
tail -f /var/log/messages //如果启动失败,可以通过查看日志文件来排查错误
6、实例配置
设置网络
<Huawei>
<Huawei>u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname sw2
[sw2]user-interface console 0
[sw2-ui-console0]idle-timeout 0 0
[sw2-ui-console0]vlan bat 10 20 100
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw2]int g0/0/3
[sw2-GigabitEthernet0/0/3]p l t
[sw2-GigabitEthernet0/0/3]p t a v a
[sw2-GigabitEthernet0/0/3]int vlanif 10
[sw2-Vlanif10]ip add 192.168.1.254 24
[sw2-Vlanif10]int vlan 20
[sw2-Vlanif20]ip add 192.168.2.254 24
[sw2-Vlanif20]int vlan 100
[sw2-Vlanif100]ip add 192.168.100.254 24
[sw2-Vlanif100]
[sw2-Vlanif100]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[sw2]
[sw2]dhcp enable
[sw2]int vlan 100
[sw2-Vlanif100]dhcp select relay
[sw2-Vlanif100]dhcp relay server-ip 192.168.100.20
[sw2-Vlanif100]int vlan 10
[sw2-Vlanif10]dhcp select relay
[sw2-Vlanif10]dhcp relay server-ip 192.168.100.20
[sw2-Vlanif10]int vlan 20
[sw2-Vlanif20]dhcp select relay
[sw2-Vlanif20]dhcp relay server-ip 192.168.100.20
<Huawei>
<Huawei> u t m
Info: Current terminal monitor is off.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]q
[Huawei]vlan bat 10 20 100
Info: This operation may take a few seconds. Please wait for a moment...done.
[Huawei]int e0/0/1
[Huawei-Ethernet0/0/1]p l a
[Huawei-Ethernet0/0/1]p d v 10
[Huawei-Ethernet0/0/1]int e0/0/2
[Huawei-Ethernet0/0/2]p l a
[Huawei-Ethernet0/0/2]p d v 20
[Huawei-Ethernet0/0/2]int e0/0/3
[Huawei-Ethernet0/0/3]p l a
[Huawei-Ethernet0/0/3]p l t
[Huawei-Ethernet0/0/3]p t a v a
[Huawei-Ethernet0/0/3]int e0/0/4
[Huawei-Ethernet0/0/4]p l a
[Huawei-Ethernet0/0/4]p d v 100
[Huawei-Ethernet0/0/4]
[Huawei-Ethernet0/0/4]
虚拟机设置
宿主机配置
配置网卡设置
重启网卡
1.安装dhcp
查看挂载
2.复制模板文件并配置
3.配置内容
4.在ensp验证结果