Connection timed out usually means the server is ignoring your request due to a firewall, or simply the network is not configured correctly.
Checking Connectivity
Ensure you can ping the client and the client can ping the server to verify connectivity. If you can not, ensure both have IP addresses first with something such as ip -br addr
and look to see if they are on the same network with valid IP address.
Configuring NFSv4
NFS using NFSv4 requires these services to work as specified by Redhat (Note I prefer using Redhat documentation as they cover more in-depth details, and are easier to navigate, but the configuration will be very similar between the 2 flavors of Linux).
nfsd
rpc.mountd
rpc.nfsd
rpc.rquotad
rpc.idmapd
Ensuring exports
Ensure your /etc/exports
are correct. (This example is to allow ClientIP to mount /Path as read/write)
/Path clientIP(rw)
Run exportfs to export the nfs share. This doesnt need to be done if we restart the nfs process anyway but this will allow you to share and unshare exports without restarting the nfs service.
exportfs -a # export all shares
Configuring Firewall (Optional, but highly recommended/required if firewall is in place)
# On server
firewall-cmd --permanent --add-service nfs
firewall-cmd --reload
systemctl restart nfs-server
# On client, this is required for NFSv4.0 but later versions from NFSv4.1 dont require it. NFSv4.1 and later do the callback on the same connection initiated by the client.
# echo "fs.nfs.nfs_callback_tcpport = <callback-port>" >/etc/sysctl.d/90-nfs-callback-port.conf
# sysctl -p /etc/sysctl.d/90-nfs-callback-port.conf
# firewall-cmd --permanent --add-port=<callback-port>/tcp
# firewall-cmd --reload
ufw allow from ClientIP to any port nfs
ufw status
Verification
Verify on the server with netstat -tuna
the nfs is running.
Verify nfs works by doing systemctl restart nfs-server
then check status with systemctl status nfs-server
. If all is good then the server should be working.
Mounting on client
Run mount -t nfs -o nfsvers=4.0,port=2049,tcp ServerIP:/Path /local/dir
Documentation
Redhat: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/managing_file_systems/exporting-nfs-shares_managing-file-systems#doc-wrapper
Digitalocean: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nfs-mount-on-ubuntu-22-04
Linuxhint: https://linuxhint.com/install-and-configure-nfs-server-ubuntu-22-04/