Recent Changes - Search:

Network Programming

This website demonstrates using wikis as teaching and learning tool.

The course instructor is happy to share the teaching materials here with those who find it readable.

Network Filesystems

A Network Programming Lecture by Steven Choy

Overview: Introduction to NFS (Network File System) - NFS Architecture - NFS Protocol - NFS Implementation - Starting up NFS - Exporting File System - NFS Transport protocol - Introduction to SMB/CIFS - What is Samba? - SMB Protocol - What is the difference between NFS and CIFS?


Introduction to NFS (Network File System)

"The Network File System (NFS) software allows one computer (an NFS client) attached to a network to access the filesystems present on the hard disk of another computer (an NFS server) on the network. An NFS client can mount the whole or part of a remote filesystem. It can then access the files in this filesystem almost as if they were present on a local hard disk."
"The Network File System (NFS) was developed to allow machines to mount a disk partition on a remote machine as if it were a local disk. It allows for fast, seamless sharing of files across a network."
  • A typical client/server application
  • Client side import file system from remote machine
  • Server side export file system to remote machine
  • Each machine can be either client or server, or can be both client and server
  • Based on RPC (remote procedure call)
  • NFS can be used over any kind of datagram (UDP) or stream protocols (TCP)

NFS Architecture

NFS Protocol

  • NFS protocol designed without states (Stateless protocol)
  • No need for server to hold information about which client is working with which file.
  • To get their work done, server need only information from RPC requests.
  • NFS designed to support UNIX file system semantic, but protocol design can be adopted to support any file system semantic
  • Security and access check mechanisms based on Unix UID (user ID) and GID (group ID) mechanism.
  • NFS protocol design doesn’t depend on transport protocols. It’s used with UDP by default, but still can be used with TCP protocol.
  • NFS Commands: Some Examples

NFS Implementation

  • Each file on the server are identified by the file handler for clients to access
  • File handle is used to uniquely distinguish file.
  • NFS VFS (Virtual File System)
  • VFS added to UNIX kernel
    • Access-transparent file access
    • Distinguishes between local and remote access
    (Access Transparency: Client should be unaware of the distribution of files. Access transparency enables local and remote resources to be accessed using identical operations. That means it doesn’t matter whether the resources are from local or remote machines — the way to access them should be identical.)
  • At client Side:
    • Processes file system calls to determine whether access is local (passes it to UNIX FS) or remote (passes it to NFS client).
  • At server side:
    • NFS server receives request and passes it to local FS through VFS.
  • If local, translates file handle to internal file id’s (in UNIX i-nodes).
  • If file local, reference to file’s i-node.
  • If file remote, reference to file handle.

Starting up NFS

  • There are three key things you need to start on Linux to make NFS work.
      /usr/sbin/rpc.portmap
      /usr/sbin/rpc.mountd
      /usr/sbin/rpc.nfsd
  • Check if they are there
      rpcinfo -p localhost
         program vers proto   port
          100000    2   tcp    111  portmapper
          100000    2   udp    111  portmapper
          100005    1   udp    679  mountd
          100005    1   tcp    681  mountd
          100003    2   udp   2049  nfs
          100003    2   tcp   2049  nfs

Exporting File System

  • To make parts of your file system accessible over the network to other systems, the /etc/exports file must be set up to define which of the local directories will be available to remote users and how each is used.
  • A sample of /etc/exports file
	/home/yourname 192.168.12.1(rw)
	/master(rw) trusty(rw,no_root_squash) 
	/projects proj*.local.domain(rw) 
	/usr *.local.domain(ro) @trusted(rw) 
	/home/joe pc001(rw,all_squash,anonuid=150,anongid=100) 
	/pub (ro,insecure,all_squash) 
	/pub/private (noaccess)
  • To stop and restart the server
	# etc/rc.d/init.d/nfs stop
	# etc/rc.s/init.d/nfs start
  • Local and remote file systems accessible on an NFS client
	mount –t nfs Server1:/export/people /usr/students
	mount –t nfs Server2:/nfs/users /usr/staff

NFS Transport protocol

  • Originally used UDP.
    • Better performance in LANs.
    • NFS and RPC do their own reliability checks.
  • Most current implementations support both UDP and TCP.
    • WANs: congestion control.
  • TCP officially integrated in NFS v.3.

Demonstration

