Linux中dhcp服务器的配置

dhcp服务的配置:

   在一台虚拟机(客户端)发送数据包,将IP范围内的地址随机分给另外一台虚拟机,接收后可使用ifconfig命令查看是否在范围之内。本次实验使用两台虚拟机:我们通过真机连接Desktop虚拟机进行发送:

[kiosk@foundation21 Desktop]$ ssh [email protected] 切换到超级用户

[email protected]'s password:

Last login: Fri Apr 20 21:53:19 2018 from foundation22.ilt.example.com

[root@localhost ~]# yum search dhcp    

Loaded plugins: langpacks

Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast

============================== 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.

***记住安装dhcp时候需要进行yum源的搭建与共享,不然都无法安装dhcp更加没办法进行配置。点击打开链接,这个链接里面为我自己写的yum源的搭建与共享,一步步按照来即可。

[root@localhost ~]# yum install dhcp.x86_64 -y   在Desktop安装dhcp安装包


[root@localhost ~]# cd /etc/dhcp/  

[root@localhost dhcp]# ls

dhclient.d  dhcpd6.conf  dhcpd.conf

[root@localhost dhcp]# vim dhcpd.conf  编辑文件,将文件内容复制

Try 'cp --help' for more information.

[root@localhost dhcp]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf  复制

cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y   出现overwrite代表命令好了

[root@localhost dhcp]# ls

dhclient.d  dhcpd6.conf  dhcpd.conf

[root@localhost dhcp]# vim dhcpd.conf

文件内容如下:34行以后删除,27,28行删除,其它内容按照图片修改即可。



[root@localhost dhcp]# systemctl start dhcpd  打开dhcpd

[root@localhost dhcp]# systemctl enable dhcpd

ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service'


[root@localhost dhcp]# cat /var/lib/dhcpd/dhcpd.leases  查看与另外一台机子里面查看的ifconfig对比看是否相同

# 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

server-duid "\000\001\000\001\"mYvRT\000\000\025\012";

 lease 172.25.254.207 {

  starts 6 2018/04/21 02:09:07;

  ends 6 2018/04/21 02:19:07;

  cltt 6 2018/04/21 02:09:07;

  binding state active;

  next binding state free;

  rewind binding state free;

  hardware ethernet 00:21:cc:5e:3f:1e;   对照文件

  uid "\001\000!\314^?\036";

  client-hostname "L3-A17229";

}


[root@localhost dhcp]# systemctl stop dhcpd

然后重置server拔网线进去查看ifconfig,对照相应的MAC值,相同的话DHCP即配置成功。


猜你喜欢

转载自blog.csdn.net/aaaaaab_/article/details/80106300