How do I set the NFS4 client callback port to a specific port?
Environment
- Red Hat Enterprise Linux (NFS client)
- NFS4
Issue
- How do I set the NFS4 client callback port to a specific port?
Resolution
Red Hat Enterprise Linux - all versions (NFS 4.1 and above)
NFS v4.1 and later uses the pre-existing client port for callbacks, so the callback port cannot be set separately.
Red Hat Enterprise Linux 5 - 7 (NFS 4.0)
The kernel tunable fs.nfs.nfs_callback_tcpport can be used to set the NFS4 client callback port to a specific port.
This option can be set at runtime as follows. Once set, all new NFS4 mount requests will use the new callback port.
# /sbin/sysctl -w fs.nfs.nfs_callback_tcpport=60000
On RHEL6 and RHEL7, the callback port can be made permanent by entering the option into modprobe, for example:
echo "options nfs callback_tcpport=60000" >> /etc/modprobe.d/nfs-callbacks.conf
On RHEL5, the callback port can be made permanent by editing /etc/modprobe.d/modprobe.conf.dist with the line:
install nfs /sbin/modprobe --first-time --ignore-install nfs && { /sbin/sysctl -w fs.nfs.nfs_callback_tcpport=60000; }
To see the modprobe option take effect, umount any NFS4 mount point, rmmod and modprobe the NFS module, then remount the share. For example
# umount /mnt/nfs4
# rmmod nfs
# modprobe nfs
# mount nfs-server:/export /mnt/nfs4
To verify the callback port has been set to what you'd expect, make sure at least one NFS4 share is mounted, then check for a TCP LISTEN port equal to the port you set.
# grep nfs4 /proc/mounts
nfs-server:/export /mnt/nfs4 nfs4 rw,relatime,vers=4,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.46,minorversion=0,local_lock=none,addr=192.168.122.2 0 0
# netstat -an | grep tcp | grep LIST | grep 60000
tcp 0 0 0.0.0.0:60000 0.0.0.0:* LISTEN
tcp 0 0 :::60000 :::* LISTEN
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.