busybox 自带的 udhcpd 和 udhcpc 提供不完整的 DHCP 服务器和客户端,它们只是实现了 DHCP 协议的一部分,并且它们的功能有限。
介绍
udhcpd
DHCP 服务器udhcpc
DHCP 客户端
udhcpd
udhcpd -f /etc/udhcpd.conf
udhcpc
udhcpc -b -i $interface --script=/usr/share/udhcpc/default.script # -q
说明:
- 通过 script 指定的脚本,配置 IP、route、DNS 等
help
$ udhcpc --help
BusyBox v1.24.2 (2019-07-03 11:13:35 EEST) multi-call binary.
Usage: udhcpc [-fbqvRB] [-t N] [-T SEC] [-A SEC/-n]
[-i IFACE] [-s PROG] [-p PIDFILE]
[-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]...
-i,--interface IFACE Interface to use (default eth0)
-s,--script PROG Run PROG at DHCP events (default /usr/share/udhcpc/default.script)
-p,--pidfile FILE Create pidfile
-B,--broadcast Request broadcast replies
-t,--retries N Send up to N discover packets (default 3)
-T,--timeout SEC Pause between packets (default 3)
-A,--tryagain SEC Wait if lease is not obtained (default 20)
-n,--now Exit if lease is not obtained
-q,--quit Exit after obtaining lease
-R,--release Release IP on exit
-f,--foreground Run in foreground
-b,--background Background if lease is not obtained
-S,--syslog Log to syslog too
-r,--request IP Request this IP address
-o,--no-default-options Don't request any options (unless -O is given)
-O,--request-option OPT Request option OPT from server (cumulative)
-x OPT:VAL Include option OPT in sent packets (cumulative)
Examples of string, numeric, and hex byte opts:
-x hostname:bbox - option 12
-x lease:3600 - option 51 (lease time)
-x 0x3d:0100BEEFC0FFEE - option 61 (client id)
-F,--fqdn NAME Ask server to update DNS mapping for NAME
-V,--vendorclass VENDOR Vendor identifier (default 'udhcp VERSION')
-C,--clientid-none Don't send MAC as client identifier
-v Verbose
Signals:
USR1 Renew lease
USR2 Release lease
script 支持的环境变量
$HOME - The set $HOME env or "/"
$PATH - the set $PATH env or "/bin:/usr/bin:/sbin:/usr/sbin"
$1 - What action the script should perform
interface - The interface this was obtained on
ip - The obtained IP
siaddr - The bootp next server option
sname - The bootp server name option
boot_file - The bootp boot file option
subnet - The assigend subnet mask
timezone - Offset in seconds from UTC
router - A list of routers
timesvr - A list of time servers
namesvr - A list of IEN 116 name servers
dns - A list of DNS server
logsvr - A list of MIT-LCS UDP log servers
cookiesvr - A list of RFC 865 cookie servers
lprsvr - A list of LPR servers
hostname - The assigned hostname
bootsize - The length in 512 octect blocks of the bootfile
domain - The domain name of the network
swapsvr - The IP address of the client's swap server
rootpath - The path name of the client's root disk
ipttl - The TTL to use for this network
mtu - The MTU to use for this network
broadcast - The broadcast address for this network
ntpsrv - A list of NTP servers
wins - A list of WINS servers
lease - The lease time, in seconds
dhcptype - DHCP message type (safely ignored)
serverid - The IP of the server
message - Reason for a DHCPNAK
tftp - The TFTP server name
bootfile - The bootfile name
重新获取 IP
udhcpc also responds to SIGUSR1 and SIGUSR2. SIGUSR1 will force a renew state,
and SIGUSR2 will force a release of the current lease, and cause udhcpc to
go into an inactive state (until it is killed, or receives a SIGUSR1). You do
not need to sleep between sending signals, as signals received are processed
sequencially in the order they are received.
# Release
kill -s USR2 udhcpc
# Renew
kill -s USR1 udhcpc