Linux 持续ping网关防止wifi掉线

nano /etc/systemd/system/network-ping-gateway.service
添加以下内容

# Save in /etc/systemd/system/network-ping-gateway.service

[Unit]
Description=Ping default network gateway service
After=network-online.target

[Service]
ExecStart=/bin/bash -c 'read _ _ gateway _ < <(ip route list match 0/0); ping "$gateway"'
Type=simple

[Install]
WantedBy=multi-user.target

执行
systemctl enable network-ping-gateway
systemctl start network-ping-gateway