AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1017041
Accepted
Christian Deacon
Christian Deacon
Asked: 2020-05-14 17:41:14 +0800 CST2020-05-14 17:41:14 +0800 CST 2020-05-14 17:41:14 +0800 CST

NFTables 伪装不工作

  • 772

我正在尝试设置 NFTables 以将来自特定 UDP 端口的流量转发到具有不同 IP 地址的另一台服务器。但是,我的伪装规则似乎不起作用。当我向这个特定的 UDP 端口发送数据包时,它会尝试转发流量,但不会将源 IP 更改为转发服务器的 IP 地址。据我了解,这应该与伪装规则一起发生。但是,即使是 SNAT 规则也不起作用。

这是显示问题所在的 TCPDump 输出:

01:04:12.437619 fe:00:02:b8:34:ff > 56:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <MyIP>.7130 > <ForwardIP>.27015: UDP, length 9
01:04:12.437657 56:00:02:b8:34:ff > fe:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <MyIP>.7130 > <DestIP>.27015: UDP, length 9
01:04:14.145003 fe:00:02:b8:34:ff > 56:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <MyIP>.7130 > <ForwardIP>.27015: UDP, length 9
01:04:14.145051 56:00:02:b8:34:ff > fe:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <MyIP>.7130 > <DestIP>.27015: UDP, length 9

我希望它看起来像这样:

01:04:12.437619 fe:00:02:b8:34:ff > 56:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <MyIP>.7130 > <ForwardIP>.27015: UDP, length 9
01:04:12.437657 56:00:02:b8:34:ff > fe:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <ForwardIP>.7130 > <DestIP>.27015: UDP, length 9
01:04:14.145003 fe:00:02:b8:34:ff > 56:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <MyIP>.7130 > <ForwardIP>.27015: UDP, length 9
01:04:14.145051 56:00:02:b8:34:ff > fe:00:02:b8:34:ff, ethertype IPv4 (0x0800), length 51: <ForwardIP>.7130 > <DestIP>.27015: UDP, length 9

这是我当前的 NFTables 的设置方式:

root@forwardtest:~# nft list tables
table ip compressor_forward

root@forwardtest:~# nft list table compressor_forward -a
table ip compressor_forward { # handle 1
        chain prerouting { # handle 15
                type nat hook prerouting priority dstnat; policy accept;
                udp dport 27015 dnat to 149.28.45.245 # handle 17
        }

        chain postrouting { # handle 16
                type nat hook postrouting priority srcnat; policy accept;
                masquerade random # handle 18
        }
}

我尝试删除randomNAT 标志以及添加persistentNAT 标志。对于我的情况,我确实需要randomNAT 标志。但是,添加/删除标志并没有什么不同。

还设置了 IPv4 转发:

root@forwardtest:~# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

IPTables (NAT) 也应该被删除。以下是我运行的一些命令:

root@forwardtest:~# rmmod iptable_nat
rmmod: ERROR: Module iptable_nat is not currently loaded

root@forwardtest:~# lsmod | grep "iptable"

root@forwardtest:~# lsmod | grep "nft"
nft_masq               16384  1
nft_nat                16384  1
nft_chain_nat          16384  2
nf_nat                 40960  3 nft_nat,nft_masq,nft_chain_nat
nf_conntrack          139264  3 nf_nat,nft_nat,nft_masq
nf_tables             135168  8 nft_nat,nft_masq,nft_chain_nat

root@forwardtest:~# iptables -t nat -L -n
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

root@forwardtest:~# iptables -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

请记住lsmod | grep "iptable"什么都没退回。我也尝试过创建postrouting优先级为 1 的链,但这没有任何区别。

转发服务器Ubuntu 20.04 LTS在内核上运行5.4.0-26-generic。

在这种情况下我有什么遗漏吗?话虽如此,我是 NFTables 的新手。因此,如果我遗漏了一些明显的东西,我深表歉意。

如果您需要更多信息,请告诉我!

非常感谢任何帮助!

感谢您的时间。

nat nftables
  • 1 1 个回答
  • 1440 Views

1 个回答

  • Voted
  1. Best Answer
    Christian Deacon
    2020-05-14T18:01:38+08:002020-05-14T18:01:38+08:00

    我解决了这个问题。我将转发服务器的内核从5.4.0-26-genericto升级了5.6.11-050611-generic,它开始正常工作。话虽如此,我确实尝试在旧内核上重新启动转发服务器,并且在重新启动后问题仍然存在。因此,我确实相信内核实际上是这里的问题。

    绝对是一个奇怪的问题。我将设置另一个很快运行的测试服务器5.4.0-26-generic来确认。

    谢谢!

    • 0

相关问题

  • 为 Cisco ASA 5510 上的端口 443/80 创建 NAT 规则和安全策略

  • Linux 路由器上的 NAT GRE(IP 协议 47)

  • OCS 2007 R2 A/V NAT - 外部客户端尝试内部 IP

  • 为什么我无法从我的win2008 NAT 后面连接到某些ftp 服务器?

  • 隧道 Xbox 网络流量 [关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve