我希望将到达 192.168.0.1:80 的网络流量重定向到 127.0.0.1:3000。而且,我还希望处理响应的映射。我完整的 NAT 和 Filter 表规则粘贴在下面。
我能够在端口 80 上接收连接。但是,我无法将流量重定向到 localhost:3000。
add table inet filter
add chain inet filter input { type filter hook input priority 0; policy accept; }
add chain inet filter forward { type filter hook forward priority 0; policy accept; }
add chain inet filter output { type filter hook output priority 0; policy accept; }
add rule inet filter input ct state related,established counter accept
add rule inet filter input ip protocol icmp counter …
Run Code Online (Sandbox Code Playgroud) 使用 iptables,我可以将 INPUT 策略更改为iptables -P INPUT DROP
drop。有什么选择可以做同样的事情nft
吗?
编辑/etc/nftables.conf
当然可以,但这不是我想要的。
https://wiki.nftables.org/wiki-nftables/index.php/Quick_reference-nftables_in_10_minutes#Meta
iifname
(外面的名字是字符串)和iif
推荐的有什么区别吗?
我有一个在输入链中丢弃数据包的策略
chain input {
type filter hook input priority 0; policy drop;
Run Code Online (Sandbox Code Playgroud)
我怎样才能只记录这些丢弃的数据包?
iptables
(和/或后续工具nftables
)是用户空间实用程序,允许系统管理员配置 Linux 内核防火墙的 IP 数据包过滤规则,该规则作为不同的Netfilter 模块实现。(摘自维基百科)
由于iptables
和nftables
是旨在由人们、系统管理员使用的用户空间实用程序,并且人们并不总是完全熟悉底层数字,因此它们接受 IP 协议(tcp、icmp、udp 等)的人类可读描述, IP 地址(主机名)和端口号(服务名称)。
从 UI 方面来看,使用人类可读的名称似乎是一件好事:
iptables --protocol udp
iptables --protocol 17
和类似的含义的人。gateway.example.net
通常比 IP 地址更有意义,例如192.0.2.1
这样做安全吗?
或者你应该远离它?
有什么注意事项?
编辑:按照 Marco 的建议添加了额外的 .conf 文件管理器并稍微更改了措辞
我正在运行Fail2ban v0.10,它应该支持 IPv6。
我已经根据这些说明设置了带有 nftables 的 Fail2ban,但我对 nftables 使用了 'inet' 系列而不是 ip 系列,因为我想允许 IPv6 流量到我的服务器。
服务器可以通过 IPv6 访问,而且我的防火墙(nftables)似乎配置正确,就我所见(表 inet 过滤器)。
然而,'table inet fail2ban' 是我写这篇文章的原因,在我看来,Fail2ban 只读取 IPv4 日志,并阻止违规的 IPv4 主机。
我读对了吗?如果是这样,有谁知道我如何使 Fail2ban 也能处理 IPv6 流量?我知道 Fail2ban v0.10 更新日志指出,并非所有禁令行动都支持 IPv6,但我似乎找不到列表。
也欢迎提供指向我可以找到信息的链接,因为我自己似乎无法找到。
我只包含了 recidive jail 配置,因为我认为如果我可以让 jail 使用 IPv6,我可以对其他人做同样的事情,如果我误解了这个假设,请告诉我 :)
我的 nftables 规则集:
table inet filter {
chain input {
type filter hook input priority 0; policy accept;
ct state { related, …
Run Code Online (Sandbox Code Playgroud) 我想在我的服务器上打开一系列 TCP 端口nftables
。
通常,在 netfilter/iptables 中我可以这样编写规则
iptables -A INPUT -p tcp 1000:2000 -j ACCEPT
Run Code Online (Sandbox Code Playgroud)
我尝试以同样的方式写/etc/nftables.conf
tcp dport {1000:2000} accept
Run Code Online (Sandbox Code Playgroud)
但nft
报告
/etc/nftables.conf:24:15-24: Error: mapping outside of map context
tcp dport {1000:2000} accept
^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud) 我想向您询问有关透明防火墙构建的最佳实践建议。
我有 2 段网络和带有 2 个 10G 接口的 CentOS 服务。我想过滤/监控/限制/丢弃网段之间的流量。流量已被标记。我应该取消流量过滤标记并将其标记回来,还是 nftable 可以处理标记的流量?
现在方案看起来像:
PCs--| |--PCs
PCs--|--untag--[Switch]--tag--[Switch]--untag--|--PCs
PCs--| |--PCs
Run Code Online (Sandbox Code Playgroud)
我想:
PCs--| |--PCs
PCs--|--untag--[Switch]--tag--**[Firewall]**--tag--[Switch]--untag--|--PCs
PCs--| |--PCs
Run Code Online (Sandbox Code Playgroud) 我希望限制 Linux 服务器上运行的给定服务的并发连接数。我的理解是这可以通过iptables
使用connlimit
模块来完成。例如,如果我想限制与 SSH 服务器的并发连接(并假设默认策略是拒绝),那么这应该允许 10 个并发连接,第 11 个被拒绝(从内存中写入):
iptables -A INPUT -p tcp --dport 22 -m connlimit --connlimit-upto 10 -j ACCEPT
问题是在我正在构建的新服务器上,我想使用nftables
. 虽然我可以connlimit
在手册页中找到提到的内容,但它只是简单地说明了consider native interface. Refer to Meters
。在搜索了有关 Meters 的信息后,虽然它对于速率限制看起来很棒,但我找不到任何表明我可以做相当于connlimit
.
那么,假设我想使用nftables
,如何创建一个仅匹配 X 个并发连接的规则?
我已经设置了一个网桥,并希望将穿过它的 HTTP/HTTPS 流量重定向到本地端口 (8080),以便我可以使用 mitmproxy 进一步处理它。
到目前为止,我使用的是 ebtables 和 iptables 规则的组合。不幸的是,我不得不知道 eatables 不再支持表 'brute',我应该使用nftables代替。
使用的软件:
我如何创建这座桥:
root@kali:~# ip link add name br0 type bridge
root@kali:~# ip link set dev br0 up
root@kali:~# ip link set dev eth0 master br0
root@kali:~# ip link set dev eth2 master br0
Run Code Online (Sandbox Code Playgroud)
我的界面:
root@kali:~# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.178.67 netmask 255.255.255.0 broadcast 192.168.178.255
ether 00:01:c0:1b:4b:31 txqueuelen 1000 (Ethernet)
root@kali:~# ifconfig eth2
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用规则上的nftables
命名来跟踪从一组特定 IP 地址(IPv4 和 IPv6)传输的总数据。counter
我的目标是能够在一个日历月内跟踪这一总数,以便我可以根据使用情况进行计费。
相关规则如下:
add table stats
add counter stats os-traffic-4
add counter stats os-traffic-6
add chain inet stats INPUT { type filter hook input priority 0; }
add rule ip stats INPUT ip saddr 192.168.123.123 counter name os-traffic-4
add rule ip stats INPUT ip saddr 192.168.123.234 counter name os-traffic-4
add rule ip stats INPUT ip saddr 192.168.123.345 counter name os-traffic-4
add rule ip6 stats INPUT ip6 saddr 1234:1234:1234:1234:1234:1234:1234:1234 counter name os-traffic-6
add rule …
Run Code Online (Sandbox Code Playgroud) 如何使用 nftables 跟踪 nat 传出连接。只需要查看 nat 统计信息,即或多或少使用了哪些输出地址。
root@nat-1:~# nft list table nat
table ip nat {
chain post {
type nat hook postrouting priority 100; policy accept;
ip saddr 10.0.0.0/8 oif "bond0.926" snat to 19.246.159.1-19.246.159.7
}
chain pre {
type nat hook prerouting priority -100; policy accept;
}
}
Run Code Online (Sandbox Code Playgroud)
netstat-nat 适用于 iptables,但不再适用于 nftables。
netstat-nat -S
Could not read info about connections from the kernel, make sure netfilter is enabled in kernel or by modules.
Run Code Online (Sandbox Code Playgroud)
我当然可以使用 tcpdump,但应该有一些更好的实用程序;-)
我的服务器上的 IPv6 存在问题。我将 nginx 配置为侦听 IPv4 和 IPv6 的端口 443。它效果很好:我的网站可以通过启用了 TLS 的 Internet 访问。
当我激活 nftables 时,事情变得复杂:当我从 IPv4 访问我的网站时,它可以工作,但当我从 IPv6 连接访问它时,超时:(
输出sudo nft list ruleset
:
table inet filter {
chain INPUT {
type filter hook input priority filter; policy drop;
meta nftrace set 1
ct state established,related accept comment "allow established connections"
iif "lo" accept comment "allow all from localhost"
iif != "lo" ip daddr 127.0.0.0/8 counter packets 0 bytes 0 drop comment "drop connections to loopback …
Run Code Online (Sandbox Code Playgroud)