Skip to content

สร้าง Static Route บน Ubuntu


#!/bin/sh
#modified from https://openwrt.org/docs/guide-user/base-system/cron
#modified to use logger for global logging instead of scriptlogfile & added infinite reboot protection for reboot
# Prepare vars
DATE=$(date +%Y-%m-%d” “%H:%M:%S)
#logFile=”/persistlogs/syslog”
# Ping and reboot if needed
#YOUR WIREGUARD PEER
CHECKHOSTNAME=”10.1.100.1″
notification_email=”itdhivii@gmail.com”
VPNINTERFACE=”10.1.100.0/22″

ping -c3 $CHECKHOSTNAME

if [ $? -eq 0 ]; then
echo “ok”
# curl -X POST -H “Authorization: Bearer SUguU4HiPpnT0ldnuR1X5OwmXyHF5eYJoPVm7Npv3x7” -F “message=${DATE} – $0: OK – $VPNINTERFACE Added AND RUNNING” https>
else
# echo “RESTART wg0 Interface”
# logger $(echo “${DATE} – $0: NO Route CONNECTION RESTART $VPNINTERFACE INTERFACE…”)
# Note: To avoid infinite reboot loop, wait 70 seconds and touch a file in /etc
ip route add 10.1.100.0/22 via 10.73.16.186 dev eth0

# echo Subject: $0: VPN $VPNINTERFACE has been restarted | sendmail -v “$notification_email”
curl -X POST -H “Authorization: Bearer SUguU4HiPpnT0ldnuR1X5OwmXyHF5eYJoPVm7Npv3x7” -F “message=${DATE} – $VPN Route to VPN has been added” https://notif>fi

เสร็จแล้ว สร้าง Crontab
* * * * * /home/add_route.sh

Tags: