Udhcpc: Difference between revisions
(replace /etc/init.d with rc-service) |
Prabuanand (talk | contribs) (Added reference to Main Networking article, headings and moved the content related to ADSL MTU to troubleshooting section.) |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:udhcpc}} | {{DISPLAYTITLE:udhcpc}} | ||
{{Main|Configure Networking}} | |||
This page documents the working of default DHCP client <code>udhcpc</code> from Busybox. | |||
The default behavior is driven by the script {{path|/usr/share/udhcpc/default.script}} | == Configuration == | ||
The default DHCP client <code>udhcpc</code> from busybox gets invoked by the networking scripts {{path|/sbin/ifup}} and {{path|/sbin/ifdown}} when "<code>dhcp</code>" is added to the interface name in the file {{path|/etc/network/interfaces}}. | |||
The default behavior of udhcpc is driven by the script {{path|/usr/share/udhcpc/default.script}} | |||
Entries in {{path|/etc/network/interfaces}} for DHCP interfaces will drive the <code>udhcpc</code> command line. For example:<br> | Entries in {{path|/etc/network/interfaces}} for DHCP interfaces will drive the <code>udhcpc</code> command line. For example:<br> | ||
Line 18: | Line 22: | ||
The hostname will send the DHCP option to the server to tell the server the name of this client. | The hostname will send the DHCP option to the server to tell the server the name of this client. | ||
You can add arbitrary command line parameters to the <code>udhcpc_opts</code> setting in {{path|/etc/network/interfaces}}. See the example of <code>udhcpc_opts</code> in [[Configure Networking#IPv4 DHCP Configuration|the main networking article]]. | You can add arbitrary command line parameters to the <code>udhcpc_opts</code> setting in {{path|/etc/network/interfaces}}. See the example of <code>udhcpc_opts</code> in [[Configure Networking#IPv4 DHCP Configuration|the main networking article]]. | ||
Line 64: | Line 66: | ||
{{cat|/etc/udhcpc/udhcpc.conf|RESOLV_CONF{{=}}"no" # Prevents overwriting of /etc/resolv.conf}} | {{cat|/etc/udhcpc/udhcpc.conf|RESOLV_CONF{{=}}"no" # Prevents overwriting of /etc/resolv.conf}} | ||
Custom scripts can be added as {{path|/etc/udhcpc/pre-*}} and {{path|/etc/udhcpc/post-*}} to be run before/after deconfig/renew/bound DHCP events. | Custom scripts can be added as {{path|/etc/udhcpc/pre-*}} and {{path|/etc/udhcpc/post-*}} to be run before/after deconfig/renew/bound DHCP events. The custom scripts must be set as '''executable''' by root, e.g. <code>chmod 744</code>. Refer an example [[#Change default MTU for ADSL|custom script]] | ||
== Troubleshooting == | |||
{{Todo|The below section need testing and confirmation. Please help contributing.}} | |||
=== Change default MTU for ADSL === | |||
As an example, {{path|/etc/udhcpc/post-bound/mtu}} could contain, to change the interface MTU from the default (1500) to 1492, which is useful if [https://en.wikipedia.org/wiki/Maximum_transmission_unit on ADSL that uses PPPoE] (which uses 8 bytes for its own header): | As an example, {{path|/etc/udhcpc/post-bound/mtu}} could contain, to change the interface MTU from the default (1500) to 1492, which is useful if [https://en.wikipedia.org/wiki/Maximum_transmission_unit on ADSL that uses PPPoE] (which uses 8 bytes for its own header): | ||
{{cmd|<nowiki>r=$(/sbin/ip route | grep ^default | head -n 1) | {{cmd|<nowiki>r=$(/sbin/ip route | grep ^default | head -n 1) | ||
# Needs iproute2 package, rather than busybox's "ip", to change mtu | # Needs {{pkg|iproute2}} package, rather than busybox's "ip", to change mtu | ||
/sbin/ip route replace $r mtu 1492 | /sbin/ip route replace $r mtu 1492 | ||
</nowiki>}} | </nowiki>}} | ||
I needed to restart my firewall (which replaces the <code>iptables</code> script from Alpine) when the client binds to a new IP, so I added the following line in the function <code>bound()</code>, right after '<code>resolvconf</code>': | I needed to restart my firewall (which replaces the <code>iptables</code> script from Alpine) when the client binds to a new IP, so I added the following line in the function <code>bound()</code>, right after '<code>resolvconf</code>': | ||
Line 79: | Line 86: | ||
The reload drops all firewall rules, re-acquires the Internal and external IPs, and re-writes the rules. I'm sure there is a better way. | The reload drops all firewall rules, re-acquires the Internal and external IPs, and re-writes the rules. I'm sure there is a better way. | ||
== See Also == | |||
[https://udhcp.busybox.net/README.udhcpc Busybox udhcpc Readme] | |||
[[Category:Networking]] | [[Category:Networking]] | ||
[[Category:Embedded Systems]] | [[Category:Embedded Systems]] |
Revision as of 14:27, 17 October 2024
This page documents the working of default DHCP client udhcpc
from Busybox.
Configuration
The default DHCP client udhcpc
from busybox gets invoked by the networking scripts /sbin/ifup and /sbin/ifdown when "dhcp
" is added to the interface name in the file /etc/network/interfaces.
The default behavior of udhcpc is driven by the script /usr/share/udhcpc/default.script
Entries in /etc/network/interfaces for DHCP interfaces will drive the udhcpc
command line. For example:
Contents of /etc/network/interfaces
will set these parameters on the command line:
udhcpc -i eth0 -x hostname:myhostname
The hostname will send the DHCP option to the server to tell the server the name of this client.
You can add arbitrary command line parameters to the udhcpc_opts
setting in /etc/network/interfaces. See the example of udhcpc_opts
in the main networking article.
The default configuration of udhcpc
may be overridden by /etc/udhcpc/udhcpc.conf. Please see /usr/share/udhcpc/default.script for how the values are used.
udhcpc.conf accepts the following key:value pairs:
key | default value | possible values | meaning |
---|---|---|---|
RESOLV_CONF | /etc/resolv.conf | no ; NO ; - | do not overwrite or alternative path for resolv.conf |
NO_DNS | - | <list of iface names> | Prevent overwriting of resolv.conf on a per-interface basis |
NO_GATEWAY | - | <list of iface names> | List of interfaces where DHCP routes are ignored |
IF_METRIC | - | <metric value> | offset value for routing metric |
IF_PEER_DNS | yes | <anything but yes> | please use RESOLV_CONF or NO_DNS instead |
Example /etc/udhcpc/udhcpc.conf:
Contents of /etc/udhcpc/udhcpc.conf
Custom scripts can be added as /etc/udhcpc/pre-* and /etc/udhcpc/post-* to be run before/after deconfig/renew/bound DHCP events. The custom scripts must be set as executable by root, e.g. chmod 744
. Refer an example custom script
Troubleshooting
Change default MTU for ADSL
As an example, /etc/udhcpc/post-bound/mtu could contain, to change the interface MTU from the default (1500) to 1492, which is useful if on ADSL that uses PPPoE (which uses 8 bytes for its own header):
r=$(/sbin/ip route | grep ^default | head -n 1) # Needs {{pkg|iproute2}} package, rather than busybox's "ip", to change mtu /sbin/ip route replace $r mtu 1492
I needed to restart my firewall (which replaces the iptables
script from Alpine) when the client binds to a new IP, so I added the following line in the function bound()
, right after 'resolvconf
':
# rc-service iptables reload
The reload drops all firewall rules, re-acquires the Internal and external IPs, and re-writes the rules. I'm sure there is a better way.