【1】动态主机分配协议
【2】由Internet工作任务小组设计开发,专门为用户TCP/IP网络中的计算机自动分配IP地址
【1】减少管理员的工作量
【2】避免IP地址冲突
【3】提高了IP地址的利用率
【1】自动分配:分配到一个IP地址后永久使用
【2】手动分配:由dhcp服务器管理员指定IP地址
【3】动态分配:使用完该IP地址就动态释放,其他用户使用
【1】discover:客户机在网络中找到DHCP服务器的过程
【2】offer:dhcp服务器向客户机提供IP地址、子网掩码、网关、DNS地址、租约
【3】request:客户机再次请求确认IP地址等是否可用
【4】ACK:服务器确认IP地址等可用 | noACK:IP地址等不可用,重新discover
[root@localhost ~]# yum install -y dhcp*
文件路径:/etc/dhcp/dhcpd.conf
模板路径:/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
进入主配置文件之后编辑模板文件
在模板文件下把内容强制写入到主配置文件。
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "centos7.6";
option domain-name-servers 10.10.10.10;
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.50.0 netmask 255.255.255.0 {
range 192.168.50.100 192.168.50.200;
option routers 192.168.50.1;
option domain-name-servers 9.9.9.9;
}
使用windows内部命令查看boss主机的物理地址用于手动指定IP地址
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
host boss {
hardware ethernet 00:0C:29:EA:92:0B;
fixed-address 192.168.50.88;
}
[root@localhost ~]# setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl start dhcpd(第一次使用开启服务)
[root@localhost ~]# systemctl status dhcpd(查看服务状态)
dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
Active: active (running) since 日 2020-07-05 12:04:05 CST; 1min 14s ago
[root@localhost ~]# systemctl restart dhcpd(每次修改完配置文件必须重启服务)
(1)修改客户机的IP获取方式为自动获取
(2)使用windows内部命令查看boss指定IP地址
(3)使用Windows内部命令查看其他客户机IP地址
当某一个企业的内部网络规模较大时,通常会被划分多个子网形成不同的vlan,而DHCP服务这只能在同一广播域中给主机分配IP地址,其他网段的主机无法从DHCP服务器获取IP地址,所以DHCP中继的功能是跨越不同的vlan给不同的广播域分配IP地址。注:DHCP中继是配置在网关上为各个网段分配地址。
1)二层交换机SW1配置
undo terminal monitor (关闭提示信息)
sys
[Huawei]sysname SW1
[SW1]vlan batch 10 20 100
[SW1]int e0/0/1
[SW1-Ethernet0/0/1]p l a
[SW1-Ethernet0/0/1]p d v 10
[SW1-Ethernet0/0/1]q
[SW1]int e0/0/2
[SW1-Ethernet0/0/2]p l a
[SW1-Ethernet0/0/2]p d v 20
[SW1-Ethernet0/0/2]q
[SW1]int g0/0/2
[SW1-GigabitEthernet0/0/2]p l a
[SW1-GigabitEthernet0/0/2]p d v 100
[SW1-GigabitEthernet0/0/2]q
[SW1]int e0/0/3
[SW1-Ethernet0/0/3]p l a
[SW1-Ethernet0/0/3]p d v 100
[SW1-Ethernet0/0/3]q
[SW1]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l t
[SW1-GigabitEthernet0/0/1]p t a v a
[SW1-GigabitEthernet0/0/1]q
2)三层交换机LSW1的配置
undo terminal monitor (关闭提示信息)
sys
[Huawei]sysname LSW1
[LSW1]vlan batch 10 20 100
[LSW1]dhcp enable
[LSW1]interface Vlanif10
[LSW1-Vlanif10]ip address 192.168.10.1 255.255.255.0
[LSW1-Vlanif10]dhcp select relay(启动中继)
[LSW1-Vlanif10]dhcp relay server-ip 192.168.100.10(中继服务地址)
[LSW1]interface Vlanif20
[LSW1-Vlanif20]ip address 192.168.20.1 255.255.255.0
[LSW1-Vlanif20]dhcp select relay
[LSW1-Vlanif20]dhcp relay server-ip 192.168.100.10
[LSW1]interface Vlanif100
[LSW1-Vlanif100]ip address 192.168.100.1 255.255.255.0
[LSW1-Vlanif100]dhcp select relay
[LSW1-Vlanif100]dhcp relay server-ip 192.168.100.10
[LSW1] interface GigabitEthernet0/0/1
[LSW1-GigabitEthernet0/0/1]port link-type trunk
[LSW1-GigabitEthernet0/0/1]port trunk allow-pass vlan 2 to 4094
[LSW1-GigabitEthernet0/0/1]q
[root@kgc ~]# vim /etc/dhcp/dhcpd.conf
1)全局配置
option domain-name "centos7.6";
option domain-name-servers 10.10.10.10;
2)子网段配置
192.168.100.0网段
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.100 192.168.100.200;
option routers 192.168.100.1;
option domain-name-servers 9.9.9.9;
}
192.168.10.0网段
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200;
option routers 192.168.10.1;
option domain-name-servers 9.9.9.9;
}
192.168.20.0网段
subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.100 192.168.20.200;
option routers 192.168.20.1;
option domain-name-servers 9.9.9.9;
}
在虚拟机上ping服务器网关
[root@kgc ~]# ping 192.168.100.1
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data.
64 bytes from 192.168.100.1: icmp_seq=1 ttl=128 time=0.347 ms
64 bytes from 192.168.100.1: icmp_seq=1 ttl=255 time=27.0 ms
64 bytes from 192.168.100.1: icmp_seq=2 ttl=128 time=0.517 ms
64 bytes from 192.168.100.1: icmp_seq=2 ttl=255 time=39.2 ms
在网络模拟器上三层交换机上ping其余网段的网关
[LSW1]ping 192.168.10.1
PING 192.168.10.1: 56 data bytes, press CTRL_C to break
Reply from 192.168.10.1: bytes=56 Sequence=1 ttl=255 time=30 ms
Reply from 192.168.10.1: bytes=56 Sequence=2 ttl=255 time=10 ms
Reply from 192.168.10.1: bytes=56 Sequence=3 ttl=255 time=1 ms
Reply from 192.168.10.1: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 192.168.10.1: bytes=56 Sequence=5 ttl=255 time=30 ms
PC>ipconfig /renew
IP Configuration
Can't find DHCP server!
Link local IPv6 address...........: fe80::5689:98ff:fe2c:6333
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.10.100
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.10.1
Physical address..................: 54-89-98-2C-63-33
DNS server........................: 9.9.9.9
192.168.20.0网段获取IP地址
PC>ipconfig /renew
IP Configuration
Can't find DHCP server!
Link local IPv6 address...........: fe80::5689:98ff:feaf:670a
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.20.100
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.20.1
Physical address..................: 54-89-98-AF-67-0A
DNS server........................: 9.9.9.9
在192.168.100.0网段获取IP地址
PC>ipconfig /renew
IP Configuration
Link local IPv6 address...........: fe80::5689:98ff:fe51:4eba
IPv6 address......................: :: / 128
IPv6 gateway......................: ::
IPv4 address......................: 192.168.100.101
Subnet mask.......................: 255.255.255.0
Gateway...........................: 192.168.100.1
Physical address..................: 54-89-98-51-4E-BA
DNS server........................: 9.9.9.9