关于udhcpc、udhcpd在嵌入式系统的使用

一般嵌入式系统使用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

  • 11
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值