Linux部署dhcp (照做就行)
作者:互联网
大家好,今天来跟大家分享一下centos7如何快速安装DHCP服务
DHCP的意思就是动态主机配置协议。作用在于为局域网内的主机自动提供地址。这样的话。省去了手工配置的过程。避免了手工配置可能发生的错误。同时有效的提高工作效率,这些都是他的好处。
这里我们使用自己的内网静态ip
[root@localhost yum.repos.d]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.75.10 netmask 255.255.255.0 broadcast 192.168.75.255
inet6 fe80::5f9c:18cd:8c82:9cc8 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:1a:26:9c txqueuelen 1000 (Ethernet)
RX packets 1400 bytes 111205 (108.5 KiB)
RX errors 0 dropped 4 overruns 0 frame 0
TX packets 364 bytes 40052 (39.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
1.把光盘连接到桌面
[root@localhost ~]# mkdir /media/cdrom
[root@localhost ~]# mount /dev/cdrom /media/cdrom/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]#
[root@localhost ~]# rpm -ivh /media/cdrom/Packages/dhcp-4.2.5-68.el7.centos.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:dhcp-12:4.2.5-68.el7.centos ################################# [100%]
[root@localhost ~]# //安装DHCP服务
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
# //这是dhcp的配置文件
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost ~]# //把dhcp的配置文件的模板复制到dhcp.conf文件里 y (表示覆盖)
[root@localhost ~]# cd /etc/dhcp/
[root@localhost dhcp]# ls
dhclient.d dhclient-exit-hooks.d dhcpd6.conf dhcpd.conf scripts
[root@localhost dhcp]# //查看一下
[root@localhost ~]# cp /etc/dhcp/dhcpd.conf /opt/ //做备份
[root@localhost ~]# grep -v "^#" /etc/dhcp/dhcpd.conf > /etc/dhcp/dhcpd.conf.bak
[root@localhost ~]#
//将/etc/dhcp/dhcpd.conf文件中的以#开头的行给过滤掉,导入到一个名叫/etc/dhcp/dhcpd.bak文件当中
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf.bak //编辑这个文件
host passacaglia {
hardware ethernet 0:0:c0:5d:bd:95;
filename "vmunix.passacaglia";
server-name "toccata.fugue.com";
}
host fantasia {
hardware ethernet 08:00:07:26:c0:a5;
fixed-address fantasia.fugue.com;
}
class "foo" {
match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}
shared-network 224-29 {
subnet 10.17.224.0 netmask 255.255.255.0 {
option routers rtr-224.example.org;
}
subnet 10.0.29.0 netmask 255.255.255.0 {
option routers rtr-29.example.org;
}
pool {
allow members of "foo";
range 10.17.224.10 10.17.224.250;
}
pool {
deny members of "foo";
range 10.0.29.10 10.0.29.230;
}
}
"/etc/dhcp/dhcpd.conf.bak" 71L, 1508C // 这些都是它原来的配置文件
subnet 192.168.75.0 netmask 255.255.255.0 { //地址段,掩码
range 192.168.75.20 192.168.75.30; //地址范围
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1;
option broadcast-address 10.5.5.31;
default-lease-time 600;
max-lease-time 7200; 配置这一段,根据现实情况
}
保持退出
[root@localhost ~]# cd /etc/dhcp/
[root@localhost dhcp]# ls
dhclient.d dhclient-exit-hooks.d dhcpd6.conf dhcpd.conf dhcpd.conf.bak scripts
[root@localhost dhcp]#
[root@localhost dhcp]# mv dhcpd.conf.bak dhcpd.conf
mv:是否覆盖"dhcpd.conf"? y
[root@localhost ~]# systemctl start dhcpd //开启范围
[root@localhost ~]# systemctl start dhcpd
dhcpd6.service dhcpd.service
[root@localhost ~]# systemctl start dhcpd
[root@localhost ~]# systemctl status dhcpd //状态正常
● dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
Active: active (running) since 六 2021-10-30 13:22:56 CST; 48s ago
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 5374 (dhcpd)
Status: "Dispatching packets..."
Tasks: 1
CGroup: /system.slice/dhcpd.service
└─5374 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: No subnet declaration for virbr0 (192.168.122.1).
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: ** Ignoring requests on virbr0. If this is not what
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: you want, please write a subnet declaration
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: in your dhcpd.conf file for the network segment
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: to which interface virbr0 is attached. **
10月 30 13:22:56 localhost.localdomain dhcpd[5374]:
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: Listening on LPF/ens33/00:0c:29:1a:26:9c/192.168.75.0/24
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: Sending on LPF/ens33/00:0c:29:1a:26:9c/192.168.75.0/24
10月 30 13:22:56 localhost.localdomain dhcpd[5374]: Sending on Socket/fallback/fallback-net
10月 30 13:22:56 localhost.localdomain systemd[1]: Started DHCPv4 Server Daemon.
在Windows上任务管理器上禁用VMwarework dhcp 以及VMwarework nat
[root@localhost ~]# systemctl stop firewalld.service //关闭防火墙
接着在客户机上测试
以太网适配器 VMware Network Adapter VMnet1:
连接特定的 DNS 后缀 . . . . . . . : internal.example.org
本地链接 IPv6 地址. . . . . . . . : fe80::101e:e033:f882:a919%14
IPv4 地址 . . . . . . . . . . . . : 192.168.75.20
子网掩码 . . . . . . . . . . . . : 255.255.255.0
实验完成
标签:conf,部署,etc,dhcpd,Linux,dhcp,root,localhost 来源: https://www.cnblogs.com/jishusicheng/p/15484898.html