检查电脑网络是否畅通?

检查电脑网络是否畅通?

我创建了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) 上网络状态的最佳方法是什么?

答案1

检查 Linux 上网络状态的最佳方法是什么

ip 一个并确定UPDOWN

例如:

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

相关内容