nfsv4
We ever discussed fixing ports used by NFSv3 so that it can be easily exported to external networks. For NFSv4.1 or higher, things are much easier. The ports for mountd
, statd
, and lockd
are not required in a pure NFSv4 environment. We have less ports to control or allow for connections. Only port 111 and 2049 need to be taken care of for NFSv4. In this post, we will discuss how to export NFSv4 to external networks.
我们曾经讨论过NFSv3使用的固定端口,以便可以将其轻松导出到外部网络。 对于NFSv4.1或更高版本,事情要容易得多。 在纯NFSv4环境中,不需要mountd
, statd
和lockd
的端口。 我们需要控制或允许连接的端口较少。 对于NFSv4,只需要注意端口111和2049。 在本文中,我们将讨论如何将NFSv4导出到外部网络。
In this tutorial’s example, we assume
在本教程的示例中,我们假设
- network is 192.168.0.0/16网络是192.168.0.0/16
- the gateway’s external network IP is 192.168.1.100 网关的外部网络IP为192.168.1.100
- the NFS server’s private/internal IP is 10.2.2.2 NFS服务器的专用/内部IP为10.2.2.2
If you are running on a different network configuration, please replace these IPs in the following command with you IPs.
如果您在其他网络配置上运行,请用您的IP替换以下命令中的这些IP。
Steps to export an NFSv4 are as follows.
导出NFSv4的步骤如下。
在网关上设置端口转发 (Set up port forwarding on the gateway)
On the gateway, run
在网关上 ,运行
# iptables -t nat -A PREROUTING -d 192.168.1.100/32 -p tcp -m tcp --dport 2049 -j DNAT --to-destination 10.2.2.2:2049
# iptables -t nat -A PREROUTING -d 192.168.1.100/32 -p udp -m udp --dport 2049 -j DNAT --to-destination 10.2.2.2:2049
# iptables -t nat -A PREROUTING -d 192.168.1.100/32 -p tcp -m tcp --dport 111 -j DNAT --to-destination 10.2.2.2:111
# iptables -t nat -A PREROUTING -d 192.168.1.100/32 -p udp -m udp --dport 111 -j DNAT --to-destination 10.2.2.2:111
to export the port 2049 and 111.
出口端口2049和111。
Note: the rules are in memory only. Please remember to save the iptables rules after it is tested working following your gateway host’s iptables management.
注意:规则仅在内存中。 经过测试,请遵循网关主机的iptables管理功能,保存iptables规则。
允许NFSv4服务器中的外部网络IP (Allow external network IPs in the NFSv4 server)
On the NFSv4 server:
在NFSv4服务器上:
Add this line (exactly the same; exports requirement is strict)
添加此行(完全相同;出口要求严格)
/nfs/data 192.168.0.0/16(rw,no_root_squash)
to /etc/exports
到/ etc / exports
and then run
然后运行
# exportfs -a
to make it take effect
使它生效
You can check the exported FS by running exportfs
. It should show something like
您可以通过运行exportfs
检查导出的FS。 它应该显示类似
/nfs/data
10.2.0.0/16
/nfs/data
192.168.0.0/16
挂载NFS (Mount the NFS)
Then, on another node in the external network, you can mount the /nfs/data by
然后,在外部网络的另一个节点上,可以通过以下方式挂载/ nfs / data
# mount 192.168.1.100:/nfs/data /nfs
Then you can use the NFS exported from the private network. Enjoy!
然后,您可以使用从专用网络导出的NFS。 请享用!
翻译自: https://www.systutorials.com/export-nfsv4-server-external-networks/
nfsv4