DHCP service in Linux environment (Linux that Xiaobai can understand)

1. The concept of DHCP

Hyperlink DHCP concept

Two, install the DHCP server

1. Configure DHCP relay in ensp

dhcp enable									#开启DHCP功能

interface Vlanif10
 ip address 192.168.10.254 255.255.255.0
 dhcp select relay							#开启DHCP中继功能
 dhcp relay server-ip 192.168.100.253			#指向DHCP服务器的地址

interface Vlanif20
 ip address 192.168.20.254 255.255.255.0
 dhcp select relay
 dhcp relay server-ip 192.168.100.253

interface Vlanif100
 ip address 192.168.100.254 255.255.255.0
 dhcp select relay
 dhcp relay server-ip 192.168.100.253

2. Configure the DHCP server

  • Dhcp-4.2.5-58.el7.centos.x86_64.rpm in the CentOS 7 CD
  • Main files of the DHCP software package
    Main configuration file: /etc//dhcp/dhcpd.conf
    Executive program: /usr/sbin/dhcpd, /usr/sbin/dhcrelay
yum install -y dhcp
cat /etc/dhcp/dhcpd.conf    #查看主配置文件
cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example  #查看示例配置文件

3. Configure the content of the main configuration file


 
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
      /etc/dhcp/dhcpd.conf
      
      vim /etc/dhcp/dhcpd.conf   #设置全局配置参数 default-lease-time 600;	
      #默认租约为 10分钟,单位为秒 max-lease-time 7200;	 #最大租约为 1 小时,单位为秒 option domain-name "example.org";  #指定默认域名 option domain-name-servers
      8.8.8.8; #指定 DNS 服务器地址 ddns-update-style none;  #禁用 DNS 动态更新
      
      #subnet网段声明(作用于整个子网段,部分配置参数优先级高于全局配置参数) subnet 192.168.100.0 netmask 255.255.255.0 {    	#声明要分配的网段地址    range 192.168.100.1
      192.168.100.128;     #设置地址池   option routers 192.168.100.254;      #指定默认网关地址 } subnet 192.168.10.0 netmask 255.255.255.0 {   range 192.168.10.1 192.168.10.128;   option routers 192.168.10.254; } subnet 192.168.20.0 netmask 255.255.255.0 {   range 192.168.20.1
      192.168.20.128;   option routers 192.168.20.254; }
      
      #host主机声明(给单机分配固定的 IP 地址) host hostname {										#指定需要分配固定 IP地址的客户机名称   hardware ethernet 00:c0:c3:22:46:81;				#指定该主机的
      MAC地址   fixed-address 192.168.10.100;						#指定保留给该主机的 IP地址 }
      
      #后面内容可都删除
      
      #关上防火墙 systemctl start dhcpd systemctl stop firewalld setenforce 0
      
      netstat -anpu | grep ":67"
      
      #如果DHCP服务启动失败,可以查看日志文件 tail -f /var/log/messages

4. The Linux client uses DHCP to dynamically obtain IP

#方法一:
vim /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
ONBOOT=yes
BOOTPROTO=dhcp

ifdown ens33 ; ifup ens33

#方法二:
dhclient -d ens33

查看租约文件 
less /var/lib/dhcpd/dhcpd.lease

Three, DHCP experiment example

1) ensp configuration

Insert picture description here
1. Cloud1 settings in ensp

Insert picture description here
2.sw1 configuration
Insert picture description here
3.sw2 configuration
Insert picture description here

Network Configuration

1) Cloud server configuration
Here you must first set up your own virtual network card. Some may have their own DHCP service, which needs to be turned off, otherwise there will be conflicts.
Insert picture description here
(2) Modify the virtual machine network type
Insert picture description here
Insert picture description here
Insert picture description here
3) Configure the network card IP
Insert picture description here

Insert picture description here
Insert picture description here

Install dhcp, view and find the configuration file

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
This file has a template file in the dhcpd.conf.example file in the /usr/share/doc/dhcp-4.2.5 directory. We can copy the file through cp
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
and get it by pc2.
Insert picture description here

Assign a fixed IP address to the PC

We first need to find out the physical network card of the win10 virtual machine
Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/zhangyuebk/article/details/113920483
Recommended