Ubuntu builds DHCP-Server

DHCP stands for Dynamic Host Configuration Protocol and it is mainly used to dynamically assign network configuration parameters such as IP addresses for interfaces and services. In a PXE environment, a DHCP server allows clients to request and automatically obtain an IP address to access the network.

0. Configure static ip
About configuring static IP

1. Installation:

$ sudo apt update
$ sudo apt install isc-dhcp-server

2. Specify the network card

$ sudo vim /etc/default/isc-dhcp-server
INTERFACES="enp2s0" (注:刚才配置的静态IP的那个网卡)

3. Modify the configuration file

$ sudo vim /etc/dhcp/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
authoritative;
allow booting;
allow bootp;
allow unknown-clients;

## 将以下内容注释:
##(域名服务和域名)
#  option domain-name-servers ns1.internal.example.org;
#  option domain-name "internal.example.org";
##(广播地址)
#  option broadcast-address 255.255.255.255;

subnet 192.168.15.0 netmask 255.255.255.0 {
    range 192.168.15.10 192.168.15.100;#IP地址池
    ## dhcp客户端可以获取的ip范围(非绑定的)
    ##如果已经设定了ip-mac绑定,又不允许未绑定的mac获取ip可以注释上行range部分

    default-lease-time 6000;                 #为客户机获取网络参数的默认租约时间
    max-lease-time 72000;                    #为客户机获取网络参数之后的最大租约时
    option subnet-mask 255.255.255.0;        #子网掩码
    option routers 192.168.15.254;           #路由
    option domain-name-servers 114.114.114.114; #域名服务器

    next-server 172.0.1.123;                 #tftp-server的ip(搭建pxe-server用)
    filename "xxxx/xx/pxelinux.0";           #NBP文件在tftp服务器中的相对位置(pxe用) 

    ## 绑定MAC地址和IP地址
    host PC_001 {                           # hostname 不能重复
    hardware ethernet aa:bb:cc:dd:00:11;    #主机mac地址  
    fixed-address 192.168.15.101;           #绑定IP,在range之外
    next-server 172.0.1.123;                #tftp-server的ip(搭建pxe-server用)
    filename "xxxx/xx/pxelinux.0";          #NBP文件在tftp服务器中的相对位置(pxe用) 
    }
    ## 可以帮定多条
}

For the above content, if the client does not need to download the startup file from the specified tftp server after obtaining the IP, the next-server and filename parts can be omitted.

4. Inspection method:

$ sudo netstat -nupl | grep dhcpd
# 或
$ sudo dhcpd -d

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325810666&siteId=291194637