- 論壇徽章:
- 0
|
本帖最后由 himBH 于 2018-12-04 00:29 編輯
網(wǎng)上的來源大部分是:
/etc/network/interfaces文件中一般用auto或者allow-hotplug來定義接口的啟動(dòng)行為。
auto
語法:
auto <interface_name>
含義:
在系統(tǒng)啟動(dòng)的時(shí)候啟動(dòng)網(wǎng)絡(luò)接口,無論網(wǎng)絡(luò)接口有無連接(插入網(wǎng)線),如果該接口配置了DHCP,則無論有無網(wǎng)線,系統(tǒng)都會(huì)去執(zhí)行DHCP,如果沒有插入網(wǎng)線,則等該接口超時(shí)后才會(huì)繼續(xù)。
allow-hotplug
語法:
allow-hotplug <interface_name>
含義:
只有當(dāng)內(nèi)核從該接口檢測(cè)到熱插拔事件后才啟動(dòng)該接口。如果系統(tǒng)開機(jī)時(shí)該接口沒有插入網(wǎng)線,則系統(tǒng)不會(huì)啟動(dòng)該接口,系統(tǒng)啟動(dòng)后,如果插入網(wǎng)線,系統(tǒng)會(huì)自動(dòng)啟動(dòng)該接口。也就是將網(wǎng)絡(luò)接口設(shè)置為熱插拔模式。
手動(dòng)重新啟動(dòng)網(wǎng)絡(luò)
一般修改了網(wǎng)絡(luò)配置文件后,會(huì)用以下命令重新啟動(dòng)網(wǎng)絡(luò)
# /etc/init.d/networking restart
但從squeeze開始,此命令會(huì)有如下提示:
Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces … (warning).
Reconfiguring network interfaces…done.
如果設(shè)置接口為auto,雖然會(huì)有如此提示,但接口仍然會(huì)正確的啟動(dòng)。
如果接口設(shè)置為allow-hotplug則沒有這么走運(yùn)了,網(wǎng)絡(luò)接口不會(huì)正確啟動(dòng)。這種情況下必須使用如下命令啟動(dòng)網(wǎng)絡(luò)接口:
#ifup <interface_name>
而命令
#ifconfig <interface_name> up
也無法正確啟動(dòng)接口
所以allow-hotplug設(shè)置的接口最好如下方式重新啟動(dòng)網(wǎng)絡(luò)接口,當(dāng)然auto方式的接口也沒問題:
#ifdown <interface_name> && ifup <interface_name>
特別是在ssh登錄遠(yuǎn)程主機(jī)的情況下,一定要像上面這樣在一條命令里執(zhí)行ifdown和ifup,否則,如果先執(zhí)行ifdown,則再也沒有機(jī)會(huì)執(zhí)行ifup了。
看來大多數(shù)情形下,網(wǎng)絡(luò)接口還是用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.
實(shí)際我用主機(jī)debian 9操作了一下,2種方式都行,奇怪的是auto獲取dhcp的速度要慢一些,hot就很快。估計(jì)與主板或者網(wǎng)卡型號(hào)有關(guān)系。
|
|