Advertisment

Share Directories between Linux Machines

author-image
PCQ Bureau
New Update

We generally talk about how to make Linux share resources–likedisk directories–with Windows, and in past issues of PC Quest, we’ve shownyou how to do this using Samba. But what if you have two or more Linux machineson a network and want to access the disk directories of one Linux machine fromthe other? The solution for this is NFS, short for Network File System.

Advertisment

The NFS protocol was developed by Sun and is a standard forUnix-Unix disk sharing. NFS is based on the concept of server and client. Themachine whose disk directories you want to access is the server, and the machinefrom which you access the server’s disk directories is the client. The serviceis available in the Red Hat Linux distribution carried in our PCQ CDs (you’llfind the latest distribution–Red Hat Linux 6.2–on the June 2000 PCQ CD).

To start NFS service on the server, type:

/etc/rc.d/init.d/portmap start

Advertisment

/etc/rc.d/init.d/nfs start

Here, portmap is a Linux daemon service for running the RPC(Remote Procedural Calls) protocol. NFS uses this protocol for communicationover the network. To run portmap and NFS automatically on reboot, run ntsysv onthe console as:

ntsysv

Advertisment

Then, select the services portmap and nfs. Once you’vestarted the NFS server, you need to tell it which directories are to be shared,with which clients, and what kind of access should be provided. These arespecified in a file named exports in /etc directory.

Let’s assume that the name of our NFS server is pcq, withIP address 192.168.1.1, while the name of our client is shekhar with IP address192.168.1.2. Both are in the same domain–pcqlabs. On the pcq machine, edit thefile /etc/exports using a text editor like vi or joe and insert a line as:

/nfs-share shekhar(rw)

Advertisment

Initially, the file is empty, so this will be the first line.The line uses the following format:

directory-to-share host name1 (permissions)hostname2(permissions)

In our case, the machine named shekhar can read and writeinto the directory nfs-share on the machine pcq. nfs-share is not a standardLinux directory and must be created using the mkdir command. You can also usethe IP address if a machine can’t be located by its hostname, for example, ifyou aren’t running a DNS server. You can give access to multiple clients bysimply entering their hostnames and permissions in this format.

Advertisment

To allow all machines in the pcqlabs domain to access thedirectory /nfs-share, enter:

/nfs-share *.pcqlabs(rw)

Other than the IP address and hostname, you can also useaddress/netmask format. For instance, to match all machines in the network192.168.1.x having netmask 255.255.255.0, enter:

Advertisment

/nfs-share 192.168.1.0/24(rw)

The permissions you can give include:

rw : read-write access

Advertisment

ro : read-only access

noaccess : denies access to subdirectories below thespecified directory

no_root_squash : trust the client’s root account

anonuid= : set the anonymous user id to for NFS

anongid= : set the anonymous group id to for NFS

By default, the root user from the NFS client is mapped tothe user nobody of group nobody on the NFS server. This is called root_squashmode. This means that a client machine logged in as user root doesn’t get rootprivileges on the NFS server machine. You can, however, disable this defaultbehavior, and give the root account on an NFS client root privileges on theserver as well:

/nfs-share 192.168.1.2(rw,no_ root_ squash)

As we’ve mentioned above, user nobody and group nobody isused by default. You can specify another user ID and group ID by using anonuidand anongid respectively:

/usr/local/nfs *.pcqlabs(rw,anonuid=200,anongid=200,noaccess)

Here, /usr/local/nfs can be accessed by all the machines inthe domain pcqlabs. The client privileges are mapped to userid 200 in group 200,and clients can read as well as write into this directory. However, because we’vespecified noac cess, clients can’t access subdirectories below/usr/local/nfs.

Advertisment