Article title: dynamically allocates IP addresses in embedded linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Dhcp is inevitable because network communication is required. The ideal network communication method is supported in the following three ways:
1. access an existing network. This requires that the client can be used as a dhcp client.
2. dynamically allocate IP addresses as DHCP servers.
3. specify a fixed IP address
There are no more than 3rd cases. let's briefly describe the first two cases.
Procedure:
(1) configure DHCP in the network entry of the kernel;
(2) put [*] udhcp server (udhcpd) in busybox)
[*] Udhcp client (udhcpc) is selected.
Udhcpd is the terminal device used as the DHCP server.
A udhcpc is a client that uses a terminal device as a DHCP client.
An example of dhcp in busybox is provided,
[Zhh @ localhost busybox-1.14.1] $ ls./examples/udhcp/
Sample. bound sample. deconfig sample. nak sample. renew sample. script simple. script udhcpd. conf
For example, when using udhcpc
You can use simple. script directly without changing the name. The default directory file in busybox is/usr/share/udhcpc/default. script.
You can view help
# Udhcpc -- help
BusyBox v1.14.1 (10:35:16 CST) multi-call binary
Usage: udhcpc [-Cfbnqtvo] [-c CID] [-v vcls] [-h hostname] [-I INTERFACE]
[-P pidfile] [-r IP] [-s script] [-O dhcp-option]... [-p n]
-V classid Vendor class identifier
-I INTERFACE Interface to use (default: eth0)
-H,-h HOSTNAME Client hostname
-C CLIENTID Client identifier
-C Suppress default client identifier
-P file Create pidfile
-R IP address to request
-S file Run file at DHCP events (default/usr/share/udhcpc/default. script)
-T N Send up to N request packets
-T n Try to get a lease for N seconds (default 3)
-A n Wait N seconds (default 20) after failure
-O opt Request DHCP option OPT (cumulative)
-O Do not request any options (unless-O is also given)
-F Run in foreground
-B Background if lease is not immediately obtained
-S Log to syslog too
-N Exit with failure if lease is not immediately obtained
-Q Quit after obtaining lease
-R Release IP on quit
-P n Use port N instead of default 68
-A Use arping to validate offered address
#
This makes it easy to understand.
The following describes how to use udhcpd. you can also directly use the udhcpd. conf that comes with busybox as a reference. you will not detail how to set this file. refer to the relevant documentation. How to use udhcpd
# Udhcpd -- help
BusyBox v1.14.1 (10:35:16 CST) multi-call binary
Usage: udhcpd [-fS] [-p n] [configfile]
DHCP server
-F Run in foreground
-S Log to syslog too
-P n Use port N instead of default 67
The help is clear at a glance.
When I use it directly
# Udhcpd/etc/udhcpd. conf
You can.
Another lease file should be brief. when udhcpd is used, a lease file will be required to be created. just create one as Prompted. what does it do? It is to record the IP address obtained by the client. if there is no lease file, a new IP address will be assigned to the client again. if yes, the original IP address will be used.