NFS Server and Client with Static Ports (Firewall ready)
This caused me a bit of a headache… mostly with nlockmgr, and as I know this caused me headache last time too (pages I’d bookmarked had all gone the way of a 404) here’s a quick guide to setting up an NFS server on a Ubuntu 9.10 Karmic Koala server.
NFS SERVER
1. Install NFS
sudo apt-get install nfs-kernel-server nfs-common portmap
2. Create a share
mkdir /files
sudo vim /etc/exports
Then add your share to that file:
/files 192.168.1.0/24(rw,no_root_squash,async,no_subtree_check)
Which gives full read/write permissions to the IP range 192.168.1.1 through 192.168.1.255 which is the private range I’m working on.
Save that and restart the service:
sudo /etc/init.d/nfs-kernel-server restart
And as we’ve changed /etc/exports… update that:
sudo exportfs -a
3. Make all of the ports static
Edit /etc/default/nfs-common:
sudo vim /etc/default/nfs-common
To update the STATDOPTS line thus:
STATDOPTS="--port 4000"
Save that and restart the service:
sudo /etc/init.d/nfs-common restart
Edit /etc/default/nfs-kernel-server:
sudo vim /etc/default/nfs-kernel-server
To update the RPCMOUNTDOPTS:
RPCMOUNTDOPTS="--p 4002"
Save and restart:
sudo /etc/init.d/nfs-kernel-server restart
And this is the one that caught me out… nlockmgr, edit /etc/sysctl.conf:
sudo vim /etc/sysctl.conf
And add the following two lines to the bottom of the file:
fs.nfs.nlm_tcpport=4001
fs.nfs.nlm_udpport=4001
Save and reboot the server:
sudo reboot
When the server comes up, do the following to see the changes:
rpcinfo -p
Which should give you something like this:
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 4000 status
100024 1 tcp 4000 status
100021 1 udp 4001 nlockmgr
100021 3 udp 4001 nlockmgr
100021 4 udp 4001 nlockmgr
100021 1 tcp 4001 nlockmgr
100021 3 tcp 4001 nlockmgr
100021 4 tcp 4001 nlockmgr
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100005 1 udp 4002 mountd
100005 1 tcp 4002 mountd
100005 2 udp 4002 mountd
100005 2 tcp 4002 mountd
100005 3 udp 4002 mountd
100005 3 tcp 4002 mountd
And you’re done… one NFS server with static ports serving to a private range of IPs.
NFS CLIENT
This bit is much simpler.
Install the software:
sudo apt-get install portmap nfs-common
Create the directory that will reflect the NFS share:
sudo mkdir /files
Mount the share onto the empty directory (replace the IP address with the IP or FQDN of your NFS server):
sudo mount 192.168.1.29:/files /files
You can then test this by creating a file via the share. If you get a permissions error go check the permissions on the NFS server, specifically the directory permissions for /files.
To automatically mount the directory at boot time we need to add an entry to fstab:
sudo vim /etc/fstab
Then add a line to the end of that file (again ensuring to insert the IP or FQDN for your NFS server):
192.168.1.29:/files /files nfs rsize=8192,wsize=8192,timeo=14,intr
And before you reboot, just test that:
sudo mount /files
There… now you have an NFS client connected to your NFS server
Credits:
http://ubuntuforums.org/showthread.php?t=249889
http://ubuntuforums.org/showthread.php?t=352486
https://bugzilla.redhat.com/show_bug.cgi?id=434795
No Comments, Comment or Ping
Reply to “NFS Server and Client with Static Ports (Firewall ready)”