+ -
当前位置:首页 → 问答吧 → [自己搞定]FreeBSD 开机自适应网卡DCHP获取 shell

[自己搞定]FreeBSD 开机自适应网卡DCHP获取 shell

时间:2011-05-19

来源:互联网

本帖最后由 ahyate 于 2011-05-19 10:34 编辑

FreeBSD 8.2

因为有台机器没有显示器, 想弄个bsd进去.

所以,想弄个自适应网卡的shell, 开机的时候,自动运行,识别网卡名称,
然后把网卡dhcp获取ip,如果有多个网卡,就都dhcp

请问这个shell,该如何写呢.

我是这样的,

获取 每个网卡名称: ifconfig -l
下载 (582 Bytes)
2011-05-19 10:30


然后弄个循环
  1. #!/bin/sh
  2. ListInter=`ifconfig -l`
  3. for inter in $ListInter
  4.     do
  5.         echo $ListInter
  6.         dhclient $ListInter
  7.     done
复制代码
这里有个问题是 想lo0, plip0 这些不需要的网卡,怎么去排除呢....
怎么判断?
是去掉后面的数字,然后判断名称是否匹配定义的 lo plip 不dhcp.如果这样的话, 如何去掉后面的数字呢......好像没有 right() left()截取之类的东西.
还是有别的方法?

算啦.自己搞定,就直接判断名字算了........先凑合用了
下载 (3.62 KB)
2011-05-19 10:20

作者: ahyate   发布时间: 2011-05-19

ifconfig -l ?? 不知道楼主用的什么系统,我这儿没有这个参数
这样不知道是不是你想要的结果:
ifconfig -a|grep Ethernet|cut -d" " -f1

作者: dzhxc   发布时间: 2011-05-19

什么系统啊?设置网卡dhcp要自己写脚本?

作者: waker   发布时间: 2011-05-19

本帖最后由 ahyate 于 2011-05-19 09:52 编辑

FreeBSD 8.2

ifconfig -l 就可以出来网卡列表了

作者: ahyate   发布时间: 2011-05-19



QUOTE:
什么系统啊?设置网卡dhcp要自己写脚本?
waker 发表于 2011-05-19 09:45



FreeBSD 开机没设置的话,是不会自动DHCP的啊....

作者: ahyate   发布时间: 2011-05-19

本帖最后由 ahyate 于 2011-05-19 10:33 编辑

谢谢 楼上两位,热心帮助哦.
  1. #!/bin/sh
  2. ListInter=`ifconfig -l`

  3. for inter in $ListInter
  4.   do
  5.     echo $inter   
  6.     echo "========== DHCP $inter ============"
  7.     if [ $inter != "lo0" ] && [ $inter != "plip0" ]; then
  8.       dhclient $inter
  9.     else
  10.       echo "***** Noting *****"
  11.     fi
  12.     echo -e "========== DHCP $inter ============\n\n"
  13.   done
复制代码

作者: ahyate   发布时间: 2011-05-19