VM配置centos7 DHCP服务器步骤(linux系统)

VM配置DHCP步骤

一、服务器配置

1.配置网络。

[root@centos7-1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=9f92031e-cb20-4cde-b796-6935a082ba86 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.10.1 NETMASK=255.255.255.0 GATEWAY=192.168.10.254 DNS1=192.168.10.1
[root@centos7-1 ~]# systemctl restart network //重启网络 [root@centos7-1 ~]# ip add //查看并检查配置的网络

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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

link/ether 00:0c:29:54:15:b6 brd ff:ff:ff:ff:ff:ff

inet 192.168.10.1/24 brd 192.168.10.255 scope global noprefixroute ens33

valid_lft forever preferred_lft forever

inet6 fe80::1ff8:ec83:f031:9ce7/64 scope link noprefixroute

valid_lft forever preferred_lft forever

3: ens36: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

link/ether 00:0c:29:54:15:c0 brd ff:ff:ff:ff:ff:ff

4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000

link/ether 52:54:00:4d:8b:42 brd ff:ff:ff:ff:ff:ff

inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0

valid_lft forever preferred_lft forever

5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000

link/ether 52:54:00:4d:8b:42 brd ff:ff:ff:ff:ff:ff

2.检测系统是否已经安装了DHCP相关软件。

[root@centos7-1 ~]# rpm -qa | grep dhcp

dhcp-libs-4.2.5-83.el7.centos.1.x86_64

dhcp-common-4.2.5-83.el7.centos.1.x86_64

[root@centos7-1 ~]# mkdir /opt/centos //创建目录/opt/centos [root@centos7-1 ~]# mount /dev/cdrom /opt/centos //挂载光盘到/opt/centos 下 mount: /dev/sr0 写保护,将以只读方式挂载 [root@centos7-1 ~]# mv /etc/yum.repos.d/* /home //移动文件到/home下

3.制作用于安装的yum 源文件。

[root@centos7-1 ~]# vim /etc/yum.repos.d/local.repo [centos] name=centos baseurl=file:///opt/centos gpgcheck=0 enabled=1

4.使用yum命令查看dhcp 软件包的信息

[root@centos7-1 ~]# yum info dhcp

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

centos | 3.6 kB 00:00

(1/2): centos/group_gz | 166 kB 00:00

(2/2): centos/primary_db | 3.1 MB 00:00

可安装的软件包

名称 :dhcp

架构 :x86_64

时期 :12

版本 :4.2.5

发布 :68.el7.centos.1

大小 :513 k

源 :centos

简介 : Dynamic host configuration protocol software

网址 :http://isc.org/products/DHCP/

协议 : ISC

描述 : DHCP (Dynamic Host Configuration Protocol) is a protocol which allows

: individual devices on an IP network to get their own network

: configuration information (IP address, subnetmask, broadcast address,

: etc.) from a DHCP server. The overall purpose of DHCP is to make it

: easier to administer a large network.

:

: To use DHCP on your network, install a DHCP service (or relay agent),

: and on clients run a DHCP client daemon. The dhcp package provides

: the ISC DHCP service and relay agent.

5.查看yum状态

[root@centos7-1 ~]# yum repolist

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

源标识 源名称 状态

centos centos 4,021

repolist: 4,021

[root@centos7-1 ~]# yum clean all //安装前先清除缓存

已加载插件:fastestmirror, langpacks

正在清理软件源: centos

Cleaning up list of fastest mirrors

Other repos take up 454 M of disk space (use –verbose for details)

6.安装dhcp

[root@centos7-1 ~]#yum install dhcp -y

已加载插件:fastestmirror, langpacks

Determining fastest mirrors

centos | 3.6 kB 00:00:00

(1/2): centos/group_gz | 153 kB 00:00:00

(2/2): centos/primary_db | 3.3 MB 00:00:00

正在解决依赖关系

–> 正在检查事务

—> 软件包 dhcp.x86_64.12.4.2.5-83.el7.centos.1 将被 安装

–> 解决依赖关系完成

依赖关系解决

=======================================================================================

Package 架构 版本 源 大小

=======================================================================================

正在安装:

dhcp x86_64 12:4.2.5-83.el7.centos.1 centos 515 k

事务概要

=======================================================================================

安装 1 软件包

总下载量:515 k

安装大小:1.4 M

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

正在安装 : 12:dhcp-4.2.5-83.el7.centos.1.x86_64 1/1

验证中 : 12:dhcp-4.2.5-83.el7.centos.1.x86_64 1/1

已安装:

dhcp.x86_64 12:4.2.5-83.el7.centos.1

完毕!

7.软件包安装完毕,可以使用rpm命令再一次进行查询

[root@centos7-1 ~]#rpm -qa |grep dhcp

dhcp-libs-4.2.5-83.el7.centos.1.x86_64

dhcp-common-4.2.5-83.el7.centos.1.x86_64

dhcp-4.2.5-83.el7.centos.1.x86_64

8.配置dhcp主配置

[root@centos7-1 ~]#vim /etc/dhcp/dhcpd.conf ddns-update-style none; log-facility local7; subnet 192.168.10.0 netmask 255.255.255.0 { range 192.168.10.31 192.168.10.104; range 192.168.10.106 192.168.10.106; range 192.168.10.108 192.168.10.200; option domain-name-servers 192.168.10.1; #option domain-name "myDHCP.smile.com"; //可用可不用,用的话得有dns option routers 192.168.10.254; option broadcast-address 192.168.10.255; default-lease-time 6a00; max-lease-time 720; } host Client2{ hardware ethernet 00:0C:29:7A:0B:0E; //客户机指定的网卡地址 fixed-address 192.168.10.105; }

9.配置完成保存并退出,重启 dhcpd 服务,并设置开机自动启动

[root@centos7-1 ~]#systemctl restart dhcpd //重启dhcp [root@centos7-1 ~]#sysemctl enable dhcpd //开机自启动

Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd,service to /usr/lib/systemd/system/dhcpd.service.

二、在客户端Client1 上进行测试

因为使用的是VM, 在VMWare 主窗口中,依次打开“编辑”→“虚拟网络编辑器”,打开“虚拟网络编辑器”窗口,选中VMnetl 或 VMnet8,去掉对应的DHCP服务启用选项,如图所示

VM配置centos7 DHCP服务器步骤(linux系统)插图

1.以root用户身份登录名为Clientl的Linux计算机,依次单击“应用程序"→"系统工具”→“设置"→“网络",打开“网络”对话框,如图所示。

VM配置centos7 DHCP服务器步骤(linux系统)插图1

VM配置centos7 DHCP服务器步骤(linux系统)插图2

VM配置centos7 DHCP服务器步骤(linux系统)插图3

2.在图1-5弹出的“有线”对话框架中单击“IPv4”选项,并将“IPv4 Method选项配置为“自动(DHCP)”,最后单击“Apply”(应用)按钮,如图所示。

VM配置centos7 DHCP服务器步骤(linux系统)插图4

3.在下图中先选择“关闭"关闭“有线",再选择“打开”打开“有线”。这时会看到下图所示的结果:Clientl 成功获取到了 DHCP服务器地址池的一个地址。VM配置centos7 DHCP服务器步骤(linux系统)插图5

VM配置centos7 DHCP服务器步骤(linux系统)插图6

三、在客户端Client2 上进行测试
同样以root 用户身份登录名为 Client2 的 Linux计算机,按上面“4.在客户端Clientl上进行测试”的方法,设置Client自动获取IP地址,最后的结果如图所示。

VM配置centos7 DHCP服务器步骤(linux系统)插图7

注意:利用网络卡配置文件也可设置使用 DHCP服务器获取IP地址。在该配置文件中,"IPADDR=192.168.1.1,PREFIX=24,NETMASK=255.255.255.0、HWADDR=00:0C:29:A2:BA:98"等条目删除,将“BOOTPROTO=none”改为“BOOTPROTO=dhcp”。设置完成,一定要重启网络管理服务。

四.Windows 客户端配置
(1)Windows 客户端比较简单,在TCP/IP属性中设置自动获取就可以。
(2)在 Windows 命令提示符下,利用ipconfig可以释放IP地址后,重新获取IP地址。相关命令如下。
释放IP地址:ipconfig /release。

重新申请IP地址:ipconfig /renew。

原文链接:https://blog.csdn.net/m0_63624418/article/details/128089741?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168525635616800213086355%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168525635616800213086355&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-5-128089741-null-null.268%5Ev1%5Econtrol&utm_term=NAS%E3%80%81%E7%BE%A4%E6%99%96%E3%80%81%E9%98%BF%E9%87%8C%E4%BA%91%E3%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90%E3%80%81%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E3%80%81ipv6%E3%80%81ddns%E3%80%81%E8%BD%BB%E9%87%8F%E7%BA%A7%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E9%93%81%E5%A8%81%E9%A9%AC%E3%80%81%E5%A8%81%E8%81%94%E9%80%9A%E3%80%81DSM%E3%80%81DSM6.0%E3%80%81%E7%BE%A4%E6%99%96nas%E3%80%81%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E8%9C%97%E7%89%9B%E6%98%9F%E9%99%85%E3%80%81%E9%BB%91%E7%BE%A4%E6%99%96%E3%80%81docker%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81%E5%9F%9F%E5%90%8D%E6%B3%A8%E5%86%8C%E3%80%81%E5%AE%9D%E5%A1%94%E3%80%81%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E3%80%81nginx%E3%80%81frp%E3%80%81%E5%8A%A8%E6%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享