This article will describe installing isc-dhcp-server and running DHCP server.
Table of Contents
1 Install isc-dhcp-server
Install isc-dhcp-server with apt.
$ sudo apt install -y isc-dhcp-server
2 /etc/default/isc-dhcp-server
Add configuration for DHCPD. INTERFACESv4 is a network interface name which is connected to a network which you try to provided DHCP.
$ INTERFACESv4=eth0 $ sudo sed -e 's/^#DHCPD_CONF=/DHCPD_CONF=/g' \ -e 's/^#DHCPD_PID=/DHCPD_PID=/g' \ -e "s/INTERFACESv4=\"\"/INTERFACESv4=\"${INTERFACESv4}\"/g" \ -i /etc/default/isc-dhcp-server
3 /etc/dhcp/dhcpd.conf
Define domain name, DHCP server IP address and gateway IP address. Mapping MAC address 52:54:00:5e:7a:a4 to IP address 192.168.11.250. Set IP address of this server to DNS server.
$ SERVER_IPADDR=$(hostname -I | awk '{ print $1 }') $ cat <<EOF | sudo tee /etc/dhcp/dhcpd.conf subnet 192.168.11.0 netmask 255.255.255.0 { option domain-name "hiroom2.com"; option domain-name-servers ${BIND_SERVER_IPADDR}; option routers 192.168.11.1; } host client { hardware ethernet 52:54:00:5e:7a:a4; fixed-address 192.168.11.250; option host-name "client.hiroom2.com"; } EOF
4 Run isc-dhcp-server
Run isc-dhpc-server with systemd.
$ sudo systemctl enable isc-dhcp-server $ sudo systemctl restart isc-dhcp-server
5 Execution result
Run the following command on client machine.
IP address is provided.
$ ip a s 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:5e:7a:a4 brd ff:ff:ff:ff:ff:ff inet 192.168.11.250/24 brd 192.168.11.255 scope global dynamic noprefixroute eth0 valid_lft 42938sec preferred_lft 42938sec inet6 fe80::3af3:7f8b:9205:2e03/64 scope link noprefixroute valid_lft forever preferred_lft forever
Hostname is provided.
$ hostname -f client.hiroom2.com
DNS server is provided.
$ cat /etc/resolv.conf # Generated by NetworkManager search hiroom2.com nameserver 192.168.11.82