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/dhcpClient-wifi.pid -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.
#!/bin/sh
# Sample udhcpc renew script
RESOLV_CONF="/etc/resolv.conf"
[ -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" ]
then
echo "deleting routers"
while /sbin/route del default gw 0.0.0.0 dev $interface
do :
done
for i in $router
do
/sbin/route add default gw $i dev $interface
echo $i > /var/dhcp_gw_wifi
done
fi
Same file can be extended to work on multiple interfaces link eth0 eth1 using $interface
example
if [ "$interface" == "eth0" ];
then
echo $ip > /var/dhcpfile
echo $subnet >> /var/dhcpfile
else
echo $ip > /var/dhcpfile1
echo $subnet >> /var/dhcpfile1
fi
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/dhcpClient-wifi.pid -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.
#!/bin/sh
# Sample udhcpc renew script
RESOLV_CONF="/etc/resolv.conf"
[ -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" ]
then
echo "deleting routers"
while /sbin/route del default gw 0.0.0.0 dev $interface
do :
done
for i in $router
do
/sbin/route add default gw $i dev $interface
echo $i > /var/dhcp_gw_wifi
done
fi
Same file can be extended to work on multiple interfaces link eth0 eth1 using $interface
example
if [ "$interface" == "eth0" ];
then
echo $ip > /var/dhcpfile
echo $subnet >> /var/dhcpfile
else
echo $ip > /var/dhcpfile1
echo $subnet >> /var/dhcpfile1
fi
Comments