虚拟主机A部署dhcp服务
步骤一:安装dhcp服务
[root@a ~]# yum -y install dhcp
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
软件包 12:dhcp-4.2.5-42.el7.x86_64 已安装并且是最新版本
无须任何处理
步骤二:修改配置文件
[root@a ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.4.0 netmask 255.255.255.0 { #分配IP段
range 192.168.4.200 192.168.4.202; #地址池
option domain-name-servers 8.8.8.8; #dns
option routers 192.168.4.254; #网关
default-lease-time 600; #签约时间
max-lease-time 7200;
步骤三:重启服务
[root@a ~]# systemctl restart dhcpd
[root@a ~]# systemctl enable dhcpd
步骤四:虚拟机B验证
[root@b ~]# nmcli connection modify eth0 ipv4.method auto #自动获取IP和网关
[root@b ~]# nmcli connection up eth0 #激活eth0
成功激活的连接(D-Bus 激活路径:/org/freedesktop/NetworkManager/ActiveConnection/3)
[root@b ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.4.200 netmask 255.255.255.0 broadcast 192.168.4.255
inet6 fe80::5652:4ff:fe09:a01 prefixlen 64 scopeid 0x20<link>
- 查看网关命令
[root@b ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.4.254 0.0.0.0 UG 100 0 0 eth0
192.168.4.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0