嵌入式linux系统获取ip的方法
方法1:uboot中设置bootargs参数和内核发出dhcp请求,此种方法比较常用,在此省略...
方法2:进入系统后发出dhcp请求,下面介绍第2种方法
执行脚本.sh内容(通过判断/etc/nettype.conf和/etc/net.conf来配置动态ip或者静态ip)
source /etc/nettype.conf
if [ -f /etc/net.conf ] ; then
source /etc/net.conf
if [ $NETTYPE -eq 1 ] ; then
#............
if [ $DHCP -eq 1 ] ; then
#dhcp set eth0
ifconfig eth0 down
ifconfig eth0 hw ether $MAC
echo ifconfig eth0 hw ether $MAC >/dev/console
ifconfig eth0 up
udhcpc -b -i eth0
else
#manual set eth0
ifconfig eth0 down
ifconfig eth0 hw ether $MAC
echo ifconfig eth0 hw ether $MAC >/dev/console
ifconfig eth0 $IPADDR netmask $NETMASK up
echo ifconfig eth0 $IPADDR netmask $NETMASK up >/dev/console
route add default gw $GATEWAY
echo add default gw $GATEWAY >/dev/console
fi
2个相关的网络配置文件
/usr/local/apache/logs # vi /etc/nettype.conf
CDMAUSE=0
NETTYPE=1
MAC=00:80:C3:00:01:11
~
~
~
/usr/local/apache/logs # vi /etc/net.conf
IPADDR=192.168.26.170
NETMASK=255.255.254.0
GATEWAY=192.168.26.1
DHCP=0
~