udhcpc 命令 获得IP地址(笔记本 机顶盒 通过路由器DHCP 上网)
【摘要】
[gx@ development_ipanel0630]cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolve...
[gx@ development_ipanel0630]cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
[gx@ development_ipanel0630]sudo ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 2
Transceiver: internal
Auto-negotiation: on
MDI-X: on
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
笔记本 机顶盒 通过路由器DHCP 上网
1.default.script
22.sh
F:\gx3201\t2\T2with_wifi_code\linux\gx3201_rootfs\usr\share\udhcpc
#!/bin/sh
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
RESOLV_CONF="/home/gx/resolv.conf"
[ -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 "Setting IP address 0.0.0.0 on $interface"
ifconfig $interface 0.0.0.0
;;
renew|bound)
echo "Setting IP address $ip on $interface"
ifconfig $interface $ip $NETMASK $BROADCAST
if [ -n "$router" ] ; then
echo "Deleting routers"
while route del default gw 0.0.0.0 dev $interface ; do
:
done
metric=0
for i in $router ; do
echo "Adding router $i"
route add default gw $i dev $interface metric $((metric++))
done
fi
echo "Recreating $RESOLV_CONF"
echo -n > $RESOLV_CONF-$$
[ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF-$$
for i in $dns ; do
echo " Adding DNS server $i"
echo "nameserver $i" >> $RESOLV_CONF-$$
done
mv $RESOLV_CONF-$$ $RESOLV_CONF
;;
esac
exit 0
2.UBUNTU 执行脚本
[xushx@ dd]vi /usr/share/udhcpc/default.script
[xushx@ dd]sudo ./22.sh
udhcpc (v1.18.5) started
0=/usr/share/udhcpc/default.script 1=deconfig
bro=
subnet=
router=
hihi=eth0 BROADCAST= NETMASK=
Sending discover...
Sending select for 192.168.1.2...
Lease of 192.168.1.2 obtained, lease time 86400
0=/usr/share/udhcpc/default.script 1=bound
bro=
subnet=255.255.255.0
router=192.168.1.1
hihi=eth0 192.168.1.2 BROADCAST= NETMASK=
/usr/share/udhcpc/default.script: Resetting default routes
SIOCDELRT: 没有那个进程
/usr/share/udhcpc/default.script: Adding DNS 192.168.1.1
[xushx@ dd]vi 22.sh
[xushx@ dd]cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.1.1
nameserver 127.0.0.1
[xushx@ dd]netstat -r
内核 IP 路由表
Destination Gateway Genmask Flags MSS Windowirtt Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U0 0 0 eth0
192.168.188.0 * 255.255.255.0 U0 0 0 wlan0
[xushx@ dd]route -n
内核 IP 路由表
目标 网关 子网掩码 标志 跃点 引用 使用 接口
0.0.0.0192.168.1.1 0.0.0.0 UG0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U0 0 0 eth0
192.168.188.0 0.0.0.0 255.255.255.0 U2 0 0 wlan0
文章来源: blog.csdn.net,作者:悟空胆好小,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/xushx_bigbear/article/details/123364760
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)