Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
script for installing nfs server and client
#Step 1: Install NFS Common
sudo apt-get update -y
sudo apt-get install nfs-common -y
#Step 2: Create a mount point for the NFS host’s shared folder
#Your client’s system needs a directory where all the content shared by the host server in the export folder can be accessed.
#You can create this folder anywhere on your system. We are creating a mount folder in the mnt directory of our client’s machine.
sudo mkdir -p $CLIENT_NFS_DIR
#Step 3: Mount the shared directory on the client
# Step 1: Install NFS Kernel Server
sudo apt-get update -y
sudo apt install nfs-kernel-server -y
#Step 2: Create the Export Directory
sudo mkdir -p $SERVER_NFS_DIR
sudo chown nobody:nogroup $SERVER_NFS_DIR
sudo chmod 777 $SERVER_NFS_DIR
#Step 3: Assign server access to client(s) through NFS export file
# rw: read and write operations
# sync: write any change to the disc before applying it
# no_subtree_check: prevent subtree checking
sudo bash -c "echo '$SERVER_NFS_DIR $SUBNET_IP/24(rw,sync,no_subtree_check)' >> /etc/exports"
#Step 4: Export the shared directory
sudo exportfs -a
sudo systemctl restart nfs-kernel-server
#Step 5: Open firewall for the client (s)
sudo ufw enable
sudo ufw allow from $SUBNET_IP/24 to any port nfs
sudo ufw status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment