一、基本功能搭建(服务器+ 客户机)
服务器端
$ yum -y install dhcp
$ cp -a /usr/share/doc/dhcp-4.*.*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
$ vim /etc/dhcp/dhcpd.confsubnet 192.168.66.0 netmask 255.255.255.0{range 192.168.66.3 192.168.66.254; option domain-name-servers 8.8.8.8; option domain-name "kernel.com";option routers 192.168.66.1; option broadcast-address 192.168.66.255; default-lease-time 600; max-lease-time 7200;}
$ systemctl start dhcpd
$ ss -antup | grep dhcp
$ ps aux | grep dhcp
客户端
$ vim /etc/sysconfig/network-scripts/ifcfg-eth0BOOTPROTO=dhcp去掉IPADDR、NETWORK等
$ systemctl restart network
或:ifdown ens33;ifup ens33;
$ ip addr
$ route -n
$ cat /etc/resolv.conf
二、保留地址实验(服务器+ 客户机)
服务器端
$ vim /etc/dhcp/dhcpd.confsubnet 192.168.66.0 netmask 255.255.255.0{range 192.168.66.3 192.168.66.254; option routers 192.168.66.1; }host fantasia{hardware ethernet mac地址;fixed-address IP地址; }host fantasia1{hardware ethernet mac地址;fixed-address IP地址; }
$ systemctl restart dhcpd
$ cat /var/lib/dhcpd/dhcpd.leases
客户端
$ vim /etc/sysconfig/network-scripts/ifcfg-eth0BOOTPROTO=dhcp去掉IPADDR、NETWORK等
$ systemctl restart network
或:ifdown ens33;ifup ens33;
$ ip addr
三、超级作用域实验(服务器和路由器+ 客户机1+客户机2)
网络配置
dhcp服务器:vmnet1ens33 :192.168.66.100ens33:0 :192.168.77.100
客户机1:vmnet1ens33 : 自动获取
客户机2:vmnet1ens33 : 自动获取
DHCP服务器和路由器
$ cd /etc/sysconfig/network-scripts
$ cp -a ifcfg-ens33 ifcfg-ens33:0
$ vim ifcfg-ens33BOOTPROTO=staticIPADDR=192.168.66.100PREFIX=24
$ vim ifcfg-ens33:0NAME=ens33:0DEVICE=ens33:0BOOTPROTO=staticIPADDR=192.168.77.100PREFIX=24
$ systemctl restart network
$ vim /etc/dhcp/dhcpd.confshared-network public {subnet 192.168.66.0 netmask 255.255.255.0{range 192.168.66.200 192.168.66.200;}subnet 192.168.77.0 netmask 255.255.255.0{range 192.168.77.110 192.168.77.120;}}
$ systemctl restart dhcpd--------------------------------------------
$ vim /etc/sysctl.confnet.ipv4.ip_forward=1
$ sysctl -p
------------------------------
$ vim /usr/lib/sysctl.d/50-default.confnet.ipv4.conf.default.ip_forward = 1net.ipv4.conf.all.ip_forward = 1
$ reboot
$ vim /etc/dhcp/dhcpd.confshared-network public {subnet 192.168.66.0 netmask 255.255.255.0{option routers 192.168.66.100; range 192.168.66.200 192.168.66.200;}subnet 192.168.77.0 netmask 255.255.255.0{option routers 192.168.77.100; range 192.168.77.110 192.168.77.120;}}
$ systemctl restart dhcpd
两台客户机重启网卡
$ vim /etc/sysconfig/network-scripts/ifcfg-ens33BOOTPROTO=dhcp去掉IPADDR、NETWORK等
$ systemctl restart network
或:ifdown ens33;ifup ens33;
$ ip addr
四、DHCP中继实验(DHCP服务器+DHCP中继和路由器+客户机)
网络设置
DHCP服务器:vmnet1ens33 : 192.168.66.77,网关为中继服务器上同网段的IP
DHCP中继器:ens33 :vmnet1, 192.168.66.100ens34 :vmnet2, 192.168.88.100
客户机:vmnet2ens33 : 自动获取
DHCP服务器
$ vim /etc/sysconfig/network-scripts/ifcfg-ens33BOOTPROTO=staticIPADDR=192.168.66.77PREFIX=24GATEWAY=192.168.66.100
$ systemctl restart network
$ vim /etc/dhcp/dhcpd.confsubnet 192.168.66.0 netmask 255.255.255.0{range 192.168.66.110 192.168.66.120;}subnet 192.168.88.0 netmask 255.255.255.0{range 192.168.88.110 192.168.88.120;}
$ systemctl restart dhcpd
DHCP中继服务器
$ vim /etc/sysconfig/network-scripts/ifcfg-ens33BOOTPROTO=staticIPADDR=192.168.66.100PREFIX=24
$ vim /etc/sysconfig/network-scripts/ifcfg-ens34BOOTPROTO=staticIPADDR=192.168.88.100PREFIX=24
$ systemctl restart network
$ yum -y install dhcp
$ dhcrelay DHCP服务器IP
$ ss -tulnp | grep dhcrelay -------------------------------
客户机
$ vim /etc/sysconfig/network-scripts/ifcfg-ens33BOOTPROTO=dhcp去掉IPADDR、NETWORK等
$ systemctl restart network
或:ifdown ens33;ifup ens33;
$ ip addr