So... for those unlucky ones who have a specific PPPoE link, and when that link goes down, for some reason, they need to reboot to get the link working again, I wrote a very simple script to do this automatically, without the need of user intervention. The script reboots the OPNsense box a customizable number of times if the PPPoE interface goes down and never gets and IPv4 from the ISP. It's not ideal, but until Franco comes up with a solution... this is good enough for me.
Here's the script:
#!/bin/sh
#####################################################
# NUMBER OF REBOOTS TO PERFORM IF PPPOE HAS NO IPv4 #
#####################################################
rebootnr=10;
###################################################
sleep 60
dtstart=$(date '+%d/%m/%Y %H:%M:%S');
echo "Started at $dtstart" > /root/pppoerebootlog.txt
[ -e /root/pppoerebootcount.txt ] || echo "0" > /root/pppoerebootcount.txt;
pppoeif=$(ifconfig pppoe0 | grep "inet ")
if [ ! -z "$pppoeif" ]; then
echo "IPv4: $pppoeif" >> /root/pppoerebootlog.txt;
echo "0" > /root/pppoerebootcount.txt;
else
pppoerebootcount=$(head -1 /root/pppoerebootcount.txt);
echo $(((pppoerebootcount+=1))) > /root/pppoerebootcount.txt;
fi
sleep 1
pppoerebootcount=$(head -1 /root/pppoerebootcount.txt);
if [ "$pppoerebootcount" -gt "0" ] && [ "$pppoerebootcount" -le "$rebootnr" ]; then
echo "$dtstart PPPoE down, rebooting..." > /root/pppoe_lastreboot.txt
echo "PPPoE down, rebooting..." >> /root/pppoerebootlog.txt
sleep 1
reboot
else
if [ "$pppoerebootcount" -le "$rebootnr" ]; then
echo "Franco, all good, PPPoE is up, no need to reboot" >> /root/pppoerebootlog.txt
else
echo "We reached the max number of reboots!" >> /root/pppoerebootlog.txt
fi
fi
1. Create a file on your PC with this content and save it as a shell script (pppoe.sh for example - the tutorial & script will use this name and also the /root folder)
2. IMPORTANT: If you are using a Windows machine, you need to take care of the EOL conversion. If you are using Notepad++, go to Edit > EOL Conversion > select Unix (LF) and save the file
3. Login with your root user, upload the script (using WinSCP for example) to your OPNsense box in the /root folder and issue this command from the shell (from WinSCP or putty for example): chmod +x /root/pppoe.sh
4. Create an action conf file in /usr/local/opnsense/service/conf/actions.d/, for example actions_pppoereboot.conf with this content (also taking care of EOL conversion):
[pppoereboot]
command:/root/pppoe.sh
parameters:
type:script
message:Check if PPPoE is down, reboot if it is
description:Check if PPPoE is down, reboot if it is
5. From the shell, issue this command: service configd restart
6. In the WebGUI (refresh the page if already there), go to System: Settings: Cron and click on the + sign
7. Add a cron job similar to the attached snapshot, selecting as command to execute "Check if PPPoE is down, reboot if it is" (it will execute the script every 5 minutes)
8. Save and verify the script is working - disconnect the WAN cable or disconnect the PPPoE link from the web interface or bring down the pppoe interface from ssh (read below)
The script basically verifies if the PPPoE interface has an IPv4 address. If not, it will reboot the OPNsense box a number of times. If the PPPoE link has no IPv4 address and the box was restarted up to (and including) the configured number of reboots, it will stop rebooting the box to avoid infinite reboots. You can customize that number by changing "rebootnr=10;" in the script.
It also creates some extremely basic files, in the /root folder:
- pppoerebootcount.txt > keeps the number of reboots
- pppoerebootlog.txt > keeps some very basic logging
- pppoe_lastreboot.txt > keeps the last reboot occured because of the broken PPPoE link
Verified and working on my OPNsense 18.1.2_2 :-)
Good luck :)
This is only valid for 18.1 (so far), probably because of FreeBSD 11.1. OPNsense 17.7.12 is almost fine, only IPv6 is lost after a PPPoE reconnect until a reboot and it's not yet confirmed that it happens because of OPNsense.
Update: if you have the loops and you've set custom MTU/MSS (even if valid) for the WAN interface, clear them and check if the loops occur again. This fixed the PPPoE reconnect loop & the loss of IPv6 for me.
Updated the script nevertheless, it had some design flaws :)
Hi elektroinside,
where can I find the latest version of your script. Is it in your first post?
Thanks.
Hi,
Yes, the one in the first post. It is now updated to the latest version. But I just saw another flaw in the logic :) I think it will continuously restart the box if the link never goes up, even after the restart. I'll update it today.
Done, this latest version should do it :)