我有一个iptables防火墙的Ubuntu 11.10系统。 固定的端口mountd,lockd和statd,然后在iptables中打开它们,我能够通过防火墙公开NFS共享,没有问题。
我遇到的问题是从另一个无法控制的NFS服务器上挂载一个共享。 如果我禁用防火墙, 我可以挂载共享。 我也可以挂载其他NFS共享而不禁用防火墙。
所以这引出了两个问题 :
完整的configuration和错误信息:
根据nfsstat ,服务器是NFSv3。 当我坐山时:
# 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
我看到数据包被丢弃:
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
showmount以相同的方式失败。 从详细的mount打印,它看起来像portmap是问题,但我打开了。
# 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
sysctl中有一些设置可以定义可用于连接的NFS端口范围。
sunrpc.max_resvport = 1023
sunrpc.min_resvport = 650
这些设置定义了用于进行RPC连接(NFS)的最高和最低端口,
您可以打开这些端口或根据您的系统定义不同的范围。 如果您尝试使用被防火墙或使用该端口的其他服务阻止的端口,您将会被拒绝。
编辑:
您也可以增加/减less这个范围。 我有一个服务器在fstab定义了460个NFS挂载,并且在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
从Sourceforge NFS borrowed这个信息被copied
涉及通过nfs共享数据的一些守护进程已经绑定到一个端口。 portmap始终在端口111 tcp和udp上。 nfsd始终在端口2049 TCP和UDP上(但是,从内核2.4.17起,NFS over TCP被认为是实验性的,不适用于生产机器)。
其他守护进程statd,mountd,lockd和rquotad通常会移动到portmapper通知的第一个可用端口。
要强制statd绑定到特定端口,请使用-p portnum选项。 要强制statd在特定端口上响应,另外在启动时使用-o portnum选项。
要强制mountd绑定到特定的端口,使用-p portnum选项。
例如,要进行端口32765的statd广播,并在端口32766上侦听,并在端口32767上侦听,请input:
# statd -p 32765 -o 32766 # mountd -p 3276
当需要的时候,locking由内核启动。 因此,您需要传递模块选项(如果您将其作为模块构build)或内核选项来强制locking,才能在特定端口上侦听和响应。
如果您使用的是可加载模块,并且想要在/etc/modules.conf文件中指定这些选项,请将如下所示的行添加到文件中:
options lockd nlm_udpport=32768 nlm_tcpport=32768
为了这个讨论,我们来描述一个networking并设置一个防火墙来保护我们的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
第一行表示接受所有数据包片段(除了第一个数据包片段将被视为普通数据包)。 从理论上说,在重组之前,数据包不会被传递,除非通过第一个数据包片段,否则不会重新组装。 当然,还有一些攻击可以通过使用数据包碎片重载机器来产生。 但是,除非让碎片通过,否则NFS将无法正常工作。 有关详细信息,请参见第7节“故障排除”。
其他线路允许从客户端主机上的任何端口到我们在服务器上提供的特定端口的特定连接。 这意味着如果192.158.0.46尝试联系NFS服务器,将无法挂载或查看可用的挂载。
有了新的端口固定function,控制哪些主机可以挂载NFS共享显然更容易。 值得一提的是,NFS不是一个encryption的协议,同一物理networking上的任何人都可以嗅探stream量并重新组合来回传递的信息。