实验环境
主机名称 | 操作系统 | IP地址 | 网络连接方式 |
---|---|---|---|
Server | CentOS 7.5 | ens33:192.168.200.10 | vnet8 |
Client1 | CentOS 7.5 | DHCP分配(动态获取) | vnet8 |
Client2 | CentOS 7.5 | DHCP分配(动态获取) | vnet8 |
###建议:
###测试前,先关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]# setenforce 0
一、【物理机】关闭Vnet1和Vnet8的DHCP功能
二、【Server】配置静态IP地址
2.1 配置静态IP地址
-
配置ens33网卡
[root@server ~]# cd /etc/sysconfig/network-scripts/
[root@server network-scripts]# vim ifcfg-ens33
配置内容如下
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens33
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
IPADDR=192.168.200.10
NETMASK=255.255.255.0
GATEWAY=192.168.200.2
DNS1=114.114.114.114
2.2 测试网络
192.168.200.2为VM NAT网关地址。
[root@server ~]# ping 192.168.200.2 -c3
PING 192.168.200.2 (192.168.200.2) 56(84) bytes of data.
64 bytes from 192.168.200.2: icmp_seq=1 ttl=128 time=0.245 ms
64 bytes from 192.168.200.2: icmp_seq=2 ttl=128 time=0.713 ms
64 bytes from 192.168.200.2: icmp_seq=3 ttl=128 time=0.256 ms
--- 192.168.200.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 0.245/0.404/0.713/0.219 ms
三、【Server】安装DHCP服务器
[root@server ~]# yum install dhcp -y
四、【Server】编辑配置文件/etc/dhcp/dhcpd.conf
[root@server ~]# vim /etc/dhcp/dhcpd.conf
4.1 DHCP配置
ddns-update-style none;
ignore client-updates;
shared-network superscope {
option domain-name "test.org";
default-lease-time 21600;
max-lease-time 43200;
subnet 192.168.200.0 netmask 255.255.255.0{
option routers 192.168.200.2;
option domain-name-servers 192.168.200.2;
range dynamic-bootp 192.168.200.200 192.168.200.200;
}
subnet 192.168.100.0 netmask 255.255.255.0{
option routers 192.168.100.1;
option domain-name-servers 114.114.114.114;
range dynamic-bootp 192.168.100.100 192.168.100.100;
}
}
4.2 重启dhcp服务
[root@server ~]# systemctl restart dhcpd
[root@server ~]# systemctl enable dhcpd
-
说明:在配置dhcp时,一定要小心,如若出现语法错误、输入错误,DHCP将无法启动。
五、客户端测试
5.1 【Client1】上测试
5.2 【Client2】上测试