My Tech notes: Configure udhcpc for Setting IP netmask and Gateway

Unix Documentation

Free Online Unix Training Materials

Lists many links to free Unix training materials.

Pointers and Arrays Materials

Pointers and Arrays materials Explained for C beginners

C FAQ and General Questions C Interview Questions

Powered By

Free XML Skins for Blogger

Powered by Blogger

Monday, April 20, 2009

Configure udhcpc for Setting IP netmask and Gateway

How to Configure udhcpc for Setting IP netmask and Gateway?
Tell udhcpc client to run on eht1 interface with -i option.
Also use -s option to tell udhcpc client to use script from specified path.
/sbin/udhcpc -i eth1 -p /var/run/ -s /usr/share/udhcpc-wifi/default.script &

default.script directs the udhcpc to executes one by one scripts from specified folder ie /usr/share/udhcpc-wifi/
else default folder location for udhcpc script is /usr/share/udhcpc/

For directing IP address to temp file obtained using udhcpc client or for DHCP, do little
modification in sample.bound file.
Here is Sample udhcpc renew script, which will update the ip address, netmask and gatway obtained
by boradcasting. The new values will be updataed in /var/dhcpfile.

# Sample udhcpc renew script


[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet

echo $ip > /var/dhcpfile
echo $subnet >> /var/dhcpfile

/sbin/ifconfig $interface $ip $BROADCAST $NETMASK

if [ -n "$router" ]
echo "deleting routers"
while /sbin/route del default gw dev $interface
do :

for i in $router
/sbin/route add default gw $i dev $interface
echo $i > /var/dhcp_gw_wifi

Same file can be extended to work on multiple interfaces link eth0 eth1 using $interface


if [ "$interface" == "eth0" ];
echo $ip > /var/dhcpfile
echo $subnet >> /var/dhcpfile
echo $ip > /var/dhcpfile1
echo $subnet >> /var/dhcpfile1

No comments:

Post a Comment