前提机器能上网或已下载dhcp服务
yum install dhcp -y #下载dhcp
find / -name dhcpd.conf #查看配置文件位置
vi /etc/dhcp/dhcpd.conf #编辑配置文件
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
subnet 172.16.70.0 netmask 255.255.255.0{
range 172.16.70.10 172.16.70.20;
option domain-name-servers 114.114.114.114;
option domain-name "internal.example.org";
option routers 172.16.70.2;
default-lease-time 600;
max-lease-time 7200;
:wq
systemctl start dhcpd.service #启动dhcp
systemctl enable dhcpd.service #开机自启
ps -aux | dhcp #查看dhcp是否运行
netstat -anpu | grep ":67"
这里介绍一下dhcp配置文件
subnet 172.16.70.0 netmask 255.255.255.0{//网段
option routers 192.168.0.1;//为客户机设置默认网关
option net-mask 255.255.255.0;//子网掩码为24位
option nis-domain "domian.org";
option domain-name-server 192.168.1.1;//域名
range dynamic-bootp 192.168.0.128 192.168.0.254//地址分配范围
default-lease-time 21300;//默认租赁时间
max-lease-time 432000;//最大租赁时间(秒)
}
测试连通性,前提两台虚拟机在同一网段
ip add
ifdown ens33
ifup ens33