免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4227 | 回复: 0
打印 上一主题 下一主题

[网络配置] 网卡配置中auto与allow-hotplug区别 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-12-04 00:28 |只看该作者 |倒序浏览
本帖最后由 himBH 于 2018-12-04 00:29 编辑

网上的来源大部分是:
/etc/network/interfaces文件中一般用auto或者allow-hotplug来定义接口的启动行为。
auto
语法:
auto <interface_name>
含义:
在系统启动的时候启动网络接口,无论网络接口有无连接(插入网线),如果该接口配置了DHCP,则无论有无网线,系统都会去执行DHCP,如果没有插入网线,则等该接口超时后才会继续。
allow-hotplug
语法:
allow-hotplug <interface_name>
含义:
只有当内核从该接口检测到热插拔事件后才启动该接口。如果系统开机时该接口没有插入网线,则系统不会启动该接口,系统启动后,如果插入网线,系统会自动启动该接口。也就是将网络接口设置为热插拔模式。
手动重新启动网络
一般修改了网络配置文件后,会用以下命令重新启动网络
# /etc/init.d/networking restart
但从squeeze开始,此命令会有如下提示:
Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces … (warning).
Reconfiguring network interfaces…done.
如果设置接口为auto,虽然会有如此提示,但接口仍然会正确的启动。
如果接口设置为allow-hotplug则没有这么走运了,网络接口不会正确启动。这种情况下必须使用如下命令启动网络接口:
#ifup <interface_name>
而命令
#ifconfig <interface_name> up
也无法正确启动接口
所以allow-hotplug设置的接口最好如下方式重新启动网络接口,当然auto方式的接口也没问题:
#ifdown <interface_name> && ifup <interface_name>
特别是在ssh登录远程主机的情况下,一定要像上面这样在一条命令里执行ifdown和ifup,否则,如果先执行ifdown,则再也没有机会执行ifup了。
看来大多数情形下,网络接口还是用auto方式比较省心。

auto:            try to ip link set <dev> up  at boot.  Best choice for
                 anything PCIe/SoC.

allow-hotplug:   *wait* for kernel+drivers+udev to detect the device,
                 then ip link set <dev> up it.  The only thing that can
                 deal with annoying USB, SDIO, etc.

This can be kinda important when non-auto-loading stuff is involved, or
when network file systems are involved.

So, look at what *exact* kind of network device you're dealing with.


实际我用主机debian 9操作了一下,2种方式都行,奇怪的是auto获取dhcp的速度要慢一些,hot就很快。估计与主板或者网卡型号有关系。



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

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP