Skip to content

Instantly share code, notes, and snippets.

@Markieta
Last active September 22, 2025 22:24
Show Gist options
  • Select an option

  • Save Markieta/f2d6d677500603296d03168d57b49f5b to your computer and use it in GitHub Desktop.

Select an option

Save Markieta/f2d6d677500603296d03168d57b49f5b to your computer and use it in GitHub Desktop.
Dynamically update Google IP set for firewall4 (nftables) in OpenWrt.
#!/usr/bin/env ash
FILE4=/tmp/google-ipv4
FILE6=/tmp/google-ipv6
GOOG=$(curl -s https://www.gstatic.com/ipranges/goog.json)
IPV4=$(echo "$GOOG" | jq ".prefixes.[].ipv4Prefix | select( . != null )" -r)
IPV6=$(echo "$GOOG" | jq ".prefixes.[].ipv6Prefix | select( . != null )" -r)
reload=false
if ! diff $FILE4 <(echo "$IPV4") > /dev/null; then
echo "$IPV4" > $FILE4
reload=true
fi
if ! diff $FILE6 <(echo "$IPV6") > /dev/null; then
echo "$IPV6" > $FILE6
reload=true
fi
if [ "$reload" = true ]; then
fw4 -q reload-sets
fi
@Markieta
Copy link
Author

Maybe need to replace fw4 -q reload-sets with service firewall restart

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