Linux NFS Crash Course

by Marion Bates <mbates at whoopis.com>

Last modified: December 31 1969 16:00:00

  1. Connections and definitions. goober is 192.168.1.2 and spleen is 192.168.1.3. spleen is the server and goober is the client. Both use a built-in 10/100 interface (eth0) for regular communication with the rest of the network. Each has an additional, gigabit NIC (eth1). A crossover cable is installed between the two secondary interfaces.

  2. Network interfaces. On spleen:
    ifconfig eth1 192.168.1.3 netmask 255.255.255.0 up
    

    On goober:

    ifconfig eth1 192.168.1.2 netmask 255.255.255.0 up
    

    And added requisite changes in /etc/sysconfig/network-scripts/ifcfg-eth1 on both so they come up on reboot.

    [root@spleen ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.1.3
    NETMASK=255.255.255.0
    TYPE=Ethernet
    
    [root@goober ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
    DEVICE=eth1
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.1.2
    NETMASK=255.255.255.0
    TYPE=Ethernet
    

  3. NFS server setup. On spleen (server), make a dir to share:
    [root@spleen ~]# mkdir /export
    

    Edit /etc/exports:

    # only goober, 192.168.1.2, can diddle with the /export dir read-write.
    # also, root is root on both systems.
    /export 192.168.1.2(rw,sync,no_root_squash)
    

    (Re)start services nfs and portmap for any changes to /etc/export. Run chkconfig and make sure nfs and portmap and rpc services are set to start in runlevel 3 (or 5, whatever the "runlevel" command reports under normal circumstances).

  4. Access control via TCPWrappers. On spleen, edit /etc/hosts.allow:
    portmap:192.168.1.2
    lockd:192.168.1.2
    rquotad:192.168.1.2
    mountd:192.168.1.2
    statd:192.168.1.2
    

  5. Mounting the NFS shares at boot. On goober, make a mountpoint:
    [root@goober ~]# mkdir /export
    

    Edit /etc/fstab:

    192.168.1.3:/export  /export   nfs   rw    0 0
    

  6. Mounting the share at the command line (should only need to do this once, from then on, the line in fstab should mount it at boot time). On goober, type:
    [root@goober ~]# mount 192.168.1.3:/export /export
    

  • Enjoy...