udhcpc 参数使用说明

简介: 当没有网络的时候,板子一直发送dhcp请求,导致程序不往下执行,解决的办法是把它切换到后台运行,可是如何切换到后台呢,有办法,它自带参数可以实现该功能。如下:   udhcpc -b -i eth0 -p /var/run/udhcpc.pid -R解释一下,-b就是切换到后台指令,-i是指定使用哪个网络接口,双网卡的时候一定要使用它来指定eth0  or  eth1。

当没有网络的时候,板子一直发送dhcp请求,导致程序不往下执行,解决的办法是把它切换到后台运行,可是如何切换到后台呢,有办法,它自带参数可以实现该功能。如下:

   udhcpc -b -i eth0 -p /var/run/udhcpc.pid -R

解释一下,-b就是切换到后台指令,-i是指定使用哪个网络接口,双网卡的时候一定要使用它来指定eth0  or  eth1。

【最近新添加 -R】

对于 -R参数,其实也很重要,在关闭udhcpc时,可以向dhcpserver发送release取消租约。

下面引用网友的一篇文章:

udhcpc 的配置记录

 
udhcpc scripts

Here's some debian scripts I wrote for udhcpc 0.9.6. I wanted to make it easy to run local scripts for DHCP changes so I created /etc/udhcpc.d. All the /usr/share/udhcpc/default.* scripts have been merged into /etc/udhcpc.d/S50default. S99local is an example script that patches resolv.conf and calls a DNS update script.

/etc/init.d/udhcpc
/etc/udhcpc.script
/etc/udhcpc.d/S50default
/etc/udhcpc.d/S99local

Last modified: Mon Feb 4 10:23:49 PST 2002


单调的分割线


http://udhcp.busybox.net/README.udhcpc

udhcp client (udhcpc)
--------------------

The udhcp client negotiates a lease with the DHCP server and notifies
a set of scripts when a leases is obtained or lost.


command line options
-------------------

The command line options for the udhcp client are:

-c, --clientid=CLIENTID         Client identifier
-H, --hostname=HOSTNAME         Client hostname
-h,    Alias for -H
-f, --foreground                Do not fork after getting lease
-b, --background                Fork to background if lease cannot be
                                immediately negotiated.
-i, --interface=INTERFACE       Interface to use (default: eth0)
-n, --now                       Exit with failure if lease cannot be
                                immediately negotiated.
-p, --pidfile=file              Store process ID of daemon in file
-q, --quit                      Quit after obtaining lease
-r, --request=IP                IP address to request (default: none)
-s, --script=file               Run file at dhcp events (default:
                                /usr/share/udhcpc/default.script)
-v, --version                   Display version


If the requested IP address cannot be obtained, the client accepts the
address that the server offers.


udhcp client scripts
-------------------

When an event occurs, udhcpc calls the action script. The script by
default is /usr/share/udhcpc/default.script but this can be changed via 
the command line arguments. The three possible arguments to the script 
are:

 deconfig: This argument is used when udhcpc starts, and
 when a leases is lost. The script should put the interface in an
 up, but deconfigured state, ie: ifconfig $interface 0.0.0.0.
 
 bound: This argument is used when udhcpc moves from an
 unbound, to a bound state. All of the paramaters are set in
 enviromental variables, The script should configure the interface,
 and set any other relavent parameters (default gateway, dns server, 
 etc).
 
 renew: This argument is used when a DHCP lease is renewed. All of
 the paramaters are set in enviromental variables. This argument is
 used when the interface is already configured, so the IP address,
 will not change, however, the other DHCP paramaters, such as the
 default gateway, subnet mask, and dns server may change.

 nak: This argument is used with udhcpc receives a NAK message.
 The script with the deconfig argument will be called directly
 afterwards, so no changes to the network interface are neccessary.
 This hook is provided for purely informational purposes (the
 message option may contain a reason for the NAK).

The paramaters for enviromental variables are as follows:

 $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

additional options are easily added in options.c.


note on udhcpc's random seed
---------------------------

udhcpc will seed its random number generator (used for generating xid's)
by reading /dev/urandom. If you have a lot of embedded systems on the same
network, with no entropy, you can either seed /dev/urandom by a method of
your own, or doing the following on startup:

ifconfig eth0 > /dev/urandom

in order to seed /dev/urandom with some data (mac address) unique to your
system. If reading /dev/urandom fails, udhcpc will fall back to its old
behavior of seeding with time(0).


signals accepted by udhcpc
-------------------------

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.


compile time options
-------------------

options.c contains a set of dhcp options for the client:

 name[10]: The name of the option as it will appear in scripts
 
 flags: The type of option, as well as if it will be requested
 by the client (OPTION_REQ)

 code: The DHCP code for this option

目录
相关文章
|
机器学习/深度学习 5G
5G中的调制技术:从QPSK到256QAM,赋能高速率通信
5G中的调制技术:从QPSK到256QAM,赋能高速率通信
3638 5
|
域名解析 存储 缓存
Linux中搭建DNS 域名解析服务器(详细版)
Linux中搭建DNS 域名解析服务器(详细版)
3534 5
|
SQL jenkins 持续交付
一篇文章掌握 FTP 和本地文件系统的桥梁 - CurlFtpFS
一篇文章掌握 FTP 和本地文件系统的桥梁 - CurlFtpFS
|
调度 C语言
深入浅出:C语言线程以及线程锁
线程锁的基本思想是,只有一个线程能持有锁,其他试图获取锁的线程将被阻塞,直到锁被释放。这样,锁就确保了在任何时刻,只有一个线程能够访问临界区(即需要保护的代码段或数据),从而保证了数据的完整性和一致性。 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位。一个进程可以包含一个或多个线程,而每个线程都有自己的指令指针和寄存器状态,它们共享进程的资源,如内存空间、文件句柄和网络连接等。 线程锁的概念
863 1
|
Python
SyntaxError :invalid syntax错误解决办法
SyntaxError :invalid syntax错误解决办法
4898 1
|
存储 机器学习/深度学习 人工智能
玩转AIGC | 使用阿里云NAS+PAI-EAS部署Stable Diffusion文生图模型
阿里云的AIGC存储解决方案是覆盖了数据收集、模型训练以及模型推理整个生命周期,本实验场景主要覆盖模型推理过程,介绍如何使用模型在线服务(PAI-EAS)以及文件存储NAS部署AIGC应用,快速生成图片。
14688 10
玩转AIGC | 使用阿里云NAS+PAI-EAS部署Stable Diffusion文生图模型
|
IDE 开发工具
Arduino 与28BYJ-48步进电机握手
Arduino 与28BYJ-48步进电机握手
872 1
|
应用服务中间件 nginx
nginx禁止未绑定域名或IP访问-全局设置
nginx禁止未绑定域名或IP访问-全局设置
550 0
|
C++ Python 容器
C++中pair用法
⭐pair的简介 pair是C++STL(标准模板库)中的一个现有容器,它将2个数据整合成一组数据,当我们类似需求的时候就可以使用到pair啦!pair其实有点像Python中字典中的键值对(Key-Value),一个Key对应着一个Value。pair的本质其实就是个结构体,它含有两个成员变量first和second。因为使用的是struct不是class,所以在定义后是可以直接使用pair中的成员变量的。 其标准库类型–pair类型定义在#include< utility > 头文件中
944 0