当您通过WiFi 或以太网(WiFi or ethernet)连接到本地网络时,网络路由器上的DHCP(动态主机配置协议(Dynamic Host Configuration Protocol))服务器将为您的设备分配 IP 地址。这为您的设备提供了一个 ID,允许其他设备定位并连接到它。通常,此 IP 地址在到期前会持续大约 24 小时。
这是由于DHCP租用时间。这允许本地网络将 IP 地址从已断开一段时间的设备重新分配给其他设备,从而为其他可能连接的设备释放 IP 地址(除非您为它们提供静态 IP(static IP))。
什么是 DHCP 租用时间?是否应该更改?(What Is DHCP Lease Time & Should It Be Changed?)
除非另有说明,否则典型的网络路由器将假定与之建立的任何连接都是临时的。DHCP服务器为您的设备分配了一个 IP,并附加了租用时间。如果在该期限到期后仍未看到您的设备,则租约到期,并且 IP 地址将被释放以供其他设备使用。
DHCP租用时间是租用在到期前保持活动状态的时间。正如我们所提到的,24 小时是网络为连接设备发布的通常租用时间,但这是一个标准值,可能不适合您的网络。
但是,您可以更改此值。如果您正在运行一个开放或公共网络以供其他人连接,您可能会期望大量的短期连接。这就是更短的租用时间有意义的地方,保持空闲 IP 地址池得到补充并允许新设备连接。
您使用的租赁时间取决于您自己的需要。例如,您可以将一个小时用于餐厅WiFi网络,而将 12 小时用于客户办公室网络。
您需要拥有网络路由器的管理权限才能更改这些设置。虽然您可以在 PC 或Mac(Mac)上查看当前的DHCP租用时间,但更改它需要访问您的路由器。
如何在 Windows 10 上查看 DHCP 租用时间(How To View DHCP Lease Time On Windows 10)
您可以使用Windows PowerShell(替代Windows 10上的命令行)查看(Windows 10)Windows PC的DHCP租用时间。
- 要打开PowerShell窗口,请右键单击Windows 开始(Windows Start)菜单并按Windows PowerShell (Admin)。这将启动一个具有管理权限的PowerShell终端。(PowerShell)
- 在 PowerShell 窗口中,键入ipconfig /all。这将列出有关您当前网络连接的所有相关信息,包括您的DHCP租约问题和到期时间。对于您的网络适配器,查找“已获得租约(Lease Obtained )”和“租约过期(Lease Expires)”值。
根据这些信息,您可以确定租用时间。在上面的示例中,租约到期时间正好是第一次发布租约后的 24 小时。根据您自己的网络配置,您的连接时间可能会更短或更长。
如何在 macOS 上查看 DHCP 租用时间(How To View DHCP Lease Time On macOS)
在Mac上,您可以使用内置的终端(Terminal)应用程序查看DHCP租用时间。
- 您可以通过单击屏幕底部Dock中的(Dock)Launchpad > Other > Terminal来启动终端应用程序。(Terminal)
- 您需要知道 macOS 上网络设备的设备名称。为此,请在终端(Terminal)窗口中键入networksetup -listallhardwareports 并按Enter。(networksetup -listallhardwareports )这将列出所有网络设备的名称和MAC地址。
- 获得设备名称后,您可以通过键入ipconfig getpacket en0找到当前的(ipconfig getpacket en0)DHCP租用时间,将en0替换为您自己的设备名称。这将列出有关您的连接的各种信息。DHCP租用时间将列在lease_time (uint32)选项旁边。
DHCP租用时间将在此处显示为 base-16 十六进制值。您需要将这些值转换(convert these values)为标准十进制数。例如,上面的连接有一个十六进制的DHCP租约值0x15180。这将转换为86400,以秒为单位的租约长度,相当于24 小时(24 hours)。
更改本地网络上的 DHCP 租用时间(Changing DHCP Lease Times On A Local Network)
无法在设备的网络设置中更改DHCP租用时间,因为这由分配 IP 地址的DHCP服务器(通常是您的网络路由器)控制。您需要对路由器具有管理权限才能更改此设置。
您通常可以通过在连接到网络时在 Web 浏览器中键入http://192.168.1.1 或http://192.168.0.1您可能需要查看路由器手册以确定这是否是正确的连接方式,并确定用于登录的管理员用户名和密码。
登录后,您需要在路由器的设置菜单中查找相应的Network/ LAN Settings 或DHCP 设置(DHCP Settings)区域。如果您找不到此内容,请查阅您的用户手册以获取更多建议。
DHCP租用值以多种方式命名。例如,在TP-Link路由器上,此值称为地址租用时间(address lease time)。对于这种类型的路由器,您可以在几分钟内设置此值,最多为2880(相当于48 小时(48 hours))。其他路由器将有更长或更短的最长租用期。
相应地更改值,然后保存您的设置。更改DHCP租用值后,将相应地向您的设备发布新的租用时间。
如何续订 DHCP 租约(How To Renew a DHCP Lease)
如果您更改了DHCP租用时间,您可以强制任何连接的设备释放现有的 IP 租用(release the existing IP lease)并更新它。这将允许立即应用对DHCP租用信息的任何更改。
- 要在Windows 10 PC上执行此操作,请右键单击“开始(Start)”菜单并按Windows PowerShell (Admin ) 打开(Windows PowerShell (Admin)Windows PowerShell窗口。
- 在打开的PowerShell窗口中,键入ipconfig /release。这将释放现有的 IP 租约并断开连接。
- 键入ipconfig /renew 以重新建立连接。此时网络DHCP服务器将发出新的租约。
- 在 macOS 上,您可以从“系统偏好设置”(System Preferences)菜单执行此操作。按菜单栏上的Apple 图标(Apple icon ),然后单击System Preferences。
- 在系统偏好设置(System Preferences)菜单中,按网络(Network)。在左侧菜单中选择您的网络连接,然后按Advanced。
- 在高级网络(Advanced Network)菜单中,按TCP/IP 选项卡。单击更新 DHCP 租约(Renew DHCP Lease)按钮以自动释放和更新您的 IP 租约。
这将需要几秒钟才能完成。完成后,您的 IP 地址将更新以确认您的 IP 地址,但您需要从终端应用程序运行(Terminal)ipconfig getpacket en0(将en0替换为您自己的连接)以检查当前租用时间。
在 Windows 10 中正确的网络管理(Correct Network Management In Windows 10)
分配给网络上设备的DHCP租用时间是网络工作方式的重要组成部分。但是,如果您正在为IP 地址冲突(IP address conflicts)而苦苦挣扎,您可能会发现最好将静态 IP 分配给您经常使用的设备。
其中许多设置需要在您的网络路由器上进行配置,但Windows将允许您自己更改网络设置 - 如果您的设置与您的路由器不匹配,请为冲突做好准备。这可能会阻止您看到网络上的其他计算机(seeing other computers on your network),因此请务必先仔细检查您修改的任何设置。
What Is DHCP Lease Time And How To Change It
When you connect to a local network, either by WiFi or ethernet, a DHCP (Dynamic Host Configuration Protocol) server on your network router will issue your device with an IP address. This gives your device an ID that allows other devices to locate and connect to it. Usually, this IP address lasts for around 24 hours before it expires.
This is due to the DHCP lease time. This allows a local network to reallocate IP addresses from devices that have been disconnected for a while to other devices, freeing up IP addresses for other devices that may connect (unless you give them a static IP).
What Is DHCP Lease Time & Should It Be Changed?
Unless otherwise specified, a typical network router will assume that any connection made to it is temporary. Your device is assigned an IP by the DHCP server with a lease time attached. If your device isn’t seen after that period expires, the lease expires, and the IP address is freed for other devices to use.
The DHCP lease time is the time given for a lease to remain active before it expires. As we’ve mentioned, 24 hours is the usual lease time issued by networks for connected devices, but this is a standard value that might not be appropriate for your network.
You can change this value, however. If you’re running an open or public network for others to connect to, you might expect a large number of short-term connections. This is where a smaller lease time would make sense, keeping the pool of free IP addresses replenished and allowing new devices to connect.
The lease time you use depends on your own needs. You could use an hour for a restaurant WiFi network to 12 hours for a guest office network, for instance.
You’ll need administrative access to your network router to be able to change these settings. While you can view the current DHCP lease time on your PC or Mac, changing it will require access to your router.
How To View DHCP Lease Time On Windows 10
You can view the DHCP lease time for a Windows PC by using the Windows PowerShell, the replacement for the command line on Windows 10.
- To open a PowerShell window, right-click the Windows Start menu and press Windows PowerShell (Admin). This will launch a PowerShell terminal with administrative privileges.
- In the PowerShell window, type ipconfig /all. This will list all relevant information about your current network connections, including your DHCP lease issue and expiry times. For your network adapter, look for the Lease Obtained and Lease Expires values.
From this information, you can determine the lease time. In the example above, the lease expiry time is exactly 24 hours after the lease was first issued. This period may be shorter or longer for your connection, depending on your own network configuration.
How To View DHCP Lease Time On macOS
On a Mac, you can view DHCP lease time using the built-in Terminal app.
- You can launch the Terminal app by clicking Launchpad > Other > Terminal from the Dock at the bottom of your screen.
- You’ll need to know the device name for your network device on macOS. To do this, type networksetup -listallhardwareports in the Terminal window and hit enter. This will list the name and MAC address for all network devices.
- Once you have your device name, you can find the current DHCP lease time by typing ipconfig getpacket en0, replacing en0 with your own device name. This will list various information about your connection. The DHCP lease time will be listed next to the lease_time (uint32) option.
The DHCP lease time will be shown here as a base-16 hexadecimal value. You’ll need to convert these values to a standard decimal number. For instance, the connection above has a hexadecimal DHCP lease value of 0x15180. This converts to 86400, the length of the lease in seconds, which is equivalent to 24 hours.
Changing DHCP Lease Times On A Local Network
It isn’t possible to change the DHCP lease time in your device’s network settings as this is controlled by the DHCP server that allocates IP addresses, which is usually your network router. You’ll need to have administrative access to your router to change this.
You can usually connect to your network router by typing http://192.168.1.1 or http://192.168.0.1 in a web browser while connected to the network. You may need to check the manual for your router to determine if this is the correct way to connect, as well as determine the admin username and password to log in.
Once you’ve signed in, you’ll need to look for the appropriate Network/ LAN Settings or DHCP Settings area in your router’s settings menu. If you can’t find this, consult your user manual for further advice.
The DHCP lease value is named in various ways. For instance, on a TP-Link router, this value is called the address lease time. You can set this in minutes for this type of router, up to a maximum of 2880 (the equivalent of 48 hours). Other routers will have longer or shorter maximum lease periods.
Change the value accordingly, then save your settings. Once the DHCP lease value has been changed, the new lease time will be issued to your devices accordingly.
How To Renew a DHCP Lease
If you’ve changed your DHCP lease time, you can force any connected devices to release the existing IP lease and renew it. This will allow any changes to your DHCP lease information to be applied immediately.
- To do this on a Windows 10 PC, open a Windows PowerShell window by right-clicking the Start menu and pressing Windows PowerShell (Admin).
- In the open PowerShell window, type ipconfig /release. This will release the existing IP lease and disconnect.
- Type ipconfig /renew to reestablish the connection. The network DHCP server will issue a new lease at this point.
- On macOS, you can do this from the System Preferences menu. Press the Apple icon on the menu bar, then click System Preferences.
- In the System Preferences menu, press Network. Select your network connection in the left-hand menu, then press Advanced.
- In the Advanced Network menu, press the TCP/IP tab. Click the Renew DHCP Lease button to release and renew your IP lease automatically.
This will take a few seconds to complete. Once completed, your IP address will update to confirm your IP address, but you’ll need to run ipconfig getpacket en0 (replacing en0 with your own connection) from the Terminal app to check the current lease time.
Correct Network Management In Windows 10
The DHCP lease time allocated to devices on a network is an essential component in how your network works. If you’re struggling with IP address conflicts, however, you may find that it’s better to assign a static IP to devices that you use regularly.
Many of these settings need to be configured on your network router, but Windows will allow you to change network settings yourself—just be prepared for conflicts if your settings don’t match your router. This might prevent you from seeing other computers on your network, so be sure to double-check any settings you modify first.