Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # Standard IPv6 Firewall Script
- # Designed for Slackware Linux 15.0
- # Reddit u/cyranix, r/slackware
- # Released without any license for use/modification by the general public
- #
- # It can be executed with the typical start and stop arguments.
- # If used with stop, it will stop after flushing the firewall.
- # The save and restore arguments will save or restore the rules
- # from the /etc/sysconfig/iptables file. The save and restore
- # arguments are included to preserve compatibility with
- # Redhat's or Fedora's init.d script if you prefer to use it.
- # You may want to save this script as /etc/rc.d/rc.firewall6
- # and make it executable, like this:
- # chmod +x /etc/rc.d/rc.firewall6
- # Slackware Linux will then automatically run this script
- # with the "start" parameter.
- ###############################################################################
- #
- # Local Settings
- #
- # IPTables Location - adjust if needed
- IP6T="/usr/sbin/ip6tables"
- IP6TS="/usr/sbin/ip6tables-save"
- IP6TR="/usr/sbin/ip6tables-restore"
- # Save and Restore arguments handled here
- if [ "$1" = "save" ]
- then
- echo -n "Saving firewall to /etc/sysconfig/iptables ... "
- $IP6TS > /etc/sysconfig/ip6tables
- echo "done"
- exit 0
- elif [ "$1" = "restore" ]
- then
- echo -n "Restoring firewall from /etc/sysconfig/iptables ... "
- $IP6TR < /etc/sysconfig/ip6tables
- echo "done"
- exit 0
- fi
- ###############################################################################
- #
- # Load Modules
- #
- echo "Loading kernel modules ..."
- # You should uncomment the line below and run it the first time just to
- # ensure all kernel module dependencies are OK. There is no need to run
- # every time, however.
- # /sbin/depmod -a
- # Unless you have kernel module auto-loading disabled, you should not
- # need to manually load each of these modules. Other than ip_tables,
- # ip_conntrack, and some of the optional modules, I've left these
- # commented by default. Uncomment if you have any problems or if
- # you have disabled module autoload. Note that some modules must
- # be loaded by another kernel module.
- # core netfilter module
- /sbin/modprobe ip6_tables
- ###############################################################################
- #
- # Flush Any Existing Rules or Chains
- #
- echo "Flushing Tables ..."
- $IP6T -F
- # Set default chain policies
- $IP6T -P INPUT ACCEPT
- $IP6T -P FORWARD ACCEPT
- $IP6T -P OUTPUT ACCEPT
- if [ "$1" = "stop" ]
- then
- echo "Firewall completely flushed! Now running with no firewall."
- exit 0
- fi
- # This accepts ongoing traffic for any existing connections that we've already accepted through other rule:.
- $IP6T -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
- # Accept all ICMP packets. Unlike with IPv4, it's not a good idea to block ICMPv6 traffic as IPv6 is much more heavily dependent on it:
- $IP6T -A INPUT -p ipv6-icmp -j ACCEPT
- # Feedback for problems
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 1 -j ACCEPT
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 2 -j ACCEPT
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 3 -j ACCEPT
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 4 -j ACCEPT
- # Router and neighbor discovery incoming and outgoing
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 133 -j ACCEPT
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 134 -j ACCEPT
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 135 -j ACCEPT
- $IP6T -A INPUT -p icmpv6 --icmpv6-type 136 -j ACCEPT
- $IP6T -A OUTPUT -p icmpv6 --icmpv6-type 133 -j ACCEPT
- $IP6T -A OUTPUT -p icmpv6 --icmpv6-type 134 -j ACCEPT
- $IP6T -A OUTPUT -p icmpv6 --icmpv6-type 135 -j ACCEPT
- $IP6T -A OUTPUT -p icmpv6 --icmpv6-type 136 -j ACCEPT
- # Ping request from firewall
- $IP6T -A OUTPUT -p icmpv6 --icmpv6-type 128 -j ACCEPT
- # Accept all traffic from/to the local interface:
- $IP6T -A INPUT -i lo -j ACCEPT
- $IP6T -A OUTPUT -o lo -j ACCEPT
- # Enable stateful inspection
- $IP6T -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- $IP6T -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- # Anti-spoofing
- $IP6T -A INPUT ! -i lo -s ::1/128 -j DROP
- $IP6T -A INPUT -i $INET_IFACE -s fc00::/7 -j DROP
- # Block tunnel prefixes
- $IP6T -A INPUT -s 2002::/16 -j DROP
- $IP6T -A INPUT -s 2001:0::/32 -j DROP
- # ------------------------------- Add all other rules starting here ---------------------------
- # Accept DHCPv6 traffic. If you use stateless autoconfiguration, or statically configure your machines, this is not necessary:
- $IP6T -A INPUT -d fe80::/64 -p UDP -m state --state NEW -m udp --dport 546 -j ACCEPT
- # HTTP
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 80 -j ACCEPT
- # HTTPS (Secure Web Server)
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 443 -j ACCEPT
- # Email Server (SMTP)
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 25 -j ACCEPT
- # Secure Email Server (SMTPS)
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 465 -j ACCEPT
- # Submission
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 587 -j ACCEPT
- # Email Server (POP3)
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 110 -j ACCEPT
- # Email Server (IMAP4)
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 143 -j ACCEPT
- # SSL Email Server (POP3)
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 995 -j ACCEPT
- # SSL Email Server (IMAP4)
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 993 -j ACCEPT
- # sshd
- $IP6T -A INPUT -p TCP -m state --state NEW -m TCP --dport 22 -j ACCEPT
- # BIND/named
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 53 -j ACCEPT
- $IP6T -A INPUT -p UDP -m udp --dport 53 -j ACCEPT
- $IP6T -A INPUT -p TCP -m state --state NEW -m tcp --dport 953 -j ACCEPT
- $IP6T -A INPUT -p UDP -m udp --dport 953 -j ACCEPT
- # At the end of our rules, we reject all traffic that didn't match a rule, using "port unreachable".
- # This results in the standard "Connection refused" message at the other end, and effectively hides the fact that we have a firewall.
- # Tools such as nmap will report that all our ports are "closed" rather than "filtered"
- # and have a much more difficult time determining that we even have a firewall.
- $IP6T -A INPUT -j REJECT --reject-with icmp6-adm-prohibited
- $IP6T -A FORWARD -j REJECT --reject-with icmp6-adm-prohibited
Advertisement
Add Comment
Please, Sign In to add comment