您好,登錄后才能下訂單哦!
首先我的環境是在本地的VMware虛擬機,所以先將VMware中的dhcp服務關閉
關閉防火墻,關閉selinux這些必須關閉:
systemctl stop firewalld
setenforce 0
在centos8上安裝dhcp-server端
[root@Centos8 ~]#yum install dhcp-server.x86_64
查看安裝的包和文件
[root@Centos8 ~]#rpm -ql dhcp-server
/etc/NetworkManager
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/12-dhcpd
/etc/dhcp #客戶端
/etc/dhcp/dhcpd.conf #dhcp配置文件(空文件)
/etc/dhcp/dhcpd6.conf #ipv6配置文件
/etc/openldap/schema
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/usr/bin/omshell
/usr/lib/.build-id
/usr/lib/.build-id/61
/usr/lib/.build-id/61/6771248bc042fe96877bd9496ad99a4a4817fc
/usr/lib/.build-id/e0
/usr/lib/.build-id/e0/17e374d1a55a7254398988114fdd6a0bd63df3
/usr/lib/systemd/system/dhcpd.service
/usr/lib/systemd/system/dhcpd6.service
/usr/sbin/dhcpd #服務器端
/usr/share/doc/dhcp-server
/usr/share/doc/dhcp-server/dhcp-lease-list.pl
/usr/share/doc/dhcp-server/dhcpd.conf.example #配置文件范例
/usr/share/doc/dhcp-server/dhcpd6.conf.example
/usr/share/doc/dhcp-server/ldap
/usr/share/doc/dhcp-server/ldap/README.ldap
/usr/share/doc/dhcp-server/ldap/dhcp.schema
/usr/share/doc/dhcp-server/ldap/dhcpd-conf-to-ldap
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases #地址分配記錄
/var/lib/dhcpd/dhcpd6.leases
[root@Centos8 ~]#
然后啟動dhcp服務
[root@Centos8 ~]#systemctl start dhcpd.service
發現啟動報錯,是因為dhcp如果沒有配置本網段的dhcp規則是拒絕啟動的。
查看配置文件:
[root@Centos8 ~]#vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp-server/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
dhcp默認配置文件是空的,但是它說了看/usr/share/doc/dhcp-server/dhcpd.conf.example這個文件,這個是dhcp配置的一些范例。
[root@Centos8 ~]#cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
直接替換配置文件,再次查看:
[root@Centos8 ~]#vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
#其中全局語句塊和subnet語句塊均可使配置生效,subnet語句塊優先級高于全局語句塊:
#全局語句塊:
# option definitions common to all supported networks...
#指定獲取主機域后綴:
option domain-name "wj02.com";
#指定DNS,可選
option domain-name-servers 180.76.76.76, 119.29.29.29;
#ip的租期,單位:秒
default-lease-time 86400; #默認是600s,客戶端會在租期的一半也就是300s后進行續租,組曲太短會占用大量的網絡帶寬,建議改時間長一點。這里修改為86400s,一天。
#最大租期時間
max-lease-time 100000;
...
log-facility local7;
...
#subnet配置
#指定網段
subnet 192.168.38.0 netmask 255.255.255.0 {
#指定分配的ip范圍,可以跳過一些地址
range 192.168.38.10 192.168.38.120;
range 192.168.38.150 192.168.38.254;
#指定網關
option routers 192.168.38.2;
}
#為一個mac地址分配一個固定的ip,效果等同于靜態獲取
host test {
hardware ethernet 00:0c:29:58:4f:12;
fixed-address 192.168.39.102;
}
#為00:0c:29:58:4f:12這個mac地址固定的分配192.168.39.120這個地址
......
dhcp還有語法檢查功能:
dhcpd -t -cf /etc/dhcp/dhcpd.conf
當然如果語法不對,啟動也會報錯的,這個其實不重要。
配置文件修改完畢后,重新啟動dhcp服務
[root@Centos8 ~]#systemctl start dhcpd
啟動成功。
在客戶端獲取ip
dhclient –d
因為配置文件里我綁定了mac地址,所以這個服務器應該分配到192.168.38.102這個ip
至此,dhcp服務器搭建成功。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。