Configuring a DHCP Client
- Enabling the DHCP Client Function
- (Optional) Configuring Attributes
- (Optional) Configuring an Expected Lease
- (Optional) Configuring Gateway Detection
- (Optional) Configuring a DHCP Client to Dynamically Obtain Routing Information
- (Optional) Configuring Option Information Requested by a DHCP Client
- Verifying the DHCP Client Configuration
Enabling the DHCP Client Function
Context
Before a device can function as a DHCP client, you must enable the DHCP client function.
After an interface is enabled with the DHCP client function, the interface can obtain network parameters including the IP address from the DHCP server. If the allocated IP address and IP addresses of other interfaces are on the same network segment, the interface does not use this IP address and does not re-apply for an IP address. To allow the interface to re-apply for an IP address, run the shutdown and then the undo shutdown commands on the interface. Alternatively, run the undo ip address dhcp-alloc and then the ip address dhcp-alloc command on the interface.
Procedure
- Enter the system view.
system-view
- Enter the interface view or sub-interface view.
interface interface-type interface-number [.subinterface-number ]
- (Optional) On an Ethernet interface, run undo portswitch
The interface is switched to Layer 3 mode.
By default, an Ethernet interface works in Layer 2 mode.
- Enable the DHCP client function.
ip address dhcp-alloc
By default, the DHCP client function is disabled on an interface.
(Optional) Configuring Attributes
Context
Configuring attributes allows you to specify certain parameters for the DHCP client. You can configure the Option 60 field in either the system view or the interface view. The configuration in the interface view has a higher priority and overrides the configuration in the system view.
Procedure
- Enter the system view.
system-view
- Configure the DHCP client to send DHCP Discover messages that carry the Option 60 field.
dhcp client class-id class-id
By default, the value of the Option 60 field is in the format of "huawei device model".
- Enter the interface view or sub-interface view.
interface interface-type interface-number [.subinterface-number ]
- (Optional) On an Ethernet interface, run undo portswitch
The interface is switched to Layer 3 mode.
By default, an Ethernet interface works in Layer 2 mode.
- Configure a hostname for the DHCP client.
dhcp client hostname hostname
By default, no hostname is configured for a DHCP client.
Client hostname is entered in the Option 12 field. A hostname allows access to a DHCP client through a domain name. A domain name consists of a hostname and domain name suffix.
- Configure an identifier for the DHCP client.
dhcp client client-id client-id
By default, a client's MAC address is used as its identifier.
Client identifier information is entered in the Option 61 field to uniquely identify the DHCP client.
- Configure the DHCP client to send DHCP Discover messages that carry the Option 60 field.
dhcp client class-id class-id
By default, the Option 60 field is not configured.
(Optional) Configuring an Expected Lease
Context
To enable a DHCP client to determine the lease length, configure an expected lease on the DHCP client. If the expected lease is longer than the global lease, the global lease takes effect.
Procedure
- Enter the system view.
system-view
- Enter the interface view or sub-interface view.
interface interface-type interface-number [.subinterface-number ]
- (Optional) On an Ethernet interface, run undo portswitch
The interface is switched to Layer 3 mode.
By default, an Ethernet interface works in Layer 2 mode.
- Configure the expected lease.
dhcp client expected-lease time
By default, no expected lease is configured for a DHCP client.
- Renew the lease of the DHCP client's IP address.
dhcp client renew
This command takes effect only if an IP address is already assigned.
(Optional) Configuring Gateway Detection
Context
To enable a DHCP client to detect the status of the gateway, enable the gateway detection function. A DHCP client enabled with the gateway detection function sends an ARP Request packet to detect the gateway status after obtaining an IP address. If the DHCP client receives no ARP Reply packet within the detection period, it considers the gateway address incorrect or the gateway device faulty, and then re-applies for an IP address.
Procedure
- Enter the system view.
system-view
- Enter the interface view or sub-interface view.
interface interface-type interface-number [.subinterface-number ]
- (Optional) On an Ethernet interface, run undo portswitch
The interface is switched to Layer 3 mode.
By default, an Ethernet interface works in Layer 2 mode.
- Configure the gateway detection function on the DHCP client.
dhcp client gateway-detect period period retransmit retransmit timeout time
By default, the gateway detection function is not configured on a DHCP client.
(Optional) Configuring a DHCP Client to Dynamically Obtain Routing Information
Context
To allow a DHCP client to communicate with other network devices, you need to configure a route in which the next hop address is the gateway address of the client. If the gateway address of the client is dynamically obtained from the DHCP server and the route is statically configured on the client, the static route must be manually modified when the gateway address changes. After the DHCP client is configured to dynamically obtain routing entries through DHCP, the next hop address in the static route is automatically updated when the gateway address changes, lowering maintenance costs.
A DHCP server can allocate routing entries to DHCP clients. On a device functioning as the DHCP client, you can set the priorities of routing entries allocated by the DHCP server so that the DHCP client can dynamically update its routing table.
Procedure
- Enter the system view.
system-view
- Configure the DHCP client to obtain routing entries through DHCP.
ip route ip-address { mask | mask-length } interface-type interface-number dhcp [ preference-value ]
By default, a DHCP client does not obtain routing entries through DHCP.
- Enter the interface view or sub-interface view.
interface interface-type interface-number [.subinterface-number ]
- (Optional) On an Ethernet interface, run undo portswitch
The interface is switched to Layer 3 mode.
By default, an Ethernet interface works in Layer 2 mode.
- Set the priority of routing entries allocated by the DHCP server to DHCP clients.
dhcp client default-route preference preference-value
The default priority of routing entries allocated by the DHCP server to DHCP clients is 60.
(Optional) Configuring Option Information Requested by a DHCP Client
Context
The Option 55 field in DHCP Request messages is used to set the request option list. DHCP clients use this option to specify network configuration parameters that need to be obtained from the DHCP server. You can run the dhcp client request option-list exclude command to set a list of default options that are excluded from the Option 55 field or run the dhcp client request option-list command to set a list of other options that the Option 55 field carries besides the default options based on network requirements. The other options include option 4, 7, 17, 42, 43, 66, 67, 120, and 129.
For option meanings, see DHCP Messages in Configuration- IP Service Configuration Guide - DHCP Configuration.
Procedure
- Enter the system view.
system-view
- Enter the interface view or sub-interface view.
interface interface-type interface-number [.subinterface-number ]
- (Optional) On an Ethernet interface, run undo portswitch
The interface is switched to Layer 3 mode.
By default, an Ethernet interface works in Layer 2 mode.
- Configure a list of default request options that are excluded from the Option 55 field in DHCP Request messages.
dhcp client request option-list exclude option-code &<1-8>
By default, the device does not configure the option to be excluded from the DHCP client request list.
- Configure a list of request options that the Option 55 field in DHCP Request messages carries besides the default options.
dhcp client request option-list option-code &<1-9>
By default, the Option 55 field in DHCP Request packets carries only default request options.
- Enabling the DHCP Client Function
- (Optional) Configuring Attributes
- (Optional) Configuring an Expected Lease
- (Optional) Configuring Gateway Detection
- (Optional) Configuring a DHCP Client to Dynamically Obtain Routing Information
- (Optional) Configuring Option Information Requested by a DHCP Client
- Verifying the DHCP Client Configuration