[Linux]CentOS/Ubuntu开启DHCP服务,并根据MAC地址分配特定IP地址

2021-02-27 43点热度 0人点赞 0条评论

前言

让局域网内的电脑动态分配IP,可以借助硬件网络设备(如路由器等),不过一般功能比较弱,可能没有根据电脑的MAC地址分配特定的IP的功能。而Linux的dhcpd服务,就可以轻松做到。

安装

一般Linux发新版本,都很容易安装

#centos 
yum install dhcp

#or ubuntu
apt install isc-dhcp-server

配置

以局域网192.168.1.0/24 网关192.168.1.254 DNS192.168.1.253、192.168.1.252 DHCP服务器192.168.1.251为例:

vim /etc/dhcp/dhcpd.conf

option netbios-name-servers 192.168.1.253,192.168.1.252;
#ddns-update-style none;
#ddns-updates off;
#option time-servers 10.0.1.3;
ddns-update-style none;
#option domain-name-servers 192.168.1.253,192.168.1.252;
option domain-name-servers 192.168.1.253;
#option domain-name "example";
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
subnet 192.168.1.0 netmask 255.255.255.0 {
    option netbios-name-servers 192.168.1.253;
    #option time-servers 10.0.1.2;
    option domain-name-servers 192.168.1.253;
    #option domain-name "example";
    option subnet-mask 255.255.255.0;
    option routers 192.168.1.254;
    #ddns-updates off;
    max-lease-time 86400;
    default-lease-time 43200;
#	range 10.0.6.10 10.0.6.30;
    }

# 客户端根据MAC地址分配静态IP
host webmonitor {hardware ethernet 00:A5:40:20:88:DE;fixed-address 192.168.1.239;}
host user1 {hardware ethernet 00:A5:40:20:88:11;fixed-address 192.168.1.11;}
host user1 {hardware ethernet 00:A5:40:20:88:12;fixed-address 192.168.1.12;}

配置好后,重新启动dhcp服务器,并开启开机自动即可

systemctl restart dhcpd
systemctl enable dhcpd

 

admin

这个人很懒,什么都没留下

文章评论

*

code