Setting Up An NFS Server And Client On OpenSUSE 11.3

Version 1.0
Author: Falko Timme
Follow me on Twitter
Last edited 09/14/2010

This guide explains how to set up an NFS server and an NFS client on OpenSUSE 11.3. NFS stands for Network File System; through NFS, a client can access (read, write) a remote share on an NFS server as if it was on the local hard disk.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I'm using two OpenSUSE systems here:

  • NFS Server: server.example.com, IP address: 192.168.0.100
  • NFS Client: client.example.com, IP address: 192.168.0.101

 

2 Installing NFS

server:

On the NFS server we run:

yast2 -i nfs-kernel-server

Then we create the system startup links for the NFS server and start it:

chkconfig --add nfsserver
/etc/init.d/nfsserver start

client:

On the client we can install NFS as follows:

yast2 -i nfs-client

 

3 Exporting Directories On The Server

server:

I'd like to make the directories /home and /var/nfs accessible to the client; therefore we must "export" them on the server.

When a client accesses an NFS share, this normally happens as the user nobody. Usually the /home directory isn't owned by nobody (and I don't recommend to change its ownership to nobody!), and because we want to read and write on /home, we tell NFS that accesses should be made as root (if our /home share was read-only, this wouldn't be necessary). The /var/nfs directory doesn't exist, so we can create it and change its ownership to nobody and nogroup:

mkdir /var/nfs
chown nobody:nogroup /var/nfs

Now we must modify /etc/exports where we "export" our NFS shares. We specify /home and /var/nfs as NFS shares and tell NFS to make accesses to /home as root (to learn more about /etc/exports, its format and available options, take a look at

man 5 exports

)

vi /etc/exports

# See the exports(5) manpage for a description of the syntax of this file.
# This file contains a list of all directories that are to be exported to
# other computers via NFS (Network File System).
# This file used by rpc.nfsd and rpc.mountd. See their manpages for details
# on how make changes in this file effective.

/home           192.168.0.101(rw,sync,no_root_squash,no_subtree_check)
/var/nfs        192.168.0.101(rw,sync,no_subtree_check)

(The no_root_squash option makes that /home will be accessed as root.)

Whenever we modify /etc/exports, we must run

exportfs -a

afterwards to make the changes effective.

 

4 Mounting The NFS Shares On The Client

client:

First we create the directories where we want to mount the NFS shares, e.g.:

mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfs

Afterwards, we can mount them as follows:

mount 192.168.0.100:/home /mnt/nfs/home
mount 192.168.0.100:/var/nfs /mnt/nfs/var/nfs

You should now see the two NFS shares in the outputs of

df -h

client:~ # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              12G  1.3G  9.8G  12% /
devtmpfs              245M  132K  245M   1% /dev
tmpfs                 247M  4.0K  247M   1% /dev/shm
/dev/sda3              18G  172M   17G   2% /srv
192.168.0.100:/home    12G  1.5G  9.6G  14% /mnt/nfs/home
192.168.0.100:/var/nfs
                       12G  1.5G  9.6G  14% /mnt/nfs/var/nfs
client:~ #

and

mount

client:~ # mount
/dev/sda2 on / type ext4 (rw,acl,user_xattr)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
debugfs on /sys/kernel/debug type debugfs (rw)
devtmpfs on /dev type devtmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,mode=1777)
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
/dev/sda3 on /srv type ext4 (rw,acl,user_xattr)
securityfs on /sys/kernel/security type securityfs (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,addr=192.168.0.100)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,addr=192.168.0.100)
client:~ #

 

5 Testing

On the client, you can now try to create test files on the NFS shares:

client:

touch /mnt/nfs/home/test.txt
touch /mnt/nfs/var/nfs/test.txt

Now go to the server and check if you can see both test files:

server:

ls -l /home/

server:~ # ls -l /home/
total 4
drwxr-xr-x 6 administrator users 4096 Jul 19 17:26 administrator
-rw-r--r-- 1 root          root     0 Sep 14 20:47 test.txt
server:~ #

ls -l /var/nfs

server:~ # ls -l /var/nfs
total 0
-rw-r--r-- 1 nobody nogroup 0 Sep 14 20:47 test.txt
server:~ #

(Please note the different ownerships of the test files: the /home NFS share gets accessed as root, therefore /home/test.txt is owned by root; the /var/nfs share gets accessed as nobody, therefore /var/nfs/test.txt is owned by nobody.)

 

6 Mounting NFS Shares At Boot Time

Instead of mounting the NFS shares manually on the client, you could modify /etc/fstab so that the NFS shares get mounted automatically when the client boots.

client:

Open /etc/fstab and append the following lines:

vi /etc/fstab

[...]
192.168.0.100:/home  /mnt/nfs/home   nfs      rw,sync,hard,intr  0     0
192.168.0.100:/var/nfs  /mnt/nfs/var/nfs   nfs      rw,sync,hard,intr  0     0

Instead of rw,sync,hard,intr you can use different mount options. To learn more about available options, take a look at

man nfs

To test if your modified /etc/fstab is working, reboot the client:

reboot

After the reboot, you should find the two NFS shares in the outputs of

df -h

client:~ # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              12G  1.3G  9.8G  12% /
devtmpfs              245M  132K  245M   1% /dev
tmpfs                 247M  4.0K  247M   1% /dev/shm
/dev/sda3              18G  172M   17G   2% /srv
192.168.0.100:/home    12G  1.5G  9.6G  14% /mnt/nfs/home
192.168.0.100:/var/nfs
                       12G  1.5G  9.6G  14% /mnt/nfs/var/nfs
client:~ #

and

mount

client:~ # mount
/dev/sda2 on / type ext4 (rw,acl,user_xattr)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
debugfs on /sys/kernel/debug type debugfs (rw)
devtmpfs on /dev type devtmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,mode=1777)
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
/dev/sda3 on /srv type ext4 (rw,acl,user_xattr)
securityfs on /sys/kernel/security type securityfs (rw)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,sync,hard,intr,addr=192.168.0.100)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,sync,hard,intr,addr=192.168.0.100)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
client:~ #

 

7 Links

Share this page:

8 Comment(s)

Add comment

Comments

From: Anonymous at: 2010-09-20 04:42:11

Most of it is the same on Ubuntu / Debian just exchange "yast2 -i" for "apt-get install". You should also be able to skip "chkconfig --add nfsserver". It's been awhile since I last installed NFS but that should be all the changes you need.

From: Caldavien at: 2010-09-16 15:56:36

I liked this walkthrough but would love to see the same this for a ubuntu server/client set up. Hopefully I can carry over some of this to help with my current ubuntu setup.

From: Juan at: 2011-01-24 21:40:20

Thanks bud, great article! I had to replace yast2 for zypper, but otherwise great!

From: scarter at: 2011-02-10 06:02:03

One thing, though -- if you're absent-minded, as I am, you may spend half a day trying to figure out why the mount operation sin step 4 times out even though the two machines can ping each other, before you remember to change your firewall settings to allow NIFS access on the ports it needs.

From: at: 2011-02-19 05:02:16

Recently I discovered autofs and it's ability to automount nfs shares when the user tries to access it.

 Install autofs and in /etc/auto.master uncomment "#/net -hosts"

The system will now automatically access any system with it's name in the hosts file

For example '$ls /net/falko' will mount 192.168.0.100 right away (assuming /etc/hosts contains the line '192.168.0.100 falko'). 

I prefer that over boot time mounts in fstab.

From: Anonymous at: 2014-01-23 15:52:05

Very, very nice. Thanks for your time

From: yasser at: 2014-08-28 03:02:21

Hi,

Please i need help, this is a copy-paste from the terminal, i am using OpenSuse

client1:~ # yast2 -i nfs-kernel-server

client1:~ # chkconfig --add nfsserver

nfsserver: unknown service

Could someone tell me why do i get this, and how to fix it?

Thank you

From: Sreeraj at: 2014-12-29 09:57:15

Hi my NFS server and client both are suse 11.When i tried to mount  from client i am getting error.

mount -t nfs4 10.11.1.5:/usr/sap/trans/ /usr/sap/transnfs/
mount.nfs4: No such device