Skip to content
Search Fedora

    Browse this documentation

    NFS exports and mounts: file sharing between Linux machines

    NFS is the simplest sharing between Linux machines: no account system, just IPs and UID mapping. Measured nfs-utils 2.9.2.

    Terminal window
    sudo dnf install -y nfs-utils

    Prepare a directory and write the export rule — prefer /etc/exports.d/*.exports fragments over the monolithic exports file (upgrades will not clobber them):

    Terminal window
    sudo mkdir -p /srv/nfstest
    echo "nfs-hello" | sudo tee /srv/nfstest/n.txt
    echo "/srv/nfstest 127.0.0.1(ro)" | \
    sudo tee /etc/exports.d/test.exports
    Terminal window
    sudo systemctl enable --now nfs-server
    sudo exportfs -ra # apply all rules
    sudo exportfs -v # show effective rules

    Measured -v output (every default spelled out):

    /srv/nfstest 127.0.0.1(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)

    The important ones:

    OptionMeaningWhen to change
    ro / rwread-only / read-writemedia libraries ro, collaboration rw
    root_squashclient root maps to nobodydefault on, keep it
    syncacknowledge after disk writedefault; async risks data loss
    no_subtree_checkskip subtree checksdefault on, fewer false alarms
    secureclients must use a privileged portkeep when clients are system services
    Terminal window
    sudo mkdir -p /mnt/nfstest
    sudo mount -t nfs4 127.0.0.1:/srv/nfstest /mnt/nfstest
    cat /mnt/nfstest/n.txt
    sudo umount /mnt/nfstest

    Measured: cat prints nfs-hello — the exported content is readable, chain verified.

    For fstab (_netdev waits for the network; soft keeps the client from hanging if the server dies):

    server-ip:/srv/nfstest /mnt/nfstest nfs4 _netdev,soft,timeo=50 0 0

    Fixed fstab entries hold connections open even when unused. autofs mounts only when you enter the directory:

    /srv/nfstest
    sudo dnf install -y autofs
    # /etc/auto.master.d/nfs.autofs: /mnt/nfs /etc/auto.nfs
    sudo systemctl enable --now autofs
    ls /mnt/nfs/nfstest # actual mount happens here

    With many servers and dozens of export points, autofs scales far better than fstab.

    Terminal window
    sudo firewall-cmd --add-service=nfs --permanent
    sudo firewall-cmd --add-service=rpc-bind --permanent
    sudo firewall-cmd --add-service=mountd --permanent
    sudo firewall-cmd --reload

    All three: nfs (2049), rpc-bind (111), mountd (dynamic port). Missing mountd is the classic cause of “showmount works but mount hangs”.

    Default root_squash maps client root to server nobody — a feature: a compromised client does not get server root. To let a directory accept root writes (fully trusted LANs only):

    /srv/nfstest 127.0.0.1(rw,no_root_squash)

    Regular users are unaffected by squashing: client UID 1000 reads and writes server UID 1000’s files naturally. Environments with mismatched UIDs should unify accounts (FreeIPA/LDAP) before using NFS, otherwise file ownership becomes chaos.

    SymptomCause
    mount hangs forevermountd port blocked by firewall (allow all three services)
    write Permission deniedserver directory permissions, or export is ro
    root cannot writeroot_squash in effect (default); needs explicit no_root_squash
    exports change does nothingforgot exportfs -ra
    client boot hangs on mountfstab entry lacks _netdev and soft
    files owned by nobodyUIDs differ between the two machines