NFS 客户端挂载在防火墙后面失败

Joe*_*ish 3 firewall nfs iptables ubuntu-11.10

我有一个带有 iptables 防火墙的 Ubuntu 11.10 系统。在固定 mountd、lockd 和 statd 的端口,然后在 iptables 中打开它们之后,我可以通过防火墙公开 NFS 共享,没有任何问题。

我遇到的问题是从另一个我无法控制的 NFS 服务器安装共享。如果我禁用防火墙,我可以挂载共享。我还可以不禁用防火墙的情况下挂载其他 NFS 共享。

所以这让我有两个问题

  • 为什么防火墙会阻止 NFS 客户端安装某些服务器而不是其他服务器?
  • 客户端可以指定用于 NFS 挂载的端口吗?

完整的配置和错误信息:

根据nfsstat. 当我做挂载时:

# mount -t nfs -v 192.168.80.48:/location /mnt/tmp
mount.nfs: timeout set for Fri Mar 23 09:13:00 2012
mount.nfs: trying text-based options 'vers=4,addr=192.168.80.48,clientaddr=192.168.40.173'
mount.nfs: mount(2): No such file or directory
mount.nfs: trying text-based options 'addr=192.168.80.48'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: trying 192.168.80.48 prog 100003 vers 3 prot TCP port 2049
mount.nfs: prog 100005, trying vers=3, prot=17
mount.nfs: trying 192.168.80.48 prog 100005 vers 3 prot UDP port 678
mount.nfs: portmap query retrying: RPC: Timed out
mount.nfs: prog 100005, trying vers=3, prot=6
mount.nfs: trying 192.168.80.48 prog 100005 vers 3 prot TCP port 681
mount.nfs: portmap query failed: RPC: Remote system error - Connection timed out
Run Code Online (Sandbox Code Playgroud)

我看到数据包被丢弃:

Rejected packets: SRC=192.168.80.48 DST=192.168.40.173 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=0 DF PROTO=TCP SPT=681 DPT=40325 WINDOW=5792 RES=0x00 ACK SYN URGP=0
Rejected packets: SRC=192.168.80.48 DST=192.168.40.173 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=0 DF PROTO=TCP SPT=681 DPT=47419 WINDOW=5792 RES=0x00 ACK SYN URGP=0
Rejected packets: SRC=192.168.80.48 DST=192.168.40.173 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=0 DF PROTO=TCP SPT=681 DPT=41238 WINDOW=5792 RES=0x00 ACK SYN URGP=0
Run Code Online (Sandbox Code Playgroud)

showmount以同样的方式失败。从详细的mount打印结果来看,端口映射似乎是问题所在,但我确实打开了它。

# rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  32765  status
    100024    1   tcp  32765  status
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049
    100227    3   tcp   2049
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049
    100227    3   udp   2049
    100021    1   udp   4002  nlockmgr
    100021    3   udp   4002  nlockmgr
    100021    4   udp   4002  nlockmgr
    100021    1   tcp   4001  nlockmgr
    100021    3   tcp   4001  nlockmgr
    100021    4   tcp   4001  nlockmgr
    100005    1   udp  32767  mountd
    100005    1   tcp  32767  mountd
    100005    2   udp  32767  mountd
    100005    2   tcp  32767  mountd
    100005    3   udp  32767  mountd
    100005    3   tcp  32767  mountd

# cat /etc/services
sunrpc          111/tcp         portmapper      # RPC 4.0 portmapper
sunrpc          111/udp         portmapper
nfs             2049/tcp                        # Network File System
nfs             2049/udp                        # Network File System

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:smtp
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:sunrpc
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ntp
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:netbios-ns
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:netbios-dgm
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:netbios-ssn
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:microsoft-ds
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:nfs
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:sunrpc
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:3260
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:32765
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:32766
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:32767
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:4001
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            udp dpt:sunrpc
ACCEPT     udp  --  anywhere             anywhere            udp dpt:ntp
ACCEPT     udp  --  anywhere             anywhere            udp dpt:netbios-ns
ACCEPT     udp  --  anywhere             anywhere            udp dpt:netbios-dgm
ACCEPT     udp  --  anywhere             anywhere            udp dpt:netbios-ssn
ACCEPT     udp  --  anywhere             anywhere            udp dpt:https
ACCEPT     udp  --  anywhere             anywhere            udp dpt:microsoft-ds
ACCEPT     udp  --  anywhere             anywhere            udp dpt:nfs
ACCEPT     udp  --  anywhere             anywhere            udp dpt:4002
ACCEPT     udp  --  anywhere             anywhere            udp dpt:32765
ACCEPT     udp  --  anywhere             anywhere            udp dpt:32766
ACCEPT     udp  --  anywhere             anywhere            udp dpt:32767
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:domain
ACCEPT     udp  --  anywhere             anywhere            udp spt:domain
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:sunrpc
ACCEPT     udp  --  anywhere             anywhere            udp spt:sunrpc
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:netbios-ssn
ACCEPT     udp  --  anywhere             anywhere            udp spt:netbios-ssn
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:https
ACCEPT     udp  --  anywhere             anywhere            udp spt:https
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:microsoft-ds
ACCEPT     udp  --  anywhere             anywhere            udp spt:microsoft-ds
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:submission
ACCEPT     udp  --  anywhere             anywhere            udp spt:submission
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:nfs
ACCEPT     udp  --  anywhere             anywhere            udp spt:nfs
Run Code Online (Sandbox Code Playgroud)

