Skip to content

Instantly share code, notes, and snippets.

@stigok
Last active July 4, 2017 08:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stigok/3fa59736d00a5c008bb56da5fa14825f to your computer and use it in GitHub Desktop.
Save stigok/3fa59736d00a5c008bb56da5fa14825f to your computer and use it in GitHub Desktop.
ip6tables restore script for /etc/network/if-up.d
#!/bin/bash
#
# Restores ip6tables configuration.
# Expected to reject everything BUT:
# - icmpv6 from anywhere
# - ssh (22/tcp) from a whitelisted ipv6 subnet
# - openvpn (1094/udp) from anywhere
#
# stigok, july 2017
ALLOW_SSH_FROM='5afe:b10c::/64'
IFACE=eth2
cat << ENDRULES | ip6tables-restore
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -i $IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -i $IFACE -p tcp -m tcp --dport 22 -s ${ALLOW_SSH_FROM} -m state --state NEW -j ACCEPT
-A INPUT -i $IFACE -p udp -m udp --dport 1094 -m state --state NEW -j ACCEPT
-A INPUT -p ipv6-icmp -j ACCEPT
-A INPUT -j REJECT --reject-with icmp6-port-unreachable
-A FORWARD -j REJECT --reject-with icmp6-port-unreachable
COMMIT
ENDRULES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment