Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Created August 2, 2019 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanpuyue/43b8a4e6722d575b4de1e2baa58e8d82 to your computer and use it in GitHub Desktop.
Save nanpuyue/43b8a4e6722d575b4de1e2baa58e8d82 to your computer and use it in GitHub Desktop.
#!/bin/sh
# date: 2019-08-02
# license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
# author: nanpuyue <nanpuyue@gmail.com> https://blog.nanpuyue.com
MARK=404
TABLE=404
SETNAME="surfing telegram"
VERBOSE=0
iptables(){
case $* in
*-A*|*-I*)
if command iptables $(echo $@|sed -r 's/(-A)|(-I)/-C/') 2>/dev/null; then
return 0
else
[ "$VERBOSE" = 1 ] && echo iptables "$@"
command iptables $@
fi
;;
*-D*)
if command iptables $(echo $@|sed -r 's/-D/-C/') 2>/dev/null; then
[ "$VERBOSE" = 1 ] && echo iptables "$@"
command iptables $@
else
return 0
fi
;;
*)
[ "$VERBOSE" = 1 ] && echo iptables "$@"
command iptables $@
;;
esac
}
up() {
for setname in $SETNAME; do
for chain in PREROUTING OUTPUT; do
iptables -t mangle -I $chain -m set --match-set $setname dst -j MARK --set-mark $MARK
done
done
ip route add default via $route_vpn_gateway dev $dev table $TABLE
ip rule add fwmark $MARK table $TABLE
}
down() {
for setname in $SETNAME; do
for chain in PREROUTING OUTPUT; do
iptables -t mangle -D $chain -m set --match-set $setname dst -j MARK --set-mark $MARK
done
done
ip route del default via $route_vpn_gateway dev $dev table $TABLE
ip rule del fwmark $MARK table $TABLE
}
case $script_type in
up)
up
;;
down)
down
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment