Skip to content

Instantly share code, notes, and snippets.

@raspi
Created October 20, 2017 18:42
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspi/54bd758a6e981d3379ad83c9458b0bcc to your computer and use it in GitHub Desktop.
Save raspi/54bd758a6e981d3379ad83c9458b0bcc to your computer and use it in GitHub Desktop.
Systemd service for pinging default gateway
# Save in /etc/systemd/system/network-ping-gateway.service
[Unit]
Description=Ping default network gateway service
After=network-online.target
[Service]
# Wait time if process hangs
TimeoutStopSec=1m
# Command to run
ExecStart=/bin/bash -c 'read _ _ gateway _ < <(ip route list match 0/0); ping -c 1 "$gateway"'
Type=simple
KillMode=process
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
# Timer which runs service
# Save in /etc/systemd/system/network-ping-gateway.timer
# Enable:
# systemctl enable /etc/systemd/system/network-ping-gateway.timer
# Start:
# systemctl start network-ping-gateway.timer
# Next run time:
# systemctl list-timers --all
[Unit]
Description=Ping network gateway timer
[Timer]
# Uptime after it's first ran
OnBootSec=1min
# Wait time for next run
OnUnitInactiveSec=1min
Unit=network-ping-gateway.service
Persistent=true
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment