linux使用dhcp获取本地IP,嵌入式Linux通过DHCP自动获取IP地址的方法

嵌入式Linux通过DHCP自动获取IP地址的方法

1.在编译嵌入式Linux内核时添加以下选项:

Networking --->

[*] Networking support

Networking options --->

Packet socket //添加.配置CONFIG_PACKET

[ * ] IP: DHCP support //添加

[ * ] Network packet filtering (replaces ipchains) ---> //添加,后面子选项可不选,配置CONFIG_NETFILTER

说明:若没选 Packet socket, [ * ] Network packet filtering (replaces ipchains) --->选项,在执行udhcpc命令时出现如下错误:

~ # udhcpc

udhcpc (v0.9.9-pre) started

udhcpc[208]: udhcpc (v0.9.9-pre) started

FATAL: couldn't listen on socket, Address family not supported by protocol

udhcpc[208]: FATAL: couldn't listen on socket, Address family not supported by protocol

2.在编译Busybox中添加以下选项:

Networking Utilities --->

udhcp Server/Client --->

[] udhcp Server (udhcpd) //在此不作服务端,故不选。生成udhcpd命令

[*] udhcp Client (udhcpc) //生成udhcpc命令

[ ] Lease display utility (dumpleases)

[ ] Log udhcp messages to syslog (instead of stdout)

[ ] Compile udhcp with noisy debugging messages

3.建相关配置文件

从busybox的examples/udhcp/下copy simple.script文件到开发板/usr/share/udhcpc/下,并重命名为default.script,udhcp_0.9.8cvs20050303.orig.tar.gz中也有这样的文件。

[root@localhost root]# vi usr/share/udhcpc/default.script

#!/bin/sh

# udhcpc script edited by Tim Riker

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

RESOLV_CONF="/etc/resolv.conf"

[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"

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

case "$1" in

deconfig)

/sbin/ifconfig $interface 0.0.0.0

;;

renew|bound)

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

if [ -n "$router" ] ; then

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值