您的位置:首页 > 其它

udhcpc遇到问题

2015-09-18 11:45 253 查看
udhcpc -i eth0 

手动运行该命令时,能接收来自DHCP服务器分配的IP地址,但是接收到的IP地址却没有设置到网口eth0,同时dns配置也没有修改。输入ifconfig命令,IP地址为空。

查阅相关资料,发现设备端没有移植dhcpc对应的脚本文件。

解决:在/user/share下建立udhcpc目录,并创建四个文件

-rwxrwxrwx 1 root root    2 Sep 18 10:43 config

-rwxrwxrwx 1 root root    0 Sep 18 10:45 .count (空)

-rwxrwxrwx 1 root root 4559 Sep 18 11:27 default.script

-rwxrwxrwx 1 root root    2 Sep 18 10:44 done

root@ubuntu:/home/nfs/ov9732_hi3518e/udhcpc# cat default.script
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>

RESOLV_CONF="/etc/resolv.conf"
DHCP_CONFIG="/usr/share/udhcpc"
DHCP_READ_FILE=$DHCP_CONFIG/config
DHCP_WRITE_FILE=$DHCP_CONFIG/done
config="/usr/share/udhcpc/.count"

#echo "got input $1"
#echo "interface is $interface"

[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }

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

case "$1" in
deconfig)
echo 0>$config
cat $config
echo "Setting IP address 0.0.0.0 on $interface"
ifconfig $interface 0.0.0.0
;;

renew|bound)
read type <$DHCP_READ_FILE
echo "Setting IP address $ip on $interface"
ifconfig $interface $ip $NETMASK $BROADCAST

#if [ "$type" == "0" ] && [ "$interface" == "eth0" ]; then
#  UPDATE_ROOT=yes
#elif [ "$type" == "1" ] && [ "$interface" == "ra0" ]; then
#  UPDATE_ROOT=yes
#else
UPDATE_ROOT=yes
#fi

if [ "$UPDATE_ROOT" == "yes" ]; then

echo " need update route and dns with $interface"
if [ -n "$router" ] ; then

echo "Deleting routers"
#while route del default gw 0.0.0.0 dev $interface ; do
#       :
#done

#echo "sleep 5 seconds to wait link up: try once"
#sleep 5

#metric=0
#for i in $router ; do
#       echo "Adding router $i"
#       route add default gw $i dev $interface metric $((metric++))
#done

#echo "sleep 5 seconds to wait link up: try again"
#sleep 5

metric=0
for i in $router ; do
echo "Adding router $i"
route add default gw $i dev $interface metric $((metric++))
if [ "$interface" == "eth0" ]; then
echo "gw $i" > "/tmp/gw0"
else
echo "gw $i" > "/tmp/gw1"
fi
done
fi

echo "Recreating $RESOLV_CONF"
echo -n > $RESOLV_CONF-$$
if [ "$interface" == "eth0" ]; then
echo -n > "/tmp/dns0"
[ -n "$domain" ] && echo "search $domain" >> "/tmp/dns0"
else
echo -n > "/tmp/dns1"
[ -n "$domain" ] && echo "search $domain" >> "/tmp/dns1"
fi
#[ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF-$$
rm /etc/resolv.conf
for i in $dns ; do
echo " Adding DNS server $i"
echo "nameserver $i" >> $RESOLV_CONF-$$
if [ "$interface" == "eth0" ]; then
echo "dns $i" >> "/tmp/dns0"
else
echo "nameserver $1" >> "/etc/resolv.conf"
echo "dns $i" >> "/tmp/dns1"
fi
done
echo "Set DNS config"
mv $RESOLV_CONF-$$ $RESOLV_CONF
echo "DHCP over,send msg to netmgmt"
#                        /home/sendMq 0x80 0x1 0x1ffe 0x1 &
else
echo "needn't update route to $router"
fi
echo 1 > $DHCP_WRITE_FILE
;;

esac

exit 0
root@ubuntu:/home/nfs/ov9732_hi3518e/udhcpc# cat config
1

root@ubuntu:/home/nfs/ov9732_hi3518e/udhcpc# cat done
1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: