Site icon moneyslow.com

IPv6添加iptables防火墙

如何telnet ipv6端口

如何telnet ipv6端口

iptables是一种流行的实用程序,允许系统管理员配置Linux内核防火墙提供的表以及它存储的链和规则。
它是用于IPv4流量的最常见且使用最广泛的Linux防火墙,它具有一个称为ip6tables的版本,用于ipv6流量。两种版本都需要单独配置。
在本文中,我将介绍如何在Ubuntu 16.04系统中配置ip6tables。请注意,需要具备iptables,防火墙策略和IPv6的基本知识。

系统中的IPv6
在配置ip6tables之前,请确保您的系统支持IPv6。要检查,请键入以下命令:

[root@ss-0-4-centos ~]# cat /proc/net/if_inet6
fe80000000000000505400fffe5e97dc 02 40 20 80 eth0
00000000000000000000000000000001 01 80 10 80 lo
24024e00101369000000932ea9852d0c 02 80 00 80 eth0

如何文件为空,则可以尝试通过modprobe ipv6加载IPv6模块。

在新安装的Ubuntu服务器中,默认情况下防火墙链为空。要查看链和规则,IPv6的防火墙状态可以这样看:
[root@VM-0-4-centos ~]# ip6tables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

所有链(INPUT,FORWARD,OUTPUT)都是空的,并且链的默认策略设置为ACCEPT。

只查看链的命令:
ip6tables -S | grep -e ‘-P’

添加第一个规则:
ip6tables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

追加规则:
ip6tables -A INPUT -p tcp --dport ssh -s HOST_IPV6_IP -j ACCEPT
ip6tables -A INPUT -p tcp --dport 80 -j ACCEPT
ip6tables -A INPUT -p tcp --dport 21 -j ACCEPT
ip6tables -A INPUT -p tcp --dport 25 -j ACCEPT

查看规则编号
ip6tables -L -n --line-numbers

删除ipv6规则
ip6tables -D INPUT -p tcp --dport 21 -j ACCEPT

如果想根据编号删除规则,先查询规则号
ip6tables -L --line-numbers
再删除:
iptables -D INPUT RULES_LINE_NUMBER

插入规则
ip6tables -I INPUT 2 -p icmpv6 -j ACCEPT

变更规则(从accept 改为 drop)
ip6tables -P INPUT DROP

有一个大问题,如果重启服务器,所有的规则都丢失了。所以要保存规则。
安装iptables-persistent包:
apt-get install iptables-persistent

在/etc/iptables 下会有两个文件生成,分别对应ipv4和ipv6

通过命令保存配置
/etc/init.d/iptables-persistent save

其他参数:start|restart|reload|force-reload|save|flush

Exit mobile version