Configuring NFS (Network File System)

Purpose:

To set up a shared network file system. NFS is a protocol that allows a server to host files that can be seen on client machines -- whereever the client machine exists.

Procedure:

1. Installing packages

You need two machines for today's lab -- one "client" machine and one "server" machine, both booted into our Xubuntu OS from the flash drives.

2. Create a directory to share

On the server machine, you must create a directory that you want to share to other machines:

Create a directory under /tmp. Call it what you want. You need to do this "under" sudo.

Q1. What is the name of the directory you are sharing from the server machine?


Create a file in this new directory, and put a few lines in the file. Doesn't matter what is in it. (Use can use mousepad to create/edit the file.)

3. Edit /etc/exports

Still on the server machine, edit the /etc/exports file, adding this line to the end:

 /tmp/<yourdir> 192.168.33.0/24(rw,no_root_squash,async,no_subtree_check,fsid=0) 

4. Restart nfs (network file service)

Restart the nfs file server and export this new file "system". Use

service --status-all

to see all the services that are known. Find the NFS service.

Q2. What is the service called?

Now, restart it using the service command.

5. Mount the shared file system on the client machine:

On your client machine, run these commands, under sudo:

sudo mkdir /home/<somedirthatyouchoose>
sudo mount <serverip>:/tmp/<yourdir> /home/<somedirthatyouchoose> 


6. Test

Now, as mradmin (not under sudo), 

cd /home/<somedirthatyouchoose>
cat <thefileyoucreatedinstep2> 

(Note: cat just prints out the contents of a file.)

Q3. Did it work?

Now, try to update that file on the client: start mousepad and change the contents of the file.

Q4. Did it work? If not, why not?

Q5. What are the permissions and ownership of the file? You may have to do some googling to figure out how to find this out. (Do NOT, at this point, change the owner or permissions of the file.


7. Monitor what is happening

On either your server or your client machine, run wireshark (under sudo). Set wireshark to show only nfs packets (just put nfs in the Filter field). While wireshark is running, do these steps on the client:

(NOTE: for the following questions, I expect you to do some digging -- you will be graded based on how much relevant info you can give me. E.g., you might want to indicate (at least in Q6, what layer 4 protocol is being used, what ports are being used, what format of layer 5 data is being used, what type of NFS message is sent, and what interesting flags are set in that NFS message.)

7.a. cd /home/<somedirthatyouchoose>

Q6. For all NFS packets: What layer 4 protocol is used? What ports are used? What format of layer 5 data is used?

Q7.a. What are the NFS packets sent? What's in them that seems important and interesting?

7.b. ls -Fla

Q7.b. What are the NFS packets sent? What's in them that seems important and interesting?

7.c. touch <somenewfile> (this tries to create a new file with 0 bytes in it)

Q7.c. What are the NFS packets sent? What's in them that seems important and interesting?

7.d. rm <somenewfile>

Q7.d. What are the NFS packets sent? What's in them that seems important and interesting?

7.e. touch <thefileyoucreatedinstep2>

Q7.e. What are the NFS packets sent? What's in them that seems important and interesting?

7.f. mkdir <somedir>

Q7.f. What are the NFS packets sent? What's in them that seems important and interesting?

8. Change the permissions on the shared dir:

On the server machine, cd /tmp.

Then, look at the permissions for the directory you are sharing. Do this by running ls -Fla .

Q8. What is the output? What do the permission flags mean?

Now, change the permissions for <yoursharedir> to 777 this way:

chmod 777 <yoursharedir>

Now, get wireshark visible again, so you can see what NFS packets go flying by again.

On the client machine, (not as sudo), go to the mounted directory, and create a file there. It should succeed this time.

Q9. What are the NFS packets sent? What's in them that seems important and interesting?

Now, create a directory in the mounted directory. See 7.f. above for how to do that.

Q10. What are the NFS packets sent? What's in them that seems important and interesting?

Q11. On the server machine, report the permissions and ownership of the new file and new directory you created on the client machine.

9. Cleanup

On the client machine use umount to unmount the directory. (You may not be in the directory you are trying to unmount, btw.)

On the client machine, remove the new directory you created in /home.

On the server machine use service to stop the NFS server.

On the server machine, remove the entry you put in the /etc/exports file.

On the server machine, remove the new folder you created and shared in /tmp.

Plug your machines back into the orange network and make sure they come up on the 153.106 network.