ip6tables -P INPUT DROP # 配置默认的不让进 ip6tables -P FORWARD DROP # 默认的不允许转发 ip6tables -P OUTPUT ACCEPT # 默认的可以出去
# 换回接口出入随意 ip6tables -A INPUT -i lo -j ACCEPT ip6tables -A OUTPUT -o lo -j ACCEPT # 放行ssh SSHPORT="$(ss -6tulnp | grep "ssh" | awk '{print $5}' | awk -F"]:" '{print $2}')" ip6tables -A INPUT -p tcp --dport "${SSHPORT}" -j ACCEPT
# 禁ICMP ip6tables -A INPUT -p icmpv6 --icmpv6-type echo-request -j DROP
}
iptables-set(){ ipv4-set ipv6-set } # 配置ipv6 ipv4 黑白名单 Whitelist_And_Blacklist(){ while IFS= read -r line do if [[ "$line" =~ $CIDR_REGEX_v4 ]]; then iptables -A INPUT -s "$line" -j ACCEPT elif [[ "$line" =~ $CIDR_REGEX_v6 ]]; then ip6tables -A INPUT -s "$line" -j ACCEPT else echo"$line error value" fi done < "$WHITE_LIST_PATH"
while IFS= read -r line do if [[ "$line" =~ $CIDR_REGEX_v4 ]]; then iptables -A INPUT -s "$line" -j DROP elif [[ "$line" =~ $CIDR_REGEX_v6 ]]; then ip6tables -A INPUT -s "$line" -j DROP else echo"$line error value" fi done < "$BLACK_LIST_PATH" } iptables-set Whitelist_And_Blacklist