Help Center/ Virtual Private Cloud/ FAQs/ VPCs and Subnets/ How Do I Make the Changed DHCP Lease Time of a Subnet Take Effect Immediately?
Updated on 2024-10-25 GMT+08:00

How Do I Make the Changed DHCP Lease Time of a Subnet Take Effect Immediately?

Scenario

After you change the DHCP lease time on the console, the change will be applied when the DHCP lease of an instance (such as ECS) is renewed. You can manually renew the lease or wait for the system to do it. Renewing lease will not change the IP address of the instance.

  • If you want the change to be applied immediately, manually renew the lease. Manual renewal will interrupt services.
  • If you do not want the change to be applied immediately, wait for the system to renew the DHCP lease automatically. The system renews the lease for the first time when half of the current lease time is left. If the renewal fails, the system attempts to renew the lease again when one eighth of the current lease time is left. If the renewal still fails, the IP address of the instance will be released after the current lease expires. To prevent the IP address from being released, manually renew the lease.

For details about the DHCP lease renewal, see Table 1.

Table 1 DHCP lease renewal

Applied Immediately

How to Renew

Description

Yes

Manually

You can manually renew the DHCP lease of the instance by referring to Viewing and Renewing the DHCP Lease (Windows ECS) or Viewing and Updating the DHCP Lease (Linux ECS).

You can also restart the instance to make the new DHCP release to be applied immediately.

NOTICE:

If you renew the DHCP lease manually, the IP address of the instance will be released, and a new IP address will be assigned when the new lease is applied. This may cause service interruption.

No

Automatically

You can wait for the new lease to be applied automatically.

  • First attempt: The system renews the lease for the first time when half of the current lease time is left. If the renewal succeeds, the new lease is applied.
  • Second attempt: If the first attempt fails, the system attempts to renew the lease again when one eighth of the current lease time is left. If the renewal succeeds, the new lease is applied. If the second attempt still fails, the IP address of the instance is released after the current DHCP lease expires.

Suppose the DHCP lease time of an ECS is 30 days, and the lease will expire on January 30, 2024. If you change the DHCP lease time to 10 days on January 2, 2024:

  • First attempt: The system will renew the lease on January 15, 2024 when half of the current lease time is left. If the attempt succeeds, the lease of the ECS will expire on January 25, 2024. When half of the new lease time is left, the lease will be renewed on January 20, 2024.
  • Second attempt: If the first attempt fails, the system attempts to renew the lease again on January 26, 2024 when one eighth of the current lease time is left. If the attempt succeeds, the lease will expire on February 5, 2024. If the second attempt still fails, the IP address of the ECS will be released on January 30, 2024.

Viewing and Renewing the DHCP Lease (Windows ECS)

  1. After you change the DHCP lease time on the console, log in to the ECS whose lease you want to renew.
  2. Enter cmd in the search box to open the CLI.
  3. View the expiration time of the current DHCP lease:

    ipconfig /all

  4. Renew the DHCP lease:

    ipconfig /release && ipconfig /renew

  5. Check the new DHCP lease expiration time:

    ipconfig /all

