Plaidstallion

OPNsense reset WAN if no IP

Dec 21st, 2020 (edited)
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. # /usr/local/sbin/checkwan.sh
  2. ###################################
  3.  
  4. #!/bin/sh
  5.  
  6. gatewayIP=$(netstat -4rn | grep default | awk '{print $2}')
  7. wanInterface="igb1"
  8.  
  9. echo "Gateway: $gatewayIP"
  10. echo "WAN Interface: $wanInterface"
  11. if [ -z $gatewayIP ]
  12. then
  13. echo "NO Gateway"
  14. #Bring the interface down then up to renew the WAN DHCP
  15. ifconfig $wanInterface down
  16. ifconfig $wanInterface up
  17. else
  18. # if return = 0 then host is reachable
  19. ping -c 1 $gatewayIP > /dev/null
  20. if [ $? -eq 0 ]
  21. then
  22. echo "Gateway Reachable"
  23. else
  24. echo "Gateway Unreachable"
  25. #Bring the interface down then up to renew the WAN DHCP
  26. ifconfig $wanInterface down
  27. ifconfig $wanInterface up
  28. fi
  29. fi
  30.  
  31. ######################################
  32.  
  33. #/usr/local/opnsense/service/conf/actions.d/actions_checkwan.conf
  34.  
  35. #####################################
  36. [load]
  37. command:/usr/local/sbin/checkwan.sh
  38. parameters:%s
  39. type:script
  40. description:Check WAN Interface for IP and reset if none
  41. message:Resetting WAN Interface for DHCP retrieval
Add Comment
Please, Sign In to add comment