2011/05/29

DHCP Config

How to configure DHCP client of a embedded Linux device running a busy box?

1. Make sure you have udhcpc installed.
2. Find the configuration file at busybox-1.13.3 (this is the version of udhcp on my platform) /examples/udhcp/sample.renew.
3. Copy a configuration file to /usr/share/udhcpc/default.script, and change the RESOLV_CONF path to /etc/resolv.conf the content of the file looks like below:

#!/bin/sh # Sample udhcpc bound script RESOLV_CONF="/etc/resolv.conf" [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" [ -n "$subnet" ] && NETMASK="netmask $subnet" /sbin/ifconfig $interface $ip $BROADCAST $NETMASK if [ -n "$router" ] then echo "deleting routers" while /sbin/route del default gw 0.0.0.0 dev $interface do : done metric=0 for i in $router do /sbin/route add default gw $i dev $interface metric $((metric++)) done fi echo -n > $RESOLV_CONF [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF for i in $dns do echo adding dns $i echo nameserver $i >> $RESOLV_CONF done


4. To get the new ip
#udhcpc eth0

reference:
http://tinyurl.com/3pd45s8

No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...