How to Export an NFSv4 Server to External Networks

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.

In this tutorial’s example, we assume

  • the external network is 192.168.0.0/16
  • the gateway’s external network IP is 192.168.1.100
  • the NFS server’s private/internal IP is 10.2.2.2

If you are running on a different network configuration, please replace these IPs in the following command with you IPs.

Steps to export an NFSv4 are as follows.

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.

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.

Allow external network IPs in the NFSv4 server

On the NFSv4 server:

Add this line (exactly the same; exports requirement is strict)

/nfs/data 192.168.0.0/16(rw,no_root_squash)

to /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

/nfs/data
10.2.0.0/16
/nfs/data
192.168.0.0/16

Mount the NFS

Then, on another node in the external network, you can mount the /nfs/data by

# mount 192.168.1.100:/nfs/data /nfs

Then you can use the NFS exported from the private network. Enjoy!

Similar Posts

  • Installing Fedora 19, Error “you have not created a bootloader stage1 target device”

    Installing Fedora 41, Error “you have not created a bootloader stage1 target device” . It seems appear from Fedora 41: http://forums.fedoraforum.org/showthread.php?t=271743 This can be solved by adding noefi nogpt to the kernel parameters when booting the Linux for installation in grub as follows. Note: the “_” between nogpt and root is the cursor, not the…

  • |

    How to improve video rendering quality in MPlayer

    MPlayer has lots options for video rendering and filtering. Any suggestions on good MPlayer options that improve video rendering quality nicely? My ~/.mplayer/config is as follows with 2 profiles: [fast] vf=eq2 [default] vf=hqdn3d vo=gl:yuv=3:lscale=5:cscale=5 ao=pulse The default one gives good video quality by using the hqdn3d video filter while the CPU usage is high. If…

  • | | |

    Proof of Ownership for BTC Addresses: A Detailed Guide

    Proving ownership of a Bitcoin (BTC) address is a crucial aspect in various scenarios, such as verifying identity in a transaction or demonstrating holdings without revealing private keys. This guide explores how to prove ownership for different BTC address types, including algorithm specifications and step-by-step methods. BTC Address Types P2PKH (Pay-to-Public-Key-Hash) P2SH (Pay-to-Script-Hash) P2WPKH (Pay-to-Witness-Public-Key-Hash)…

  • MFC程序使用系统风格界面

    VC6默认编译出来的程序在XP下Luma风格下运行也是Windows的经典界面, 有损界面的美观与统一. VC2008默认设置下如果不是使用的unicode也是如此. 本文给出使VC6和VC2008可以编译出使用系统界面风格的解决方案. 1. 使VC6编译出使用系统风格的程序 步骤如下: 1) 创建一个.manifest文件的资源. 在res/文件夹下创建一个跟以程序名加.manifest的文件, 如果程序为test.exe, 则创建test.exe.manifest 文件可由此下载: https://www.systutorials.com/t/g/programming/resultcollector.manifest/ 注意要使用utf-8编码保存。 2) 将新定义的资源加入到.rc2文件中, 类型设为24. 打开res/文件夹下的.rc2文件, 在其中加入如下定义: 1 24 MOVEABLE PURE “res/test.exe.manifest” 其中的文件地址按1)步中修改的设置即可. 之后编译即可, 为了使程序界面可能充分利用系统的界面特性, 可以将界面字体设置为TrueType类型的, 利用Windows XP等系统的屏幕字体平滑特性. 2. 使VC2008编译出使用系统风格的程序 在VC2008下就比较简单了, 如果程序字符集使用unicode则默认就是使用系统界面风格的, 如果选择其它的类型, 则编辑下stdafx.h即可. 最后面部分找到这么一段: #ifdef _UNICODE #if defined _M_IX86 #pragma comment(linker,”/manifestdependency:”type=’win32′ name=’Microsoft.Windows.Common-Controls’ version=’6.0.0.0′ processorArchitecture=’x86′ publicKeyToken=’6595b64144ccf1df’ language=’*'””) #elif defined _M_IA64 #pragma comment(linker,”/manifestdependency:”type=’win32’…

  • |

    The Impact of Blockchain and Crypto Technologies on Global Financial Markets

    Welcome to the groundbreaking world of cryptocurrency and blockchain technologies! These cutting-edge technologies are shaking up the global financial environment and paving the path for a more transparent and decentralized future. Consider blockchain technology to be a digital counterpart of a ledger book. It is a secure and immutable digital ledger that records all transactions…

3 Comments

  1. What about routing?
    The source-address remains the same, so the routing table of the internal nfs-server is important – isn’t it?
    Are there any additional routing configurations at the gateway?
    Regards
    Markus

    1. In the environment where this works as stated at the beginning part, the ‘gateway’ should already have been configured as a gateway including its routing rules, iptables rules, network cables/interfaces and etc. This post does not cover that part of configuring a gateway.

  2. Solved it with an SNAT entry in POSTROUTING. Works, but kind of slow. Need to analyze if its the iptables-Part or the load or the network.

    Thanks
    Markus

Leave a Reply

Your email address will not be published. Required fields are marked *