Sharing Files in a LAN using NFS
Workflow short description
We assume a Lan in a home. In the simplest casewe want a pc acting as a file server to share a folder of files to other pcs that acting as client can access the shared folder.
We assume statip IPs for the server and the client.
Care must be taken for the case that the nfs server is not operational or \ nor accessible. Then various applications in the client could have issues.
Related workflows:
Contributions
Ideas to use autofs,leased ips :
Workflow sheet
The workflow sheet ideally would be printed by the sysadmin and be used as a placeholder of crucial info and as a reminder of workflow steps.
data | value | notes |
---|---|---|
NFS Server IP | x.x.x.x | |
NFS Client IP | x.x.x.x |
About NFS
Using fstab
Preconditions
ip addresses
Server and client must have an IP. ( Setting up networking? )
We assume that both the NFS server and the NFS client have static ips.
To find the IPs of the server and the client we use :
$ sudo ifconfig or $ sudo ip addr showTest basic connectivity with ping:
(client) $ ping <nfs-server-ip> (server) $ ping <nfs-client-ip>
Server
install related deb packages
[server] $ sudo apt-get install nfs-kernel-server nfs-common
define export folder in server
$ man 5 exports (ref -> [[man7.org -> https://man7.org/linux/man-pages/man5/exports.5.html]]
[server] $ sudo nano /etc/exports ... /home/chomwitt/NFSServerExport 192.168.1.41(rw,sync,no_subtree_check) ... ^^^^^^^^^^^^ ^^^^^^^^^^^ | | | ip of the client pathdir we want to make available to the client
fix user permissions
I am not sure that this section is necessary.,
It's very possible that the above export wont work due to user accounts on the server and client with the same name having different uid:
[server]$ id uid=1000(chomwitt) gid=1000(chomwitt) groups=1000(chomwitt) [client]$ id uid=1001(chomwitt) gid=1001(chomwitt) groups=1001(chomwitt) . And following that solution the : [server] sudo nano /etc/exports changes to: .... /home/chomwitt/NFSServerSHARE 192.168.1.41(rw,all_squash,anonuid=1000,anongid=1000,sync,no_subtree_check) .... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
restarting nfs server
with sysvinit
[server] $ /etc/init.d/nfs-kernel-server restart
with runit
Client
install nfs related packages
$ sudo apt install nfs-common
verify that that nfs server's shares are accessible
showmount is an utility in the nfs-common package:
$ dpkg -S showmount nfs-common: /sbin/showmount
We can use showmount to query a remote NFS server about it's state.
$ sudo showmount -e <NFS-SERVER IP>
set access to the nfs server
[client] $ mkdir ~/NFSImport [client] $ sudo mount <nfs_srv_ip>:/path/to/dir /home/foouser/NFSImport/
Using autofs
/etc/init.d/autofs start ------------> /etc/auto.master \ | \ (find mount points) \_________ / \ / --------- | create an automount thread for each mount point