May 2, 2007 · Server ·

Sponsored Link
NFS was developed at a time when we weren't able to share our drives like we are able to today -- in the Windows environment. It offers the ability to share the hard disk space of a big server with many smaller clients. Again, this is a client/server environment. While this seems like a standard service to offer, it was not always like this. In the past, clients and servers were unable to share their disk space.

Thin clients have no hard drives and thus need a "virtual" hard-disk. The NFS mount their hard disk from the server and, while the user thinks they are saving their documents to their local (thin client) disk, they are in fact saving them to the server. In a thin client environment, the root, usr and home partitions are all offered to the client from the server via NFS.

NFS Advantages

• Local workstations use less disk space because commonly used data can be stored on a single machine and still remain accessible to others over the network.

• There is no need for users to have separate home directories on every network machine. Home directories could be set up on the NFS server and made available throughout the network.

• Storage devices such as floppy disks, CDROM drives, and Zip® drives can be used by other machines on the network. This may reduce the number of removable media drives throughout the network.

Install NFS Server in Ubuntu

sudo apt-get install nfs-kernel-server nfs-common portmap

When configuring portmap do =not= bind loopback. If you do you can either edit /etc/default/portmap using the following

sudo vi /etc/default/portmap

or use the following command

sudo dpkg-reconfigure portmap

Restart Portmap using the following command

sudo /etc/init.d/portmap restart

NFS Server Configuration

NFS exports from a server are controlled by the file /etc/exports. Each line begins with the absolute path of a directory to be exported, followed by a space-seperated list of allowed clients.

You need to edit the exports file using the following command

sudo vi /etc/exports

Here are some quick examples of what you could add to your /etc/exports

For Full Read Write Permissions allowing any computer from 192.168.1.1 through 192.168.1.255

/files 192.168.1.1/24(rw,no_root_squash,async)

Or for Read Only from a single machine

/files 192.168.1.2 (ro,async)

save this file and exit

A client can be specified either by name or IP address. Wildcards (*) are allowed in names, as are netmasks (e.g. /24) following IP addresses, but should usually be avoided for security reasons.

A client specification may be followed by a set of options, in parenthesis. It is important not to leave any space between the last client specification character and the opening parenthesis, since spaces are intrepreted as client seperators.

Now you need to restart NFS server using the following command

sudo /etc/init.d/nfs-kernel-server restart

If you make changes to /etc/exports on a running NFS server, you can make these changes effective by issuing the command

sudo exportfs -a

Install NFS client support in Ubuntu

sudo apt-get install portmap nfs-common

This will install all the required packages for nfs client

Mounting manually

Example to mount server.mydomain.com:/files to /files. In this example server.mydomain.com is the name of the server containing the nfs share, and files is the name of the share on the nfs server

The mount point /files must first exist on the client machine.

Create files directory using the following command

sudo mkdir files

You need to mount the share using the following command

sudo mount server.mydomain.com:/files /files

Now you may need to restart services using the following command

sudo /etc/init.d/portmap restart

sudo /etc/init.d/nfs-common restart

Mounting at boot using /etc/fstab

If you want to mount using fstab file

sudo vi /etc/fstab

In this example my /etc/fstab was like this

server.mydomain.com:/files /files nfs rsize=8192,wsize=8192,timeo=14,intr

Change “servername.mydomain.com:/files”, and “/files” to match your server name,share name, and the name of the mount point you created.

Firewall Ports for NFS

If you have a firewall you need to make sure ports 32771, 111 and 2049 are open
Testing Your Configuration

Use the following command in terminal to test

mount /files

the mount point /files will be mounted from the server.

Reference

http://czarism.com/easy-peasy-ubuntu-linux-nfs-file-sharing

Sponsored Link

