當前位置: 首頁>>技術教程>>正文


networking – 是否有用於驗證/etc/network/interfaces文件的工具?

, ,

問題描述

我一直喜歡在部署新配置文件之前使用apachectl configtestnamed-checkconf之類的工具測試它們。

很少會出現錯誤,但是在部署之前發現錯誤可以消除任何影響。在背麵多次咬我的是/etc/network/interfaces;我似乎找不到能夠測試它的工具,並且在遠程計算機上重新啟動網絡以發現它不再可訪問非常煩人-尤其是當我們使用大量綁定和橋接時。

最佳回答

擴展到@jdthood’s answer

如果接口已經打開,您仍然可以使用此方法來驗證/etc/network/interfaces文件。例如,假設您有一個錯誤,您可能會看到以下內容:

$ sudo ifup --no-act eth0
/etc/network/interfaces:11: unknown method
ifup: couldn't read interfaces file "/etc/network/interfaces"

顯然,第11行有錯誤。太棒了。謝天謝地,我並沒有因為失去SSH訪問而跳出網絡!

如果一切正常,您將看到:

$ sudo ifup --no-act eth0
ifup: interface eth0 already configured

次佳回答

以下內容可能會滿足您的要求。

ifup --no-act eth0

第三種回答

如果您沒有eth0,它將無法正常工作,例如:

Ignoring unknown interface eth0=eth0.

但是,如果您這樣做:

ifup -a --no-act ; echo "status: $?"

使用確定的配置:

ifup -a --no-act ; echo "status: $?"
run-parts  /etc/network/if-pre-up.d
run-parts  /etc/network/if-up.d
status: 0

使用非正常配置:

ifup -a --no-act ; echo "status: $?"
/etc/network/interfaces:12: option with empty value
ifup: couldn't read interfaces file "/etc/network/interfaces"
status: 1

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/11758.html,未經允許,請勿轉載。