使用两台虚拟机,一台server端作为dhcp的服务器,另一台desktop作为dhcp的客户端。
配置server端的ip和dns
yum install dhcp -y
[root@foundation74 etc]# cd dhcp/
[root@foundation36 dhcp]# ls
dhclient.d dhcpd6.conf dhcpd.conf
vim /etc/sysconfig/network //配置网关
GATEWAY=真机的ip
cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
vim /etc/dhcp/dhcpd.conf 修改dhcpd.conf
# dhcpd.conf
# #
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "westos.com"; ##域名
option domain-name-servers 114.114.114.114; ##dns
default-lease-time 600; ##默认租约
max-lease-time 7200; ##最长租约
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
#Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
27 删除
28 删除
# This is a very basic subnet declaration.
subnet 172.25.254.0 netmask 255.255.255.0 { ##网络号
range 172.25.254.126 172.25.254.200; ##IP地址池范围
option routers 172.25.254.26; ##网关
}
35-最后 全删除 然后保存
systemctl restart dhcpd 重启dhcp服务
dhcp服务已完成。
现在转到desktop虚拟机,让虚拟机自动获取i
systemctl stop firewalld 关闭防火墙
nm-connection-editor 设置为dhcp模式
ip是服务器分配的第一个,网关和上面服务器设置的相同
[root@localhost Desktop]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.25.254.136 netmask 255.255.255.0 broadcast 172.25.254.255
inet6 fe80::5054:ff:fe00:240a prefixlen 64 scopeid 0x20<link>
ether 52:54:00:00:24:0a txqueuelen 1000 (Ethernet)
RX packets 222203 bytes 3762566728 (3.5 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 122798 bytes 8355140 (7.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost Desktop]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.25.254.36 0.0.0.0 UG 1024 0 0 eth0
网友评论