Skip to content

Instantly share code, notes, and snippets.

@clyang
Last active August 20, 2023 01:21
Show Gist options
  • Save clyang/44ee7b6caca471d45b4c0ee2bc1d1aab to your computer and use it in GitHub Desktop.
Save clyang/44ee7b6caca471d45b4c0ee2bc1d1aab to your computer and use it in GitHub Desktop.
EdgeOS - Clean up useless IPv6 addresses after PPPoE is down/reconnected (/etc/ppp/ip-down.d)
#!/bin/sh
/sbin/ifconfig switch0 | grep -ivE 'fe80' | grep 'inet6' | awk '{print $3}' | while read -r ipv6addr ; do
echo "Removing $ipv6addr from switch0" >> /tmp/ipv6_remove.log
/sbin/ip -6 addr del $ipv6addr dev switch0
done
/etc/init.d/radvd restart
@BrianG61UK
Copy link

BrianG61UK commented Aug 15, 2023

{print $3} seems to need to be {print $2} now. Maybe ifconfig has changed. (I'm using firmware 2.0.9hf7)

I prefer search of 'global' over search for not 'fe80'. So it becomes:

#!/bin/sh

/sbin/ifconfig switch0 | grep 'inet6' | grep 'global' | awk '{print $2}' | while read -r ipv6addr ; do
    echo "Removing $ipv6addr from switch0" >> /tmp/ipv6_remove.log
    /sbin/ip -6 addr del $ipv6addr dev switch0
done
/etc/init.d/radvd restart

@BrianG61UK
Copy link

Here is a tiny script that can be placed in /config/scripts/firstboot.d which will re-add a print DeprecatePrefix on; to /opt/vyatta/sbin/vyatta_gen_radvd.pl immediately after a firmware update, assuming the firmware update hasn't drastically changed the way the original works. Just put it in a file such as fix.sh and make it executable.

#!/bin/sh
sed -i '/print $FD_WR "    prefix $prefix {\\n";/, +8 s/print $FD_WR "    };\\n";/print $FD_WR "        DeprecatePrefix on;\\n    };\\n";/g' /opt/vyatta/sbin/vyatta_gen_radvd.pl
exit 0

It doesn't matter if it accidentally gets run more than once during testing, it only changes the file once.

Note: It doesn't add another print statement, instead it just modifies the existing print statement. Don't run it if you've already added another print statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment