端口不是 69 的 TFTP 回复无法通过 NAT

端口不是 69 的 TFTP 回复无法通过 NAT

我有一台 Ubuntu 笔记本电脑,我将其配置为路由器。拓扑如下:

internet <---> laptop router <---> raspberry pi 3

笔记本电脑中启用了 NAT,以将数据包从 Raspberry pi 3 转发到互联网,并将数据包从互联网转发回 Raspberry pi 3。除了 TFTP 之外,一切正常。

每次我想从 TFTP 服务器获取文件时,都会超时失败。在笔记本电脑上捕获数据包后,找到了根本原因。

当回复返回时,NAT 使用目标 IP 和目标端口作为标志,将帧转发回 pi 3。但在 TFTP 的情况下,TFTP 请求使用 IP 和目标端口 69 发送,但 TFTP 服务器使用相同的 IP 但不同的随机端口回复请求。因此这让 NAT 感到困惑,不知道将这个回复消息转发到哪里。最后,它向 TFTP 服务器回复错误“目标不可达”。

虽然我知道原因,但不知道如何解决。有人能帮帮我吗?谢谢!

答案1

您需要手动加载 tftp 协议的 nat 帮助程序。对于 nftables,它被称为nf_nat_tftp,对于 iptables,您必须自己检查它(我没有现成的,它们可能是相同的模块)。

答案2

您需要标记数据包以使用 TFTP 特定的 NAT 模块:

iptables -t raw -I PREROUTING -j CT -p udp -m udp --dport 69 --helper tftp

使用 nft:

table filter {
    ct helper tftp-69 {
        type "tftp" protocol udp
    }
    chain input {
        ...
        ct state new udp dport 69 ct helper set "tftp-69"
    }
}

相关内容