1. install software ##安装软件
[root@server ~]# yum install dhcp -y
Loaded plugins: langpacks
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================
Package Arch Version Repository Size
==============================================================================
Installing:
dhcp x86_64 12:4.2.5-27.el7 rhel_dvd 506 k
Transaction Summary
==============================================================================
Install 1 Package
Total download size: 506 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-27.el7.x86_64.rpm | 506 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 12:dhcp-4.2.5-27.el7.x86_64 1/1
Verifying : 12:dhcp-4.2.5-27.el7.x86_64 1/1
Installed:
dhcp.x86_64 12:4.2.5-27.el7
Complete!
[root@server ~]# systemctl start dhcpd
2.建立配置文件
[root@server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@server ~]# vim /etc/dhcp/dhcpd.conf ##删除27 28 行,再将36行之后的都删掉,再进行如下修改
7 option domain-name "westos.com";
8 option domain-name-servers 172.25.254.20;
14 ddns-update-style interim;
30 subnet 172.25.254.0 netmask 255.255.255.0 {
31 range 172.25.254.100 172.25.254.110;
32 option routers 172.25.254.250;
33 }
34 key westoskey { ##man dhcpd.conf /key 按n依次找可以找到加密的模板
35 algorithm hmac-md5;
36 secret Xa89tXXrn4XmfAyK3OsWKk9BnKcPF10UE6dxJMXMa7I=;
37 };
38
39 zone westos.com. {
40 primary 127.0.0.1; ##回环接口
41 key westoskey;
[root@server ~]# vim /etc/named.conf
view localnet{
match-clients { 172.25.254.48/24; 127.0.0.1; }; ##修改
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
};
3.check
拔掉网线
在client
[root@client ~]# hostnamectl set-hostname test.westos.com
[root@client ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
[root@client ~]# systemctl restart network
[root@client ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.100 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::5054:ff:fe00:300a prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:30:0a txqueuelen 1000 (Ethernet)
RX packets 20896 bytes 1198493 (1.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15853 bytes 920492 (898.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@client ~]# vim /etc/resolv.conf
# Generated by NetworkManager
domain westos.com
search westos.com
nameserver 172.25.254.20
[root@client ~]# dig test.westos.com
; <<>> DiG 9.9.4-RedHat-9.9.4-14.el7 <<>> test.westos.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46209
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;test.westos.com. IN A
;; ANSWER SECTION:
test.westos.com. 300 IN A 172.25.254.100
;; AUTHORITY SECTION:
westos.com. 86400 IN NS dns.westos.com.
;; ADDITIONAL SECTION:
dns.westos.com. 86400 IN A 172.25.254.20
;; Query time: 0 msec
;; SERVER: 172.25.254.20#53(172.25.254.20)
;; WHEN: Tue May 09 08:41:50 EDT 2017
;; MSG SIZE rcvd: 94
4.如果遇到实验结果不是预期,具体的查看流程如下
1.需要关闭真机dhcp
2.开启server的dhcp
3.关闭server和desktop的防火墙
4.在server里查看日志
5.查看desktop的/etc/resolv.cong,是否指向server ip