23 Comments to “NFS Server and Client Configuration in Ubuntu”

  1. John says:

    I already try NFS like this. But if I create a openoffice file on share folder, why my friend can not edit that file from another computer?

  2. zukakog says:

    NFS can be tricky because it uses the same permissions as your local drive. Someone with UID=1000 and GID=1000 saves a file, with permissions 770, on an NFS share. Only those with the same UID or GID can read/write the file.

    I use NFS for all of my desktop computers, but I have a laptop that runs Vista Ultimate. With Vista Ultimate (and Windows XP), you can install Services for Unix, which includes support for NFS. My problem is that Vista and XP seem to send UID and GID as -2. I can’t figure out how to change them. Anyone have any suggestions?

  3. Jeff Coleman says:

    NFS Server Configuration worked like a charm, great tutorial.

  4. El Cerrajero says:

    # Zukakog, use NFS in combination with NIS o LDAP to avoid that problem

    # John: you can’t edit a document opened by another user because is locked, but you can edit it ‘after it is closed’ just taking in account file’s permissions.

  5. Bob says:

    One thing I’ve been unhappy with is that when I try to mount an NFS share off my server (debian machine) onto my laptop, I get a seg fault. Every time. This only happens with Ubuntu, been using NFS for years with various distros and IRIX. I don’t care enough to really track it down, but after reading this and trying to mount the share (works fine on other machines), I get a seg fault. Dammit.

    Nice tutorial by the way. Most people are surprised at how simple NFS, usually after going through SAMBA configuration dance.

  6. jeffcobb says:

    I like and use NFS but have noticed on a LAN of mixed Deb and Ubuntu boxen, the debs all mount remote dirs ~ 5x faster than the Ubuntu boxen. No idea why but the initial mount is nothing less than painful.

  7. czar says:

    Great tut…

    @zukakog:
    simply change file access permissions to any data written from the NFS mounts in Linux, as windows requires WORLD READ/WORLD WRITE

    sudo chmod -R 0777 /home/czar/my_nas_share_folder/

    Now pop back to Windows and feel the insecurity.

  8. John says:

    I think, this still not solve my question. I’m already try NFS+NIS. So everyone can make new file on share folder. But my ubuntu still give permission new file 644 with owner user.user. N another user, can not change that file. Just read only

    How to make my Ubuntu give permission (on the fly) 660 every new file created by user on share folder. N change the group owner as group “finance” as example.

    Any solusion with this? Cause with samba i can use this option:
    create mask = 0660
    directory mask = 0770
    force group = finance

  9. ben says:

    i have an ubuntu dapper server and a feisty client. the server has nfs configured since hoary and everything worked fine.
    but after upgrading from edgy to feisty on my client, the “mount” – command does not show up the mounted nfs directories even if i am working on it.
    “nfsstat -m” shows them all up.

    output of mount:

    %mount
    /dev/sda1 on / type ext3 (rw)
    proc on /proc type proc (rw,noexec,nosuid,nodev)
    /sys on /sys type sysfs (rw,noexec,nosuid,nodev)
    varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
    varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
    procbususb on /proc/bus/usb type usbfs (rw)
    udev on /dev type tmpfs (rw,mode=0755)
    devshm on /dev/shm type tmpfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    lrm on /lib/modules/2.6.20-15-generic/volatile type tmpfs (rw)
    /dev/sda3 on /home type ext3 (rw,user_xattr)
    /dev/sda4 on /var type ext3 (rw,user_xattr)
    nfsd on /proc/fs/nfsd type nfsd (rw)
    rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

    output of “nfsstat -m”


    /NFS/tohuwabohu/media from tohuwabohu:/data/media
    Flags: rw,vers=3,rsize=8192,wsize=8192,hard,intr,proto=tcp,timeo=600,retrans=2,sec=sys,addr=tohuwabohu

    /NFS/tohuwabohu/music from tohuwabohu:/data/media/music
    Flags: rw,vers=3,rsize=8192,wsize=8192,hard,intr,proto=tcp,timeo=600,retrans=2,sec=sys,addr=tohuwabohu

    /NFS/tohuwabohu/os-backup from tohuwabohu:/backup
    Flags: rw,vers=3,rsize=8192,wsize=8192,hard,intr,proto=tcp,timeo=600,retrans=2,sec=sys,addr=tohuwabohu

    /NFS/tohuwabohu/backup from tohuwabohu:/data/backup
    Flags: rw,vers=3,rsize=8192,wsize=8192,hard,intr,proto=tcp,timeo=600,retrans=2,sec=sys,addr=tohuwabohu

    /NFS/tohuwabohu/transfer from tohuwabohu:/data/transfer
    Flags: rw,vers=3,rsize=8192,wsize=8192,hard,intr,proto=tcp,timeo=600,retrans=2,sec=sys,addr=tohuwabohu

    /NFS/tohuwabohu/software from tohuwabohu:/data/software
    Flags: rw,vers=3,rsize=8192,wsize=8192,hard,intr,proto=tcp,timeo=600,retrans=2,sec=sys,addr=tohuwabohu

    /NFS/tohuwabohu/ben from tohuwabohu:/home/ben
    Flags: rw,vers=3,rsize=8192,wsize=8192,hard,intr,proto=tcp,timeo=600,retrans=2,sec=sys,addr=tohuwabohu

    if i mount one additional directory manually from the server, the mount – comamand shows it up as i would expect it.

    does anybody know, what is went wrong?

    ben

  10. Nathan says:

    @Jeffcobb: We just debugged this on our own systems. You have to make sure that portmap is installed on the Ubuntu boxen. Otherwise the mount takes ages but eventually succeeds.

  11. Southernman says:

    Thank you – works perfectly. Like I need to tell the Ubuntu-Geek this!

  12. rainman says:

    Hi, I’m new to Ubuntu and I need help. I have 7.04 everything so far so good. But I’m trying to share my hard drives from Ubuntu with my Vista Machine. I followed the direction above and from other instructions. But no luck. I’m having these issues if someone would help:

    my /etc/exports file has this line only:
    /media/hdb1/DVArchive_files/Local_Guide 192.168.1.1/24(rw,no_root_squash,async)

    When I run sudo exportfs -a I get this error
    exportfs: /etc/exports [1]: Neither ‘subtree_check’ or ‘no_subtree_check’ specified for export “192.168.1.1/24:/media/hdb1/DVArchive_files/Local_Guide”.
    Assuming default behaviour (‘subtree_check’).
    Note: this default will change with nfs-utils version 1.1.0

    Any idea what does this mean.
    Also can you please direct me to instruction on how to set nfs on Vista?

    Thanks
    Sam

  13. Alfe says:

    Hi, I have the same problem as Ben above does: The mount command does not show the NFS mounts created at boot time. Upon umounting and mounting them again, they are shown properly. I too have feisty running, but my NFS servers vary (SuSE and dapper server). So I assume only the client matters for this issue.

    My NFS mounts show up in /proc/mounts though.

    Any information on this topic would be greatly appreciated (even more if sent to ubuntugeek#alfe.de (replace the # by a @))

    Thanks!

    Alfe

  14. rbm0307 says:

    Sam,

    This is an informational message, not an error. Add the “subtree_check” option to each of your entries in /etc/exports; for example, (rw,no_root_squash,async,subtree_check). The message will disappear. As it stands, your NFS should be operational with or without this option in /etc/exportfs.

    Robert.

  15. Scott P says:

    Just a quick note – you don’t have to restart the NFS server whenever you make a config change – just issue the “exportfs -a” command.

  16. James says:

    Great tutorial. Two problems that I had and solutions for anyone experiencing the same thing.
    1) I was getting a permission denied error when mounting
    sudo mount server.mydomain.com:/files /files
    I found that changing the
    /etc/exports
    line to
    /files 192.168.1.0/255.255.255.0(rw,no_root_squash,async)
    fixed the problem. Source.

    2)In altering the /etc/fstab file I needed to add
    0 0
    to the end of the line so it read
    server.mydomain.com:/files /files nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
    Found that here. Thanks

  17. Chris says:

    Guys, this is a great tutorial, but


    /files 192.168.1.1/24(rw,no_root_squash,async)

    is insanely insecure… As long as you never have / shared like this it’s ok, but no_root_squash is generally a Bad Idea.

  18. jonDoeParkLane66 says:

    From the way you spin it is their any disernable difference to samba?

  19. lmthong says:

    zukakog says:
    May 3, 2007 at 7:38 pm

    NFS can be tricky because it uses the same permissions as your local drive. Someone with UID=1000 and GID=1000 saves a file, with permissions 770, on an NFS share. Only those with the same UID or GID can read/write the file.

    I use NFS for all of my desktop computers, but I have a laptop that runs Vista Ultimate. With Vista Ultimate (and Windows XP), you can install Services for Unix, which includes support for NFS. My problem is that Vista and XP seem to send UID and GID as -2. I can’t figure out how to change them. Anyone have any suggestions?
    ———————–

    I use ldap as a central authentication like DC (include uid/gid attributes) on NFS Server. Use pam-ldap for an other authentication method from linux client: log-in, get uid/gid from ldap, access to NFS.

    Use pGina (http://www.pgina.org) for an other authentication method from Windows platform to ldap: log-in, get uid/gid from ldap, access to NFS.

    Is it enough for you? 🙂

  20. Aaron says:

    /etc/init.d/nfs-kernel-server requires localhost to be defined in /etc/hosts

  21. tshenolo tau says:

    Hi, all iwas asking is how the mkparted command do

  22. marx says:

    You have an extra space so default options will be applied to 192.168.1.2 and all other hosts will be given (ro,async).

    /files 192.168.1.2 (ro,async)

  23. pankaj joshi says:

    wat pemission shal i set for the home folder on the server so that user can get only access to their directory under home folder and not on the home folder itself.

    thank you

Leave a Reply

  • Recent comments