How to set up and mount NFS on Ubuntu?
To set up and mount NFS on Ubuntu, you need to follow these steps:
- Install NFS server software:
- Run the following command in the terminal to install NFS server software: sudo apt-get install nfs-kernel-server.
- Set up an NFS server.
- Edit the NFS server configuration file /etc/exports using the following command: sudo nano /etc/exports.
- Add the directory and access permissions you want to share in the file. For example, to share the /home/user/shared directory and allow all clients to access it, you can add the following line: /home/user/shared *(rw,sync,no_root_squash,no_subtree_check)
- Save and close the file.
- Start the NFS server.
- To start the NFS server in the terminal, run the following command: sudo systemctl start nfs-kernel-server.
- If necessary, you can use the following command to set the NFS server to start at boot: sudo systemctl enable nfs-kernel-server.
- Mount NFS share:
- Create a directory on the client side to mount the NFS share. For example, you can create a directory named “shared” under the /mnt/nfs directory: sudo mkdir -p /mnt/nfs/shared.
- Run the following command in the terminal to mount an NFS share: sudo mount server_ip:/home/user/shared /mnt/nfs/shared, where server_ip is the IP address of the NFS server.
- You can also use the following command to automatically mount NFS shares at startup: sudo nano /etc/fstab, and then add the following line: server_ip:/home/user/shared /mnt/nfs/shared nfs defaults 0 0
- Save and close the file.
Note: Ensure that both the server and client have their firewalls configured to allow NFS traffic to pass through in order to facilitate proper communication.