NFS Server

  • Install NFS Server
    apt-get install nfs-kernel-server nfs-common
    rpcinfo -p
  • Edit /etc/exports and add the share
    /root/shared 202.40.219.247(rw,sync,no_subtree_check)

    /tmp         192.168.1.0/24(ro)   localhost(rw)   *.ev.ncku.edu.tw(ro,sync)
    # [分享目錄] [第一部主機(權限)]   [可用主機名]    [可用萬用字元]
  • Export the share
    exportfs -ra
  • Restart services
    /etc/init.d/portmap restart
    /etc/init.d/nfs-kernel-server restart

NFS Client

  • Install
    apt-get install portmap nfs-common
  • Mounts
    mount 202.40.219.240:/root/shared /root/import

Introduction to SMB/CIFS

  • SMB (Server Message Block) is Microsoft’s protocol to share files and printers
  • Also renamed CIFS (Common Internet File System)
"The Server Message Block (SMB) Protocol is a network file sharing protocol, and as implemented in Microsoft Windows is known as Microsoft SMB Protocol. The set of message packets that defines a particular version of the protocol is called a dialect. The Common Internet File System (CIFS) Protocol is a dialect of SMB. Both SMB and CIFS are also available on VMS, several versions of Unix, and other operating systems." (Source)
  • Client/Server model, developed for LAN use
  • SMB usually runs on NetBIOS (naming + sessions + datagram)
NetBIOS (Network Basic Input/Output System): The NetBIOS API allows applications on separate computers to communicate over a local area network. In modern networks, it normally runs over TCP/IP, giving each computer in the network both a NetBIOS name and an IP address corresponding to a host name. (Source)
NBTSTAT - MS-DOS utility that displays protocol statistics and current TCP/IP connections using NBT (NetBIOS over TCP/IP)
      nbtstat -a 

      Lists the remote machine's name table given its name

      nbtstat -A IP

      Lists the remote machine's name table given its IP address

      nbtstat -n

      Lists local NetBIOS names
Windows Internet Name Service (WINS) is Microsoft's implementation of NetBIOS Name Server (NBNS) on Windows, a name server and service for NetBIOS computer names. Effectively, WINS is to NetBIOS names, what DNS is to domain names - a central mapping of host names to network addresses. (Source)
How to find WINS Server IP Address if your PC have one?

What is Samba?

  • SMB/CIFS File Server
  • Authentication Server
  • Bridge between UNIX and Windows Networks
  • Runs under UNIX, VMS, Linux, FreeBSD, and more!

SMB Protocol

  • Request/response.
  • Runs atop TCP/IP.
  • E.g., file and print operations.
    • Open close, read, write, delete, etc.
    • Queuing/dequeing files in printer spool.

Samba: How does it work?

  • Set of UNIX applications running the Server Message Block (SMB) protocol.
    • SMB is the protocol MS Windows use for client-server interactions over a network.
    • By running SMB, Unix systems appear as another MS Windows system.

SMB Message

  • Header + command/response.
  • Header: protocol id, command code, etc.
  • Command: command parameters.

Establishing a SMB Connection

  • Establish TCP connection.
  • Negotiate protocol variant.
    • Client sends SMBnegprot.
    • Client sends lists of variants it can speak.
    • Server responds with index into client’s list.
  • Set session and login parameters.
    • Account name, passwd, workgroup name, etc.

A brief on setting up SAMBA

  • 1. Have samba installed.
      sudo aptitude install samba
  • 2. Configure samba
      sudo /etc/init.d/samba stop
      sudo gedit /etc/samba/smb.conf

          [global]

          workgroup = YOUR_WORKGROUP

          [MyFiles]

          path = /media/samba/
          browseable = yes
          read only = no
          guest ok = no
          create mask = 0644
          directory mask = 0755
          force user = YOUR_USERNAME
          force group = YOUR_USERGROUP
  • 3. Start samba and sett up user accounts
      sudo /etc/init.d/samba start
      sudo smbpasswd -L -a root
      sudo smbpasswd -L -e root
  • 4. Change network settings in Windows
    01 - Click "START"
    02 - Click "Control Panel"
    03 - Click "Network Connections"
    04 - Find your "LAN Connection"
    05 - Right-click the icon and select "Properties"
    06 - Select the "TCP/IP" Protocol and click the "Properties" button
    07 - Click "Advanced"
    08 - Select the third Tab entitled "WINS"
    09 - Click "Add"
    10 - Type in the ip-address of your Linux box
    11 - Click "Add"
    12 - Select "Use NetBIOS over TCP/IP"
    13 - Click "OK"
    14 - Click "OK"
    15 - Click "OK"
    16 - Reboot Windows

