什么是DHCP(动态主机配置协议)?

什么是DHCP(动态主机配置协议)?

The Dynamic Host Configuration Protocol (DHCP) is integral to networks and controls what IP addresses devices receive so they can communicate with the internet. Usually, IP assignment is automated, but if you need static IPs, familiarity with DHCP is essential.

动态主机配置协议(DHCP)是网络不可或缺的,并控制设备接收的IP地址,以便它们可以与Internet通信。 通常,IP分配是自动的,但是如果您需要静态IP,那么熟悉DHCP是必不可少的。

DHCP可以处理IP分配 (DHCP Can Handle IP Assignments)

Every device that connects to a network needs an IP address. In the early days of networking, users manually assigned themselves an IP address, but that’s a cumbersome task, especially for places with many devices, such as a corporate office. DHCP, in part, automates this process, which makes connecting devices to the network far easier. DHCP servers or routers handle this process based on a set of defined rules. Most routers are set to use a 192.168.0.x range, for instance, so you’ll commonly see IP addresses like this in home networks.

连接到网络的每个设备都需要一个IP地址。 在联网初期,用户手动为其分配IP地址,但这是一项繁琐的任务,尤其是对于具有许多设备的场所,例如公司办公室。 DHCP在某种程度上使该过程自动化,这使将设备连接到网络变得更加容易。 DHCP服务器或路由器根据一组定义的规则处理此过程。 例如,大多数路由器都设置为使用192.168.0.x范围,因此您通常会在家庭网络中看到这样的IP地址。

The process is pretty straight forward. When a client (a computer, IOT device, tablet, cell phone, etc.) connects to the network, it sends out a signal (called DHCPDISCOVER) to the DHCP server (or router). The server responds with all the rules and settings for the network and an IP address for use (a DHCPOFFER). The client acknowledges the information and asks permission to use the assigned address (a DHCPREQUEST message). Finally, the DHCP server acknowledges the request, and the client is free to connect to the network.

这个过程非常简单。 当客户端(计算机,物联网设备,平板电脑,手机等)连接到网络时,它会向DHCP服务器(或路由器)发送信号(称为DHCPDISCOVER)。 服务器以网络的所有规则和设置以及要使用的IP地址(DHCPOFFER)作为响应。 客户端确认该信息,并请求允许使用分配的地址(DHCPREQUEST消息)。 最后,DHCP服务器确认该请求,并且客户端可以*连接到网络。

DHCP控制IP地址范围 (DHCP Controls the Range of IP Addresses)

什么是DHCP(动态主机配置协议)?

You can configure DHCP to control the range of IP addresses available for use. If you state that range as starting at 192.168.0.1 and the end as 192.168.0.100, then all available addresses will fall somewhere within that range. You’ll never see a device assigned to 192.168.0.101. Also, bear in mind that the start IP (192.168.0.1 in this example) is reserved for the router. Some routers only list a starting address and then include an option for a maximum number of users (which determines the end address).

您可以配置DHCP以控制可使用的IP地址范围。 如果您将范围指定为以192.168.0.1开头,结束为192.168.0.100,则所有可用地址都将落在该范围内。 您将永远不会看到分配给192.168.0.101的设备。 另外,请记住,起始IP(在此示例中为192.168.0.1)是为路由器保留的。 某些路由器仅列出起始地址,然后包括一个用于最大用户数的选项(确定结束地址)。

The upside to this is you can control how many devices connect to your network simultaneously (no more than 100 in this example). But the downside is if you set the range too small you can unintentionally prevent connection of new devices. To allow for a lower range of IP addresses, DHCP servers only lease out IP addresses to devices.

这样做的好处是您可以控制同时连接到网络的设备数量(此示例中不超过100个)。 但是不利的是,如果将范围设置得太小,可能会无意间阻止新设备的连接。 为了允许使用较小范围的IP地址,DHCP服务器仅将IP地址出租给设备。

动态分配的地址是临时的 (Dynamically Assigned Addresses are Temporary)

When a DHCP server assigns an IP Address, it does so under a lease system. The machine retains this IP address for a set number of days, after which it can try to renew the IP address. If no renewal signal is sent (such as a decommissioned machine), then the DHCP server reclaims the IP address to assign to another device. When the renewal signal is detected, the device retains its IP address for another set of days. This is why your IP address may appear to change from time to time if you use the ipconfig option often.

DHCP服务器分配IP地址时,它是在租用系统下分配的。 机器会将该IP地址保留固定的天数,然后可以尝试更新IP地址。 如果未发送更新信号(例如,已淘汰的计算机),则DHCP服务器将收回IP地址以分配给另一台设备。 当检测到更新信号时,设备将其IP地址保留另外几天。 这就是为什么如果您经常使用ipconfig选项,则IP地址可能会不时更改的原因。

It’s possible for two devices to end up with the same IP, such as a VM machine that spends most of its time offline. The VM machine won’t be able to send the renew signal, so its IP address will be handed out to another machine. When the VM is brought back up, it still has a record of the old IP address (especially if restored from a snapshot), but it won’t be able to use that IP address since it is taken. Without that permission, it can’t connect to the network until a new IP is assigned. But using dynamic IP addresses should prevent this type of scenario.

两个设备最终可能具有相同的IP,例如一台VM机大部分时间都处于离线状态。 VM机器将无法发送更新信号,因此其IP地址将移交给另一台机器。 备份虚拟机后,它仍然具有旧IP地址的记录(尤其是从快照还原时),但是由于该IP地址被占用,因此将无法使用该IP地址。 没有该许可,它将无法连接到网络,直到分配了新IP。 但是使用动态IP地址应该可以避免这种情况。

某些设备需要静态IP地址 (Static IP Addresses are Necessary For Some Devices)

什么是DHCP(动态主机配置协议)?

If you have a network connected printer or media server (such as a NAS unit or Plex Server), it would be inconvenient for them to have their IP addresses changed. While renewal of the lease can prevent this, it’s still possible for the IP address to change. If your router is restarted, due to a power outage or because you’re trying to solve a pesky problem, then all Dynamically generated IP addresses may be reassigned. For those scenarios, manually assigning a Static IP address will solve the problem.

如果您具有网络连接的打印机或介质服务器(例如NAS单元或Plex服务器),则更改它们的IP地址将很不方便。 尽管续约可以防止这种情况,但IP地址仍然有可能更改。 如果由于断电或试图解决麻烦的问题而重启了路由器,则可能会重新分配所有动态生成的IP地址。 对于这些情况,手动分配静态IP地址将解决此问题。

The exact process for this varies, especially as router web interfaces can change from device to device even when made by the same manufacturer. On some routers, like the Eero Mesh Router kit, this may be referred to by another term, such as IP reservation. But a static IP address still needs to conform to any range rules, if they exist. Using a current IP address as the basis for a static IP is usually the easiest thing to do. Depending on the device and its Operating System, it may be possible to set a static IP at the device end instead of through the router or DHCP server. This may be necessary if the router itself doesn’t support Static IP.

确切的过程各不相同,尤其是路由器的Web界面可能因设备而异,即使由同一制造商制造也是如此。 在某些路由器上,例如Eero Mesh Router工具包 ,这可以用另一个术语来指代,例如IP保留。 但是,如果存在,静态IP地址仍需要符合任何范围规则。 使用当前IP地址作为静态IP的基础通常是最容易的事情。 根据设备及其操作系统的不同,有可能在设备端而不是通过路由器或DHCP服务器设置静态IP。 如果路由器本身不支持静态IP,则可能有必要。

翻译自: https://www.howtogeek.com/404891/what-is-dhcp-dynamic-host-configuration-protocol/