Automatically fix IPv6 configuration when another process disables it
Use these scripts to watch directories, and have stuff launch quickly.

I had a problem where Freedom.to was turning my IPv6 off. This is not good™ because I work at Facebook, where many of our servers run IPv6 exclusively. So..... I wrote a quick thing to fix this on MacOS X. Essentially, it listens to the folder /Library/Preferences/SystemConfiguration
and then runs a script every time it changes. This means every time freedom.to ruins my IPv6 configuration, this little agent fixes it.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>dev.randallb.fixipv6</string>
<key>ProgramArguments</key>
<array>
<string>/Users/randallb/fixipv6.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration</string>
</array>
</dict>
</plist>
and the script
#!/bin/bash
networksetup -setv6automatic Wi-Fi && networksetup -setv6automatic Ethernet
syslog -s -l notice "fixed IPV6"
Once you've got all the files in place, make sure to chmod +x
on your fixipv6.sh
script, and then run:
launchctl load ~/Library/LaunchAgents/dev.randallb.fixipv6.plist
Also I put my launch agent in my ~/Library/LaunchAgents
folder.
Good luck!
Photo by Shahadat Shemul on Unsplash