一般嵌入式系统使用busybox,为了方便调试,可能会使用有线网卡进行调试(我是初学者,所以刚开始还是让板子带上了RJ45口。好,废话不多说,直接上正题!
一、udhcpc
我们先看一下启动的示例命令:
udhcpc -b -i eth0 -p /var/run/udhcpc.pid
参数解析:-b 后台执行指令,-i 指定使用哪个网络接口,如果设备不止一个网卡,必须需要指定接口类型,一般为eth0 or eth1。
udhcpc -h
udhcpc: option requires an argument -- h
BusyBox v1.22.1 (2023-06-29 17:46:24 CST) multi-call binary.
Usage: udhcpc [-fbqvaRB] [-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
-a,--arping Use arping to validate offered address
-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
如何关闭udhcpc呢?
答:从eth*接口的进程文件 *.pid 读出进程号,然后直接kill掉即可(嵌入式一般都是root用户)。
至于从读脚本配置方式执行udhcpc,这里就不展开,有兴趣的搜索下相关
二、udhcpd
该命令一般作为DHCP服务端时使用,用于为设备同一局域网内接入设备分配ID地址及其他网络配置。
江湖惯例,先看一下启动的示例命令:
udhcpd -f /path/to/udhcpd.conf
conf文件配置一般方式(简单的方式,只作样例)
start 192.168.2.100
end 192.168.2.254
max_leases 252
option lease 86400 # 设置租赁时间为86400秒(1天)
租约文件:
udhcpd使用一个租约文件来跟踪已分配的IP地址。这个文件通常/etc/udhcpd.leases
样例
opt dns 192.168.5.1
opt wins 192.168.10.1
好了,其实也是简单介绍下。Linux的命令十分强大、繁杂,不同的常用命令在不同的使用场景搭配的参数不一致。本来我就不是个写博客的人,不太喜欢记录生活。但没办法,计算机这行单靠一个脑袋太难装下所有知识了,这篇博客就当且一个开端。顺便放个联系方式 QQ:359489892