What is the difference between NFS and CIFS?

"NFS is the "Network File System" for Unix and Linux operating systems. It allows files to be shared transparently between servers desktops laptops etc. It is a client/server application that allows a user to view store and update files on a remote computer as though they were on their own computer. Using NFS the user or a system administrator can mount all or a portion of a file system."
"CIFS is the "Common Internet File System" used by Windows operating systems for file sharing. CIFS uses the client/server programming model. A client program makes a request of a server program (usually in another computer) for access to a file or to pass a message to a program that runs in the server computer. The server takes the requested action and returns a response. CIFS is a public or open variation of the Server Message Block Protocol (SMB) developed and used by Microsoft and it uses the TCP/IP protocol."
"NFS and CIFS are the primary file systems used in NAS. CIFS tends to be a bit more "chatty" in its communications."

Class Discussion

  • Discuss how to enable file sharing among the machines in the following SOHO network

References and Resources

Network File System (NFS) is a network file system protocol originally jointly developed by Sun Microsystems and IBM in 1984, allowing a user on a client computer to access files over a network as easily as if the network devices were attached to its local disks. NFS, like many other protocols, builds on the Open Network Computing Remote Procedure Call (ONC RPC) system. The Network File System protocol is specified in RFC 1094, RFC 1813, and RFC 3530.
NFS為 Network FileSystem 的簡稱,最早之前是由 Sun 這家公司所發展出來的,他的目的就是想讓不同的機器、 不同的作業系統可以彼此分享個別的檔案啦!目前在 Unix Like 當中用來做為 file server 是相當不錯的一個方案喔!基本上, Unix Like 主機連接到另一部 Unix Like 主機來分享彼此的檔案時,使用 NFS 要比 SAMBA 這個伺服器快速且方便的多了!此外, NFS 的設定真的很簡單,幾乎只要記得啟動 Remote Procedure Call 這個咚咚 (RPC, 就是 portmap 這個套件啦!) 就一定可以架設的起來!真是不錯啊!不過,如果要達成 Windows 與 Linux 之間的溝通,那麼還是以 SAMBA 比較容易啊!無論如何, NFS 還是可以做為小公司或學校單位內部 Unix Like 機器共享 file 的一個 Server 喔!
在一般的區域網路中 (LAN) 如果都是 Windows 電腦,那麼使用『網路上的芳鄰』這個功能,就可以讓不同的 Windows 電腦分享彼此的檔案囉!但萬一這個 LAN 裡面有個 Linux 主機時,我怎麼讓 Linux 也加入這個 Windows 電腦當中的『網路上的芳鄰』呢?也就是說,讓 Windows 電腦可以透過『網路上的芳鄰』來存取 Linux 主機上面的檔案!呵呵!那就是 SAMBA 這個伺服器的主要目的了!
As many fellow Ubuntu users seem to have trouble setting up samba peer-to-peer with Windows I decided to write a small howto on this matter. NOTE: I am aware that there's a wiki-page as well as several other howto's around - but by looking at the constant "how do I setup samba" posts that are floating around in the forum I simply see the need for a more thourough guide on this matter.
Samba is a set of tools to share files and printers with computers running Windows. It implements the SMB network protocol, which is the heart of Windows networking.
Samba is an Open Source/Free Software suite that has provided file and print services to all manner of SMB/CIFS clients, including the numerous versions of Microsoft Windows operating systems. Samba is freely available under the GNU General Public License.
在 Windows 環境中,我們通常透過網路芳鄰來達成彼此機器間的資源分享工作,但是若想要與 Unix-Based 作業系統間做到資源分享,就會比較困難。一般在 Windows 與 Unix-Based 作業系統間,我們都會利用 FTP 或 NFS 來做檔案交換的工作,但這只能做到單方面資源的要求,而無法達到雙向互通。幸好 Samba Server 的出現可以解決這個難題。
This tutorial explains how to turn an old PC with additional hard disks into a simple home file server. The file server is intended for home use. The home file server is accessible by Windows and Linux computers in the home network.

Thanks for Reading

If you would rather like to have this lecture note in printed format, please click the print action link in the top right corner.

If you find any problem in this lecture note, please feel free to tell Steven via steven@findaway.hk.

Edit - History - Print - Recent Changes - Search
Page last modified on February 25, 2010, at 10:55 PM