使用不安全的 nfs 端口进行挂载

使用不安全的 nfs 端口进行挂载

标题说明了一切。mount 偶尔会从不安全的端口发出 NFS 挂载/卸载请求。我认为问题是由于在挂载活动非常频繁的一段时间后,所有安全端口都卡在 TIME_WAIT 中(amd)。有什么方法可以改变这种行为吗?我不希望从不安全的端口发送请求,无论是否有可用的安全端口。我宁愿挂载在等待安全端口时挂起。允许来自 NFS 服务器上不安全端口的请求不是一个选项。

我在手册页中没有看到有关 mount、nfs 或 mount.nfs 控制此问题的任何内容。为了缓解此问题,我尝试了 net.ipv4.tcp_tw_reuse=1,但似乎没有帮助。

提前致谢。

答案1

为什么不使用 iptables 来阻止您不想使用的这些端口(范围)。确保将其设为拒绝规则而不是丢弃它,在后一种情况下,可能需要更长时间,因为连接尝试超时。

典型的规则可能如下所示:

    /sbin/iptables -I OUTPUT -d 0/0 -j REJECT --reject-with icmp-net-prohibited -p tcp --dport XX -o ethX
    /sbin/iptables -I OUTPUT -d 0/0 -j REJECT --reject-with icmp-net-prohibited -p udp --dport XX -o ethX

对于端口范围使用:

--dport XX:YY

对于传入:

    /sbin/iptables -I INPUT -s 0/0 -j REJECT --reject-with icmp-net-prohibited -p tcp --dport XX -i ethX
    /sbin/iptables -I INPUT -s 0/0 -j REJECT --reject-with icmp-net-prohibited -p udp --dport XX -i ethX

更新:也许向 rpc.mountd 添加正确的选项会对你有用,从手册中可以看出:

-p  or  --port num
          Force rpc.mountd to bind to the specified port num, instead of using the random port number assigned by the portmapper.

在 Debian 中,您可以在 /etc/default/nfs-kernel-server 中执行此操作,并将选项添加到此行:

# Options for rpc.mountd.
# If you have a port-based firewall, you might want to set up
# a fixed port here using the --port option. For more information, 
# see rpc.mountd(8) or http://wiki.debian.org/?SecuringNFS
RPCMOUNTDOPTS=--manage-gids

相关内容