Skip to content

Instantly share code, notes, and snippets.

@imlk0
Created August 30, 2022 01:08
Show Gist options
  • Save imlk0/a2074e5ecab50b3232b08f757af20762 to your computer and use it in GitHub Desktop.
Save imlk0/a2074e5ecab50b3232b08f757af20762 to your computer and use it in GitHub Desktop.
Upload this file to /etc/hotplug.d/iface/
#!/bin/sh
# imlk: setup ipv6 bridge while ipv4 is nat mode. see https://jethro.fun/index.php/archives/162/
logger -t imlk-ebtables-ipv6 "hotplugin event: $INTERFACE -> $ACTION"
if [[ "$INTERFACE" != "wan" ]]; then
exit
fi
case "$ACTION" in
ifup)
logger -t imlk-ebtables-ipv6 "setup ipv6 passthrough ..."
# force non-ipv6 packet to be routed
ebtables -t broute -A BROUTING -p ! ipv6 -j DROP -i eth0.2
# drop some bad devices in UCAS
ebtables -t filter -A FORWARD --src 5c:02:14:73:1c:b6 -j DROP
ebtables -t filter -A FORWARD --src 8c:de:f9:ec:92:be -j DROP
ebtables -t filter -A FORWARD --src 54:ee:75:f2:85:12 -j DROP
brctl addif br-lan eth0.2
logger -t imlk-ebtables-ipv6 "setup ipv6 passthrough done!"
;;
ifdown)
logger -t imlk-ebtables-ipv6 "revert ipv6 passthrough ..."
brctl delif br-lan eth0.2
ebtables -t broute -D BROUTING -p ! ipv6 -j DROP -i eth0.2
logger -t imlk-ebtables-ipv6 "revert ipv6 passthrough done!"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment