linux---dhcp服务的配置

在虚拟机里安装dhcp配置之前需要挂载镜像

实验步骤:

1.[root@localhost ~]# yum search dhcp          ##查找dhcp

Loaded plugins: langpacks
============================== N/S matched: dhcp ===============================
dhcp-common.x86_64 : Common files used by ISC dhcp client and server
dhcp-libs.i686 : Shared libraries used by ISC dhcp client and server
dhcp-libs.x86_64 : Shared libraries used by ISC dhcp client and server
dhclient.x86_64 : Provides the ISC DHCP client daemon and dhclient-script
dhcp.x86_64 : Dynamic host configuration protocol software
dnsmasq.x86_64 : A lightweight DHCP/caching DNS server

  Name and summary matches only, use "search all" for everything.
2.[root@localhost ~]# yum install dhcp.x86_64 -y               ##安装dhcp安装包
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            source7.0         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!
3.[root@localhost ~]# cd /etc/dhcp/
4.[root@localhost dhcp]# ls
dhclient.d  dhcpd6.conf  dhcpd.conf
5.[root@localhost dhcp]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf##复制
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y           ##出现overwrite代表命令执行完毕,输入y=yes
6.[root@localhost dhcp]# ls
dhclient.d  dhcpd6.conf  dhcpd.conf

7.[root@localhost dhcp]# vim dhcpd.conf


(在这个文件里改7.8行内容,删除27.28行和34行以下的所有内容,改30-33的内容如下:

30 subnet 172.25.254.0 netmask 255.255.255.0 {             ##改网络位,子网掩码

31   range 172.25.254.200  172.25.254.210;                           ##动态dhcp网络的IP范围

32   option routers 192.168.0.1;                                             ##网关                  )
33 }


8.[root@localhost dhcp]# systemctl start dhcpd       ##开启dhcpd

9.[root@localhost dhcp]# systemctl enable dhcpd

10.[root@localhost dhcp]# systemctl restart network      ##重启网络

11.[root@localhost dhcp]# cat /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.2.5

lease 172.25.254.200 {
  starts 3 2018/04/25 09:56:47;
  ends 3 2018/04/25 10:06:47;
  tstp 3 2018/04/25 10:06:47;
  cltt 3 2018/04/25 09:56:47;
  binding state active;
  next binding state free;
  rewind binding state free;
  hardware ethernet 52:54:00:00:44:0a;
}
server-duid "\000\001\000\001\"s\006ZRT\000\000D\013";



分析:左边是Desktop虚拟机,右边是server虚拟机,在server虚拟机里安装dhcp的配置后用  “cat /var/lib/dhcpd/dhcpd.leases”查看 hardware ethernet ,重置Desktop虚拟机后,用ifconfig查看ether是否相同,inet是否在你设定的IP范围之内。

猜你喜欢

转载自blog.csdn.net/argued_d/article/details/80082833
今日推荐