/etc/exports
The /etc/exports file is a configuration file used by the Network File System (NFS) server on Unix-like operating systems to specify which directories are to be shared (exported) over the network and the access permissions for these directories.
Structure of /etc/exports
/etc/exportsEach line in the /etc/exports file specifies a directory to be shared and the options for sharing it. The general syntax is:
directory client(options) client(options) ...directory: The path to the directory on the NFS server that is to be shared.
client: The hostname or IP address of the client that is allowed to access the shared directory.
options: A set of options specifying how the directory is shared and what permissions the client has.
Example /etc/exports File
/etc/exports File# Share /srv/nfs to a specific client with read-write access
/srv/nfs 192.168.1.100(rw,sync,no_subtree_check)
# Share /home directory to all clients in the 192.168.1.0/24 network with read-only access
/home 192.168.1.0/24(ro,sync,no_subtree_check)
# Share /var/nfs with two specific clients with read-write access and root squashing
/var/nfs 192.168.1.101(rw,sync,no_subtree_check,root_squash) 192.168.1.102(rw,sync,no_subtree_check,root_squash)Options Explained
rw: Allow read and write access to the shared directory.
ro: Allow read-only access to the shared directory.
sync: Ensure that changes to the shared directory are immediately written to disk.
no_subtree_check: Disable subtree checking, which improves performance.
root_squash: Map requests from root on the client to an anonymous UID/GID on the server, enhancing security.
no_root_squash: Allow root on the client to have root privileges on the server.
anonuid: Specify the UID of the anonymous account.
anongid: Specify the GID of the anonymous account.
all_squash: Map all user and group IDs to the anonymous user.
Managing NFS Exports
After editing /etc/exports, use the following commands to apply changes and manage the NFS server:
Apply Export Changes
sudo exportfs -raShow Current NFS Exports
sudo exportfs -vStart NFS Server
sudo systemctl start nfs-serverEnable NFS Server at Boot
sudo systemctl enable nfs-serverRestart NFS Server
sudo systemctl restart nfs-serverSetting Up an NFS Server and Client
NFS Server Setup
Install NFS Server Package
On Debian/Ubuntu:
sudo apt update sudo apt install nfs-kernel-serverOn CentOS/RHEL:
sudo yum install nfs-utilsEdit
/etc/exportssudo nano /etc/exportsAdd the directories you want to share.
Apply Export Changes
sudo exportfs -raStart and Enable NFS Server
sudo systemctl start nfs-server sudo systemctl enable nfs-server
NFS Client Setup
Install NFS Client Package
On Debian/Ubuntu:
sudo apt update sudo apt install nfs-commonOn CentOS/RHEL:
sudo yum install nfs-utilsCreate Mount Point
sudo mkdir -p /mnt/nfsMount NFS Share
sudo mount -t nfs 192.168.1.100:/srv/nfs /mnt/nfsVerify Mount
df -h | grep nfsAutomatic Mount at Boot
Add the following line to
/etc/fstab:192.168.1.100:/srv/nfs /mnt/nfs nfs defaults 0 0
Security Considerations
Restrict Access: Only allow specific clients or networks to access NFS shares.
Use Firewalls: Ensure that only trusted IP addresses can connect to the NFS server.
Secure Options: Use
root_squashand other secure options to limit potential damage from compromised clients.Network Security: Consider using a VPN or secure network for NFS traffic.
Conclusion
The /etc/exports file is a vital part of configuring an NFS server, allowing administrators to specify which directories are shared and the permissions granted to different clients. Proper management and security considerations are essential to ensure reliable and secure NFS operations.
Last updated