Lin*_*ged 5

有一些设置sysctl定义了可用于连接的 NFS 端口范围。

sunrpc.max_resvport = 1023

sunrpc.min_resvport = 650

这些设置定义了用于建立 RPC 连接 (NFS) 的最高和最低端口

您可以根据您的系统打开这些端口或定义不同的范围。如果它尝试使用被防火墙或使用该端口的其他服务阻止的端口,您将被拒绝。

编辑:

您还可以增加/减少此范围。我有一个定义了 460 个 NFS 挂载的服务器,fstab它会在 372 个左右后失败。当我手动挂载其中一个失败的挂载时,它会挂载它但卸载其中一个工作挂载。我将这个范围增加了 150 并且它们都安装了。这不是最好的方法。automounter想到但是,它的工作原理。

要进行修改,您将编辑/etc/sysctl.conf添加一行,如:

sunrpc.min_resvport = 900

如果您需要更改它们,则使更改永久化。请记住,如果您超过 1024,那么这些是“非特权”端口,普通系统用户将可以访问它们,而 1024。

编辑2:

在您的 NFS 挂载命令中,您可以添加以下内容。

proto=tcp - 强制安装使用 TCP/IP

public-portmapper除非另有说明,否则完全绕过并在端口 2049 上联系 NFS 服务器

所以, mount nfs.test.com:/export /test

变成

mount -o proto=tcp ,public nfs.test.com:/export /test

编辑 3

好的 - 我们开始了!!! root@pressyrluck # ./nowhammies > /dev/please

此信息lifted copied swiped borrowed来自Sourceforge NFS

通过 nfs 共享数据所涉及的一些守护进程已经绑定到一个端口。portmap 始终在端口 111 tcp 和 udp 上。nfsd 始终在端口 2049 TCP 和 UDP 上(但是,从内核 2.4.17 开始,TCP 上的 NFS 被认为是实验性的,不适用于生产机器)。

其他守护进程 statd、mountd、lockd 和 rquotad 通常会移动到端口映射程序通知它们的第一个可用端口。

要强制 statd 绑定到特定端口,请使用 -p portnum 选项。要强制 statd 响应特定端口,请在启动它时另外使用 -o portnum 选项。

要强制 mountd 绑定到特定端口,请使用 -p portnum 选项。

例如,要让 statd 广播端口 32765 并侦听端口 32766,并且 mountd 侦听端口 32767,您可以键入:

# statd -p 32765 -o 32766
# mountd -p 3276
Run Code Online (Sandbox Code Playgroud)

lockd 在需要时由内核启动。因此,您需要传递模块选项(如果您将其构建为模块)或内核选项以强制 lockd 仅在某些端口上侦听和响应。

如果您正在使用可加载模块并且您想在 /etc/modules.conf 文件中指定这些选项,请在文件中添加如下一行:

options lockd nlm_udpport=32768 nlm_tcpport=32768
Run Code Online (Sandbox Code Playgroud)

为了这个讨论,让我们描述一个网络并设置一个防火墙来保护我们的 nfs 服务器。我们的 nfs 服务器是 192.168.0.42 我们的客户端只有 192.168.0.45。如上例所示,statd 已启动,因此它只绑定到 32765 端口以接收传入请求,并且必须在端口 32766 上应答。mountd 被强制绑定到端口 32767。lockd 的模块参数已设置为绑定到 32768。nfsd当然,在端口 2049 上,而端口映射器在端口 111 上。

我们没有使用配额。

iptables -A INPUT -f -j ACCEPT -s 192.168.0.45
iptables -A INPUT -s 192.168.0.45 -d 0/0 32765:32768 -p 6 -j ACCEPT
iptables -A INPUT -s 192.168.0.45 -d 0/0 32765:32768 -p 17 -j ACCEPT
iptables -A INPUT -s 192.168.0.45 -d 0/0 2049 -p 17 -j ACCEPT
iptables -A INPUT -s 192.168.0.45 -d 0/0 2049 -p 6 -j ACCEPT
iptables -A INPUT -s 192.168.0.45 -d 0/0 111 -p 6 -j ACCEPT
iptables -A INPUT -s 192.168.0.45 -d 0/0 111 -p 17 -j ACCEPT
iptables -A INPUT -s 0/0 -d 0/0 -p 6 -j DENY --syn --log-level 5
iptables -A INPUT -s 0/0 -d 0/0 -p 17 -j DENY --log-level 5
Run Code Online (Sandbox Code Playgroud)

第一行表示接受所有数据包片段(第一个数据包片段除外,它将被视为正常数据包)。理论上,在重新组装之前没有数据包会通过,并且除非第一个数据包片段通过,否则不会重新组装。当然,通过使用数据包碎片使机器超载可以产生攻击。但是除非您让片段通过,否则 NFS 将无法正常工作。有关详细信息,请参见第 7 节“故障排除”。

其他行允许从我们客户端主机上的任何端口到我们在服务器上可用的特定端口的特定连接。这意味着,如果 192.158.0.46 尝试联系 NFS 服务器,它将无法挂载或查看可用的挂载。

使用新的端口固定功能,控制允许挂载 NFS 共享的主机显然要容易得多。值得一提的是,NFS 不是加密协议,同一物理网络上的任何人都可以嗅探流量并重新组合来回传递的信息。