LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1192|回复: 2

让ArchLinux的dhcp在开机后优先续用上次的IP[How TO]

[复制链接]
发表于 2006-3-12 13:55:58 | 显示全部楼层 |阅读模式
我使用的是DHCP网络,每次开机或者重启的时候,都要在网络那里等待很久,这个时候系统在使用dhcpcd重新向服务器申请一个动态IP.

根据以前的经验,windows xp 和安装了dhcpcd的debian linux 在每次重新启动配置网络的时候,都是采用优先续用dhcp cache里面的IP, 也就是上次的IP ,这样可以提高配置网络的速度。

dhcpcd的manual里面写着dhcpcd默认会自动优先续用cache里面的IP.

  1.        -s [ipaddr]
  2.               Sends DHCP_INFORM message to DHCP server using ipaddr.  The optional ipaddr parameter must
  3.               be in the form xxx.xxx.xxx.xxx.  If no ipaddr parameter  is  given  on  the  command  line
  4.               dhcpcd  will  use  the  IP address currently assigned to the interface.  If there is no IP
  5.               address currently assigned to the interface dhcpcd will use previously obtained IP address
  6.               stored in <ConfigDir>/dhcpcd-<interface>.cache file.
复制代码


我检查了一下/etc/rc.d/network ,发现里面在每次启动dhcpcd之前吧它的cache删除掉了。所以才会出现上面提到的那种情况。

解决方法:直接修改一下/etc/rc.d/network就好了

  1. ifup()
  2. {
  3.   if [ "$1" = "" ]; then
  4.     echo "usage: $0 ifup <interface_name>"
  5.     return 1
  6.   fi
  7.   # don't bring up an interface that's already up
  8.   [ "`/sbin/ifconfig ${1} 2>/dev/null | grep UP`" ] && return 0
  9.   eval iwcfg="\$wlan_${1}"
  10.   if [ "$iwcfg" != "" ]; then
  11.     /usr/sbin/iwconfig $iwcfg
  12.     /bin/sleep 2
  13.   fi
  14.   eval ifcfg="\$${1}"
  15.   if [ "$ifcfg" = "dhcp" ]; then
  16.     # remove the .pid file if it exists
  17.     [color="Red"]rm -f /etc/dhcpc/dhcpcd-${1}.{pid}[/color] >/dev/null 2>&1
  18.     /sbin/dhcpcd $DHCPCD_ARGS ${1}
  19.   else
  20.     /sbin/ifconfig $ifcfg
  21.   fi
  22.   return $?
  23. }
复制代码


修改部分就是上面红色那行,修改之前为
rm -f /etc/dhcpc/dhcpcd-${1}.{pid,cache}
发表于 2006-3-12 15:20:51 | 显示全部楼层
For what reason does Arch packager remove dhcp's cache when reboot? Security or anything else, Could you add a bug tracker for this to ask maintainer why?
回复 支持 反对

使用道具 举报

发表于 2006-3-13 17:13:26 | 显示全部楼层
这么好的文章斑竹怎么不设精华阿,我都快被这样的问题给郁闷死了,校园网需要登陆网关才能出校外,所以每次重启都换IP搞得我很郁闷。向lnzju学习并致敬。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表