Viewing and Updating the DHCP Lease (Linux ECS)

  1. After you change the DHCP lease time on the console, log in to the ECS whose lease you want to renew.
  2. Check whether the client that provides the DHCP service is dhclient:

    ps -ef | grep dhclient

    • If information similar to the following is displayed, the dhclient process exists and the client is dhclient. The lease file following the -lf parameter contains lease information.
      [root@ecs-A ~]# ps -ef | grep dhclient
      root       580   526  0 18:49 ?        00:00:00 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-eth0.pid -lf /var/lib/NetworkManager/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease -cf /var/lib/NetworkManager/dhclient-eth0.conf eth0
      root      1512  1470  0 18:50 pts/0    00:00:00 grep --color=auto dhclient
    • If the dhclient process does not exist, this procedure may not be applicable. In this case, you need to search for the operation commands of the corresponding DHCP client.
  3. View the latest DHCP lease information in the lease file obtained in 2:

    cat lease File name

    Example command:

    cat /var/lib/NetworkManager/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease

    Information similar to the following is displayed. The lease file contains historical DHCP lease information, and the information following the last lease is about the latest DHCP lease.
    [root@ecs-A ~]# cat /var/lib/NetworkManager/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease
    lease {
      interface "eth0";
      fixed-address 172.16.0.54;
      option subnet-mask 255.255.255.0;
      option dhcp-lease-time 108000000;
      option routers 172.16.0.1;
      option dhcp-message-type 5;
      option dhcp-server-identifier 172.16.0.254;
      option domain-name-servers 100.125.1.250,100.125.64.250;
      option interface-mtu 1500;
      option dhcp-renewal-time 54000000;
      option dhcp-rebinding-time 94500000;
      option rfc3442-classless-static-routes 0,172,16,0,1,32,169,254,169,254,172,16,0,1;
      option broadcast-address 172.16.0.255;
      option host-name "host-172-16-0-54";
      option domain-name "openstacklocal";
      renew 3 2025/06/18 21:46:42;
      rebind 3 2027/01/20 04:46:44;
      expire 5 2027/06/25 10:46:44;
    }
    lease {
      interface "eth0";
      fixed-address 172.16.0.54;
      option subnet-mask 255.255.255.0;
      option routers 172.16.0.1;
      option dhcp-lease-time 108000000;
      option dhcp-message-type 5;
      option domain-name-servers 100.125.1.250,100.125.64.250;
      option dhcp-server-identifier 172.16.0.254;
      option interface-mtu 1500;
      option dhcp-renewal-time 54000000;
      option broadcast-address 172.16.0.255;
      option rfc3442-classless-static-routes 0,172,16,0,1,32,169,254,169,254,172,16,0,1;
      option dhcp-rebinding-time 94500000;
      option host-name "host-172-16-0-54";
      option domain-name "openstacklocal";
      renew 3 2025/08/20 23:57:15;
      rebind 3 2027/01/20 04:50:00;
      expire 5 2027/06/25 10:50:00;
    }
  4. Release the IP address of the ECS:

    dhclient -r

  5. Obtain the new DHCP lease:

    killall dhclient && systemctl restart NetworkManager

  6. View the latest DHCP lease information in the lease file obtained in 2:

    cat lease File name

    Example command:

    cat /var/lib/NetworkManager/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease

    Information similar to the following is displayed. The lease file contains historical DHCP lease information, and the information following the last lease is about the latest DHCP lease.
    [root@ecs-A ~]# cat /var/lib/NetworkManager/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease
    lease {
      interface "eth0";
      fixed-address 172.16.0.54;
      option subnet-mask 255.255.255.0;
      option dhcp-lease-time 108000000;
      option routers 172.16.0.1;
      option dhcp-message-type 5;
      option dhcp-server-identifier 172.16.0.254;
      option domain-name-servers 100.125.1.250,100.125.64.250;
      option interface-mtu 1500;
      option dhcp-renewal-time 54000000;
      option dhcp-rebinding-time 94500000;
      option rfc3442-classless-static-routes 0,172,16,0,1,32,169,254,169,254,172,16,0,1;
      option broadcast-address 172.16.0.255;
      option host-name "host-172-16-0-54";
      option domain-name "openstacklocal";
      renew 3 2025/08/20 23:57:15;
      rebind 3 2027/01/20 04:50:00;
      expire 5 2027/06/25 10:50:00;
    }
    lease {
      interface "eth0";
      fixed-address 172.16.0.54;
      option subnet-mask 255.255.255.0;
      option routers 172.16.0.1;
      option dhcp-lease-time 108000000;
      option dhcp-message-type 5;
      option domain-name-servers 100.125.1.250,100.125.64.250;
      option dhcp-server-identifier 172.16.0.254;
      option interface-mtu 1500;
      option dhcp-renewal-time 54000000;
      option broadcast-address 172.16.0.255;
      option rfc3442-classless-static-routes 0,172,16,0,1,32,169,254,169,254,172,16,0,1;
      option dhcp-rebinding-time 94500000;
      option host-name "host-172-16-0-54";
      option domain-name "openstacklocal";
      renew 4 2025/07/03 00:34:04;
      rebind 3 2027/01/20 04:52:43;
      expire 5 2027/06/25 10:52:43;
    }Sub-eni