Linux
檢查網路是否在電腦上?
我創建了這個
ipload
工具來簡化我的防火牆設置。特別是,我在保持我的規則正確時遇到了很多問題*(*即在管理超過 3 台電腦時以正確的順序和正確更新)。Ubuntu 軟體包包含一個
ipload.service
文件(縮寫),如下所示:[Unit] Description=IP Load -- load the firewall after boot Wants=network-pre.target systemd-modules-load.service local-fs.target Before=network-pre.target After=systemd-modules-load.service local-fs.target [Service] ExecStart=/usr/sbin/ipload --load [Install] WantedBy=multi-user.target
很明顯,我要求系統
ipload
在網路設置之前啟動(Before=network-pre.target
)。但是,我想驗證確實是這種情況,如果我ipload
在重新啟動後執行時檢測到網路已經啟動並執行,則會發出警告。在 Linux(Ubuntu)上檢查網路狀態的最佳方法是什麼?
在 Linux 上檢查網路狀態的最佳方法是什麼
ip a並辨識
UP
和DOWN
例如:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group 2: em1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN 3: em3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP 4: em2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN 5: em4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP 6: enp0s20f0u12: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000 7: ib0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 4092 qdisc mq state DOWN # this is stripped syntax to facilitate posting here, # the MAC address along with an ip address will also be # displayed... the ip address only if relevant
如何整合到您的 systemd 服務中,idk