home *** CD-ROM | disk | FTP | other *** search
/ Hackers Toolkit v2.0 / Hackers_Toolkit_v2.0.iso / HTML / archive / Unix / HOWTOs / NFS-HOWT < prev    next >
Text File  |  1999-11-04  |  39KB  |  842 lines

  1.   NFS HOWTO
  2.   Nicolai Langfeldt janl@math.uio.no
  3.   v0.7, 3 November 1997
  4.  
  5.   HOWTO set up NFS clients and servers.
  6.  
  7.   1.  Preamble
  8.  
  9.   1.1.  Legal stuff
  10.  
  11.   (C)opyright 1997 Nicolai Langfeldt.  Do not modify without amending
  12.   copyright, distribute freely but retain this paragraph.  The FAQ
  13.   section is based on a NFS FAQ compiled by Alan Cox.  The Checklist
  14.   section is based on a mount problem checklist compiled by the IBM
  15.   Corporation.
  16.  
  17.   1.2.  Other stuff
  18.  
  19.   This will never be a finished document, please send me mail about your
  20.   problems and successes, it can make this a better HOWTO.  Please send
  21.   money, comments and/or questions to janl@math.uio.no.  If you send E-
  22.   mail please make sure that the return address is correct and working,
  23.   I get a lot of E-mail and figuring out your e-mail address can be a
  24.   lot of work.  Please.
  25.  
  26.   If you want to translate this HOWTO please notify me so I can keep
  27.   track of what languages I have been published in :-).
  28.  
  29.   Curses and Thanks to Olaf Kirch who got me to write this and then gave
  30.   good suggestions for it :-)
  31.  
  32.   This HOWTO covers NFS in the 2.0 versions of the kernel.  There are
  33.   significant enhancements, and changes, of NFS in the 2.1 versions of
  34.   the kernel.
  35.  
  36.   1.3.  Dedication
  37.  
  38.   This HOWTO is dedicated to Anne Line Norheim Langfeldt.  Though she
  39.   will probably never read it since she's not that kind of girl.
  40.  
  41.   2.  README.first
  42.  
  43.   NFS, the Network File System has three important characteristics:
  44.  
  45.   ╖  It makes sharing of files over a network possible.
  46.  
  47.   ╖  It mostly works well enough.
  48.  
  49.   ╖  It opens a can of security risks that are well understood by
  50.      crackers, and easily exploited to get access (read, write and
  51.      delete) to all your files.
  52.  
  53.   I'll say something on both issues in this HOWTO.  Please make sure you
  54.   read the security section of this HOWTO, and you will be vulnerable to
  55.   fewer silly security risks.  The passages about security will at times
  56.   be pretty technical and require some knowledge about IP networking and
  57.   the terms used.  If you don't recognize the terms you can either go
  58.   back and check the networking HOWTO, wing it, or get a book about
  59.   TCP/IP network administration to familiarize yourself with TCP/IP.
  60.   That's a good idea anyway if you're administrating UNIX/Linux
  61.   machines.  A very good book on the subject is TCP/IP Network
  62.   Administration by Craig Hunt, published by O'Reilly & Associates, Inc.
  63.   And after you've read it and understood it you'll have higher value on
  64.   the job market, you can't loose ;-)
  65.  
  66.   There are two sections to help you troubleshoot NFS, called Mount
  67.   Checklist and FAQs.  Please refer to them if something dosn't work as
  68.   advertized.
  69.  
  70.   3.  Setting up a NFS server
  71.  
  72.   3.1.  Prerequisites
  73.  
  74.   Before you continue reading this HOWTO you will need to be able to
  75.   telnet back and forth between the machine you're using as server and
  76.   the client.  If that does not work you need to check the
  77.   networking/NET-2 HOWTO and set up networking properly.
  78.  
  79.   3.2.  First step
  80.  
  81.   Before we can do anything else we need a NFS server set up.  If you're
  82.   part of a department or university network there are likely numerous
  83.   NFS servers already set up.  If they will let you get access to them,
  84.   or indeed, if you're reading this HOWTO to get access to one of them
  85.   you obviously don't need to read this section and can just skip ahead
  86.   to the section on ``setting up a NFS client''
  87.  
  88.   If you need to set up a non-Linux box as server you will have to read
  89.   the system manual(s) to discover how to enable NFS serving and export
  90.   of file systems through NFS.  There is a separate section in this
  91.   HOWTO on how to do it on many different systems.  After you have
  92.   figured all that out you can continue reading the next section of this
  93.   HOWTO.  Or read more of this section since some of the things I will
  94.   say are relevant no matter what kind of machine you use as server.
  95.  
  96.   Those of you still reading will need to set up a number of programs.
  97.  
  98.   3.3.  The portmapper
  99.  
  100.   The portmapper on Linux is called either portmap or rpc.portmap.  The
  101.   man page on my system says it is a "DARPA port to RPC program number
  102.   mapper".  It is the first security holes you'll open reading this
  103.   HOWTO.  Description of how to close one of the holes is in the
  104.   ``security section''.  Which I, again, urge you to read.
  105.  
  106.   Start the portmapper.  It's either called portmap or rpc.portmap and
  107.   it should live in the /usr/sbin directory (on some machines it's
  108.   called rpcbind).  You can start it by hand now, but it will need to be
  109.   started every time you boot your machine so you need to make/edit the
  110.   rc scripts.  Your rc scripts are explained more closely in the init
  111.   man page, they usually reside in /etc/rc.d, /etc/init.d or
  112.   /etc/rc.d/init.d.  If there is a script called something like inet
  113.   it's probably the right script to edit.  But, what to write or do is
  114.   outside the scope of this HOWTO.  Start portmap, and check that it
  115.   lives by running ps aux.  It does?  Good.
  116.  
  117.   3.4.  Mountd and nfsd
  118.  
  119.   The next programs we need running are mountd and nfsd.  But first
  120.   we'll edit another file.  /etc/exports this time.  Say I want the file
  121.   system /mn/eris/local which lives on the machine eris to be available
  122.   to the machine called apollon.  Then I'd put this in /etc/exports on
  123.   eris:
  124.  
  125.   ______________________________________________________________________
  126.   /mn/eris/local  apollon(rw)
  127.   ______________________________________________________________________
  128.  
  129.   The above line gives apollon read/write access to /mn/eris/local.
  130.   Instead of rw it could say ro which means read only (if you put
  131.   nothing it defaults to read only).  There are other options you can
  132.   give it, and I will discuss some security related ones later.  They
  133.   are all enumerated in the exports man page which you should have read
  134.   at least once in your life.  There are also better ways than listing
  135.   all the hosts in the exports file.  You can for example use net groups
  136.   if you are running NIS (or NYS) (NIS was known as YP), and always
  137.   specify domain wild cards and IP-subnets as hosts that are allowed to
  138.   mount something.  But you should consider who can get access to the
  139.   server in unauthorized ways if you use such blanket authorizations.
  140.  
  141.   Note: This exports file is not the same syntax that other Unixes use.
  142.   There is a separate section in this HOWTO about other Unixes exports
  143.   files.
  144.  
  145.   Now we're set to start mountd (or maybe it's called rpc.mountd and
  146.   then nfsd (which could be called rpc.nfsd).  They will both read the
  147.   exports file.
  148.  
  149.   If you edit /etc/exports you will have to make sure nfsd and mountd
  150.   knows that the files have changed.  The traditonal way is to run
  151.   exportfs.  Many Linux distributions lack a exportfs program.  If
  152.   you're exportfs-less you can install this script on your machine:
  153.  
  154.   ______________________________________________________________________
  155.   #!/bin/sh
  156.   killall -HUP /usr/sbin/rpc.mountd
  157.   killall -HUP /usr/sbin/rpc.nfsd
  158.   echo re-exported file systems
  159.   ______________________________________________________________________
  160.  
  161.   Save it in, say, /usr/sbin/exportfs, and don't forget to chmod a+rx
  162.   it.  Now, whenever you change your exports file, you run exportfs
  163.   after, as root.
  164.  
  165.   Now you should check that mountd and nfsd are running properly.  First
  166.   with rpcinfo -p.  It should show something like this:
  167.  
  168.   ______________________________________________________________________
  169.      program vers proto   port
  170.       100000    2   tcp    111  portmapper
  171.       100000    2   udp    111  portmapper
  172.       100005    1   udp    745  mountd
  173.       100005    1   tcp    747  mountd
  174.       100003    2   udp   2049  nfs
  175.       100003    2   tcp   2049  nfs
  176.   ______________________________________________________________________
  177.  
  178.   As you see the portmapper has announced it's services, and so has
  179.   mountd and nfsd.
  180.  
  181.   If you get rpcinfo: can't contact portmapper: RPC: Remote system error
  182.   - Connection refused or something similar instead then the portmapper
  183.   isn't running.  Fix it.  If you get No remote programs registered.
  184.   then either the portmapper doesn't want to talk to you, or something
  185.   is broken.  Kill nfsd, mountd, and the portmapper and try the ignition
  186.   sequence again.
  187.  
  188.   After checking that the portmapper reports the services you can check
  189.   with ps too.  The portmapper will continue to report the services even
  190.   after the programs that extend them have crashed.  So a ps check can
  191.   be smart if something seems broken.
  192.  
  193.   Of course, you will need to modify your system rc files to start
  194.   mountd and nfsd as well as the portmapper when you boot.  It is very
  195.   likely that the scripts already exist on your machine, you just have
  196.   to uncomment the critical section or activate it for the correct init
  197.   run levels.
  198.  
  199.   Man pages you should be familiar with now: portmap, mountd, nfsd, and
  200.   exports.
  201.  
  202.   Well, if you did everything exactly like I said you should you're all
  203.   set to start on the NFS client.
  204.  
  205.   4.  Setting up a NFS client
  206.  
  207.   First you will need a kernel with the NFS file system either compiled
  208.   in or available as a module.  This is configured before you compile
  209.   the kernel.  If you have never compiled a kernel before you might need
  210.   to check the kernel HOWTO and figure it out.  If you're using a very
  211.   cool distribution (like Red Hat) and you've never fiddled with the
  212.   kernel or modules on it (and thus ruined it ;-), nfs is likely
  213.   automagicaly available to you.
  214.  
  215.   You can now, at a root prompt, enter a appropriate mount command and
  216.   the file system will appear.  Continuing the example in the previous
  217.   section we want to mount /mn/eris/local from eris.  This is done with
  218.   this command:
  219.  
  220.   ______________________________________________________________________
  221.   mount -o rsize=1024,wsize=1024 eris:/mn/eris/local /mnt
  222.   ______________________________________________________________________
  223.  
  224.   (We'll get back to the rsize and wsize options.)  The file system is
  225.   now available under /mnt and you can cd there, and ls in it, and look
  226.   at the individual files.  You will notice that it's not as fast as a
  227.   local file system, but a lot more convenient than ftp.  If, instead of
  228.   mounting the file system, mount produces a error message like mount:
  229.   eris:/mn/eris/local failed, reason given by server: Permission denied
  230.   then the exports file is wrong, or you forgot to run exportfs after
  231.   editing the exports file.  If it says mount clntudp_create: RPC:
  232.   Program not registered it means that nfsd or mountd is not running on
  233.   the server.
  234.  
  235.   To get rid of the file system you can say
  236.  
  237.   ______________________________________________________________________
  238.   umount /mnt
  239.   ______________________________________________________________________
  240.  
  241.   To make the system mount a nfs file system upon boot you edit
  242.   /etc/fstab in the normal manner.  For our example a line such as this
  243.   is required:
  244.  
  245.   ______________________________________________________________________
  246.   # device      mountpoint     fs-type     options              dump fsckorder
  247.   eris:/mn/eris/local  /mnt    nfs        rsize=1024,wsize=1024 0    0
  248.   ______________________________________________________________________
  249.  
  250.   That's all there is too it, almost.  Read on please.
  251.  
  252.   4.1.  Mount options
  253.  
  254.   There are some options you should consider adding at once.  They
  255.   govern the way the NFS client handles a server crash or network
  256.   outage.  One of the cool things about NFS is that it can handle this
  257.   gracefully.  If you set up the clients right.  There are two distinct
  258.   failure modes:
  259.  
  260.      soft
  261.         The NFS client will report and error to the process accessing a
  262.         file on a NFS mounted file system.  Some programs can handle
  263.         this with composure, most won't.  I cannot recommend using this
  264.         setting.
  265.  
  266.      hard
  267.         The program accessing a file on a NFS mounted file system will
  268.         hang when the server crashes.  The process cannot be interrupted
  269.         or killed unless you also specify intr.  When the NFS server is
  270.         back online the program will continue undisturbed from where it
  271.         were.  This is probably what you want.  I recommend using
  272.         hard,intr on all NFS mounted file systems.
  273.  
  274.   Picking up the previous example, this is now your fstab entry:
  275.  
  276.   ______________________________________________________________________
  277.   # device      mountpoint     fs-type    options                  dump fsckorder
  278.   eris:/mn/eris/local  /mnt    nfs        rsize=1024,wsize=1024,hard,intr 0 0
  279.   ______________________________________________________________________
  280.  
  281.   4.2.  Optimizing NFS
  282.  
  283.   Normally, if no rsize and wsize options are specified NFS will read
  284.   and write in chunks of 4096 or 8192 bytes.  Some combinations of Linux
  285.   kernels and network cards cannot handle that large blocks, and it
  286.   might not be optimal, anyway.  So we'll want to experiment and find a
  287.   rsize and wsize that works and is as fast as possible.  You can test
  288.   the speed of your options with some simple commands.  Given the mount
  289.   command above and that you have write access to the disk you can do
  290.   this to test the sequential write performance:
  291.  
  292.   ______________________________________________________________________
  293.   time dd if=/dev/zero of=/mnt/testfile bs=16k count=4096
  294.   ______________________________________________________________________
  295.  
  296.   This creates a 64Mb file of zeroed bytes (which should be large enough
  297.   that caching is no significant part of any performance perceived, use
  298.   a larger file if you have a lot of memory).  Do it a couple (5-10?)
  299.   of times and average the times.  It is the `elapsed' or `wall clock'
  300.   time that's most interesting in this connection.  Then you can test
  301.   the read performance by reading back the file:
  302.  
  303.   ______________________________________________________________________
  304.   time dd if=/mnt/testfile of=/dev/null bs=16k
  305.   ______________________________________________________________________
  306.  
  307.   do that a couple of times and average.  Then umount, and mount again
  308.   with a larger rsize and wsize.  They should probably be multiples of
  309.   1024, and not larger than 16384 bytes since that's the maximum size in
  310.   NFS version 2.  Directly after mounting with a larger size cd into the
  311.   mounted file system and do things like ls, explore the fs a bit to
  312.   make sure everything is as it should.  If the rsize/wsize is too large
  313.   the symptoms are very odd and not 100% obvious.  A typical symptom is
  314.   incomplete file lists when doing 'ls', and no error messages.  Or
  315.   reading files failing mysteriously with no error messages.  After
  316.   establishing that the given rsize/wsize works you can do the speed
  317.   tests again.  Different server platforms are likely to have different
  318.   optimal sizes.  SunOS and Solaris is reputedly a lot faster with 4096
  319.   byte blocks than with anything else.
  320.  
  321.   Newer Linux kernels (since 1.3 sometime) perform read-ahead for rsizes
  322.   larger or equal to the machine page size.  On Intel CPUs the page size
  323.   is 4096 bytes.  Read ahead will significantly increase the NFS read
  324.   performance.  So on a Intel machine you will want 4096 byte rsize if
  325.   at all possible.
  326.  
  327.   Remember to edit /etc/fstab to reflect the rsize/wsize you found.
  328.  
  329.   A trick to increase NFS write performance is to disable synchronous
  330.   writes on the server.  The NFS specification states that NFS write
  331.   requests shall not be considered finished before the data written is
  332.   on a non-volatile medium (normally the disk).  This restricts the
  333.   write performance somewhat, asynchronous writes will speed NFS writes
  334.   up.  The Linux nfsd has never done synchronous writes since the Linux
  335.   file system implementation does not lend itself to this, but on non-
  336.   Linux servers you can increase the performance this way with this in
  337.   your exports file:
  338.  
  339.   ______________________________________________________________________
  340.   /dir    -async,access=linuxbox
  341.   ______________________________________________________________________
  342.  
  343.   or something similar.  Please refer to the exports man page on the
  344.   machine in question.  Please note that this increases the risk of data
  345.   loss.
  346.  
  347.   5.  NFS over slow lines
  348.  
  349.   Slow lines include Modems, ISDN and quite possibly other long distance
  350.   connections.
  351.  
  352.   This section is based on knowledge about the used protocols but no
  353.   actual experiments.  My home computer has been down for 6 months (bad
  354.   HD, low on cash) and so I have had no modem connection to test this
  355.   with.  Please let me hear from you if try this :-)
  356.  
  357.   The first thing to remember is that NFS is a slow protocol.  It has
  358.   high overhead.  Using NFS is almost like using kermit to transfer
  359.   files.  It's slow.  Almost anything is faster than NFS.  FTP is
  360.   faster. HTTP is faster.  rcp is faster.  ssh is faster.
  361.  
  362.   Still determined to try it out?  Ok.
  363.  
  364.   NFS' default parameters are for quite fast, low latency, lines.  If
  365.   you use these default parameters over high latency lines it can cause
  366.   NFS to report errors, abort operations, pretend that files are shorter
  367.   than they really are, and act mysteriously in other ways.
  368.  
  369.   The first thing to do is not to use the soft mount option.  This will
  370.   cause timeouts to return errors to the software, which will, most
  371.   likely not handle the situation at all well.  This is a good way to
  372.   get for mysterious failures.  Instead use the hard mount option.  When
  373.   hard is active timeouts causes infinite retries instead of aborting
  374.   whatever it was the software wanted to do.  This is what you want.
  375.   Really.
  376.  
  377.   The next thing to do is to tweak the timeo and retrans mount options.
  378.   They are described in the nfs(5) man page, but here is a copy:
  379.  
  380.   ______________________________________________________________________
  381.          timeo=n        The  value  in  tenths  of  a second before
  382.                         sending the first retransmission  after  an
  383.                         RPC timeout.  The default value is 7 tenths
  384.                         of a second.  After the first timeout,  the
  385.                         timeout  is  doubled  after each successive
  386.                         timeout until a maximum timeout of 60  sec-
  387.                         onds  is  reached or the enough retransmis-
  388.                         sions have occured to cause a  major  time-
  389.                         out.   Then,  if  the  filesystem  is  hard
  390.                         mounted, each new timeout cascade  restarts
  391.                         at  twice the initial value of the previous
  392.                         cascade, again doubling at each retransmis-
  393.                         sion.   The  maximum  timeout  is always 60
  394.                         seconds.  Better overall performance may be
  395.                         achieved  by  increasing  the  timeout when
  396.                         mounting on  a  busy  network,  to  a  slow
  397.                         server, or through several routers or gate-
  398.                         ways.
  399.  
  400.          retrans=n      The number of minor timeouts  and  retrans-
  401.                         missions  that  must  occur  before a major
  402.                         timeout occurs.  The default is 3 timeouts.
  403.                         When a major timeout occurs, the file oper-
  404.                         ation is either aborted or  a  "server  not
  405.                         responding"  message is printed on the con-
  406.                         sole.
  407.   ______________________________________________________________________
  408.  
  409.   In other words: If a reply is not received within the 0.7 second
  410.   (700ms) timeout the NFS client will repeat the request and double the
  411.   timeout to 1.4 seconds.  If the reply does not appear within the 1.4
  412.   seconds the request is repeated again and the timeout doubled again,
  413.   to 2.8 seconds.
  414.  
  415.   A lines speed can be measured with ping with the same packet size as
  416.   your rsize/wsize options.
  417.  
  418.   ______________________________________________________________________
  419.   $ ping -s 8192 lugulbanda
  420.   PING lugulbanda.uio.no (129.240.222.99): 8192 data bytes
  421.   8200 bytes from 129.240.222.99: icmp_seq=0 ttl=64 time=15.2 ms
  422.   8200 bytes from 129.240.222.99: icmp_seq=1 ttl=64 time=15.9 ms
  423.   8200 bytes from 129.240.222.99: icmp_seq=2 ttl=64 time=14.9 ms
  424.   8200 bytes from 129.240.222.99: icmp_seq=3 ttl=64 time=14.9 ms
  425.   8200 bytes from 129.240.222.99: icmp_seq=4 ttl=64 time=15.0 ms
  426.  
  427.   --- lugulbanda.uio.no ping statistics ---
  428.   5 packets transmitted, 5 packets received, 0% packet loss
  429.   round-trip min/avg/max = 14.9/15.1/15.9 ms
  430.   ______________________________________________________________________
  431.  
  432.   The time here is how long the ping packet took to get back and forth
  433.   to lugulbanda.  15ms is quite fast.  Over a 28.000 bps line you can
  434.   expect something like 4000-5000ms, and if the line is otherwise loaded
  435.   this time will be even higher, easily double.  When this time is high
  436.   we say that there is 'high latency'.  Generally, for larger packets
  437.   and for more loaded lines the latency will tend to increase.  Increase
  438.   timeo suitably for your line and load.  And since the latency
  439.   increases when you use the line for other things: If you ever want to
  440.   use FTP and NFS at the same time you should try measuring ping times
  441.   while using FTP to transfer files.
  442.  
  443.   6.  Security and NFS
  444.  
  445.   I am by no means a computer security expert.  But I do have a little
  446.   advice for the security conscious.  But be warned: This is by no means
  447.   a complete list of NFS related problems and if you think you're safe
  448.   once you're read and implemented all this I have a bridge I want to
  449.   sell you.
  450.  
  451.   This section is probably of no concern if you are on a closed network
  452.   where you trust all the users, and no-one you don't trust can get
  453.   access to machines on the network. I.e., there should be no way to
  454.   dial into the network, and it should in no way be connected to other
  455.   networks where you don't trust everyone using it as well as the
  456.   security.  Do you think I sound paranoid?  I'm not at all paranoid.
  457.   This is just basic security advice.  And remember, the things I say
  458.   here is just the start of it.  A secure site needs a diligent and
  459.   knowledgeable admin that knows where to find information about current
  460.   and potential security problems.
  461.  
  462.   NFS has a basic problem in that the client, if not told otherwise,
  463.   will trust the NFS server and vice versa.  This can be bad.  It means
  464.   that if the server's root account is broken into it can be quite easy
  465.   to break into the client's root account as well.  And vice versa.
  466.   There are a couple of coping strategies for this, which we'll get back
  467.   to.
  468.  
  469.   Something you should read is the CERT advisories on NFS, most of the
  470.   text below deals with issues CERT has written advisories about.  See
  471.   ftp.cert.org/01-README for a up to date list of CERT advisories.  Here
  472.   are some NFS related advisories:
  473.  
  474.   ______________________________________________________________________
  475.   CA-91:21.SunOS.NFS.Jumbo.and.fsirand                            12/06/91
  476.        Vulnerabilities concerning Sun Microsystems, Inc. (Sun) Network
  477.        File System (NFS) and the fsirand program.  These vulnerabilities
  478.        affect SunOS versions 4.1.1, 4.1, and 4.0.3 on all architectures.
  479.        Patches are available for SunOS 4.1.1.  An initial patch for SunOS
  480.        4.1 NFS is also available. Sun will be providing complete patches
  481.        for SunOS 4.1 and SunOS 4.0.3 at a later date.
  482.  
  483.   CA-94:15.NFS.Vulnerabilities                                    12/19/94
  484.        This advisory describes security measures to guard against several
  485.        vulnerabilities in the Network File System (NFS). The advisory was
  486.        prompted by an increase in root compromises by intruders using tools
  487.        to exploit the vulnerabilities.
  488.  
  489.   CA-96.08.pcnfsd                                                 04/18/96
  490.        This advisory describes a vulnerability in the pcnfsd program (also
  491.        known as rpc.pcnfsd). A patch is included.
  492.   ______________________________________________________________________
  493.  
  494.   6.1.  Client Security
  495.  
  496.   On the client we can decide that we don't want to trust the server too
  497.   much a couple of ways with options to mount.  For example we can
  498.   forbid suid programs to work off the NFS file system with the nosuid
  499.   option.  This is a good idea and you should consider using this with
  500.   all NFS mounted disks.  It means that the server's root user cannot
  501.   make a suid-root program on the file system, log in to the client as a
  502.   normal user and then use the suid-root program to become root on the
  503.   client too.  We could also forbid execution of files on the mounted
  504.   file system altogether with the noexec option.  But this is more
  505.   likely to be impractical than nosuid since a file system is likely to
  506.   at least contain some scripts or programs that needs to be executed.
  507.   You enter these options in the options column, with the rsize and
  508.   wsize, separated by commas.
  509.  
  510.   6.2.  Server security: nfsd
  511.  
  512.   On the server we can decide that we don't want to trust the client's
  513.   root account.  We can do that by using the root_squash option in
  514.   exports:
  515.  
  516.   ______________________________________________________________________
  517.   /mn/eris/local apollon(rw,root_squash)
  518.   ______________________________________________________________________
  519.  
  520.   Now, if a user with UID 0 on the client attempts to access (read,
  521.   write, delete) the file system the server substitutes the UID of the
  522.   servers `nobody' account.  Which means that the root user on the
  523.   client can't access or change files that only root on the server can
  524.   access or change.  That's good, and you should probably use
  525.   root_squash on all the file systems you export.  "But the root user on
  526.   the client can still use 'su' to become any other user and access and
  527.   change that users files!" say you.  To which the answer is: Yes, and
  528.   that's the way it is, and has to be with Unix and NFS.  This has one
  529.   important implication: All important binaries and files should be
  530.   owned by root, and not bin or other non-root account, since the only
  531.   account the clients root user cannot access is the servers root
  532.   account.  In the NFSd man page there are several other squash options
  533.   listed so that you can decide to mistrust whomever you (don't) like on
  534.   the clients.  You also have options to squash any UID and GID range
  535.   you want to.  This is described in the Linux NFSd man page.
  536.  
  537.   root_squash is in fact the default with the Linux NFSd, to grant root
  538.   access to a filesystem use no_root_squash.
  539.  
  540.   Another important thing is to ensure that nfsd checks that all it's
  541.   requests comes from a privileged port.  If it accepts requests from
  542.   any old port on the client a user with no special privileges can run a
  543.   program that's is easy to obtain over the Internet. It talks nfs
  544.   protocol and will claim that the user is anyone the user wants to be.
  545.   Spooky.  The Linux nfsd does this check by default, on other OSes you
  546.   have to enable this check yourself.  This should be described in the
  547.   nfsd man page for the OS.
  548.  
  549.   Another thing.  Never export a file system to 'localhost' or
  550.   127.0.0.1.  Trust me.
  551.  
  552.   6.3.  Server security: the portmapper
  553.  
  554.   The basic portmapper, in combination with nfsd has a design problem
  555.   that makes it possible to get to files on NFS servers without any
  556.   privileges.  Fortunately the portmapper Linux uses is relatively
  557.   secure against this attack, and can be made more secure by configuring
  558.   up access lists in two files.
  559.  
  560.   First we edit /etc/hosts.deny.  It should contain the line
  561.  
  562.   ______________________________________________________________________
  563.   portmap: ALL
  564.   ______________________________________________________________________
  565.  
  566.   which will deny access to everyone.  That's a bit drastic perhaps, so
  567.   we open it again by editing /etc/hosts.allow.  But first we need to
  568.   figure out what to put in it.  It should basically list all machines
  569.   that should have access to your portmapper.  On a run of the mill
  570.   Linux system there are very few machines that need any access for any
  571.   reason.  The portmapper administrates nfsd, mountd, ypbind/ypserv,
  572.   pcnfsd, and 'r' services like ruptime and rusers.  Of these only nfsd,
  573.   mountd, ypbind/ypserv and perhaps pcnfsd are of any consequence.  All
  574.   machines that needs to access services on your machine should be
  575.   allowed to do that.  Let's say that your machines address is
  576.   129.240.223.254 and that it lives on the subnet 129.240.223.0 should
  577.   have access to it (those are terms introduced by the networking HOWTO,
  578.   go back and refresh your memory if you need to).  Then we write
  579.  
  580.   ______________________________________________________________________
  581.   portmap: 129.240.223.0/255.255.255.0
  582.   ______________________________________________________________________
  583.  
  584.   in hosts.allow.  This is the same as the network address you give to
  585.   route and the subnet mask you give to ifconfig.  For the device eth0
  586.   on this machine ifconfig should show
  587.  
  588.   ______________________________________________________________________
  589.   eth0      Link encap:10Mbps Ethernet  HWaddr 00:60:8C:96:D5:56
  590.             inet addr:129.240.223.254  Bcast:129.240.223.255  Mask:255.255.255.0
  591.             UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  592.             RX packets:360315 errors:0 dropped:0 overruns:0
  593.             TX packets:179274 errors:0 dropped:0 overruns:0
  594.             Interrupt:10 Base address:0x320
  595.   ______________________________________________________________________
  596.  
  597.   and netstat -rn should show
  598.  
  599.   ______________________________________________________________________
  600.   Kernel routing table
  601.   Destination     Gateway         Genmask         Flags Metric Ref Use    Iface
  602.   129.240.223.0   0.0.0.0         255.255.255.0   U     0      0   174412 eth0
  603.   ______________________________________________________________________
  604.  
  605.   (Network address in first column).
  606.  
  607.   The hosts.deny and hosts.allow files are described in the manual pages
  608.   of the same names.
  609.  
  610.   IMPORTANT: Do not put anything but IP NUMBERS in the portmap lines of
  611.   these files.  Host name lookups can indirectly cause portmap activity
  612.   which will trigger host name lookups which can indirectly cause
  613.   portmap activity which will trigger...
  614.  
  615.   The above things should make your server tighter.  The only remaining
  616.   problem (Yeah, right!) is someone breaking root (or boot MS-DOS) on a
  617.   trusted machine and using that privilege to send requests from a
  618.   secure port as any user they want to be.
  619.  
  620.   6.4.  NFS and firewalls
  621.  
  622.   It's a very good idea to firewall the nfs and portmap ports in your
  623.   router or firewall.  The nfsd operates at port 2049, both udp and tcp
  624.   protocols.  The portmapper at port 111, tcp and udp, and mountd at
  625.   port 745 and and 747, tcp and udp.  Normally.  You should check the
  626.   ports with the rpcinfo -p command.
  627.  
  628.   If on the other hand you want NFS to go through a firewall there are
  629.   options for newer NFSds and mountds to make them use a specific
  630.   (nonstandard) port which can be open in the firewall.
  631.  
  632.   6.5.  Summary
  633.  
  634.   If you use the hosts.allow/deny, root_squash, nosuid and privileged
  635.   port features in the portmapper/nfs software you avoid many of the
  636.   presently known bugs in nfs and can almost feel secure about that at
  637.   least.  But still, after all that: When an intruder has access to your
  638.   network, s/he can make strange commands appear in your /var/spool/mail
  639.   are mounted over NFS.  For the same reason, you should never access
  640.   your PGP private key over nfs.  Or at least you should know the risk
  641.   involved.  And now you know a bit of it.
  642.  
  643.   NFS and the portmapper makes up a complex subsystem and therefore it's
  644.   not totally unlikely that new bugs will be discovered, either in the
  645.   basic design or the implementation we use.  There might even be holes
  646.   known now, which someone is abusing.  But that's life.  To keep
  647.   abreast of things like this you should at least read the newsgroups
  648.   comp.os.linux.announce and comp.security.announce at a absolute
  649.   minimum.
  650.  
  651.   7.  Mount Checklist
  652.  
  653.   This section is based on IBM Corp. NFS mount problem checklist.  My
  654.   thanks to them for making it available for this HOWTO.  If you
  655.   experience a problem mounting a NFS filesystem please refer to this
  656.   list before posting your problem.  Each item describes a failure mode
  657.   and the fix.
  658.  
  659.   1. File system not exported, or not exported to the client in
  660.      question.
  661.  
  662.      Fix: Export it
  663.  
  664.   2. Name resolution doesn't jibe with the exports list.
  665.  
  666.      e.g.: export list says export to johnmad but johnmad's name is
  667.      resolved as johnmad.austin.ibm.com.  mount permission is denied.
  668.  
  669.      Fix: Export to both forms of the name.
  670.  
  671.      It can also happen if the client has 2 interfaces with different
  672.      names for each of the two adapters and the export only specifies
  673.      one.
  674.  
  675.      Fix: export both interfaces.
  676.  
  677.      This can also happen if the server can't do a lookuphostbyname or
  678.      lookuphostbyaddr (these are library functions) on the client.  Make
  679.      sure the client can do host <name>; host <ip_addr>; and that both
  680.      shows the same machine.
  681.  
  682.      Fix: straighten out name resolution.
  683.  
  684.   3. The file system was mounted after NFS was started (on that server).
  685.      In that case the server is exporting underlying mount point, not
  686.      the mounted filesystem.
  687.  
  688.      Fix: Shut down NFSd and then restart it.
  689.  
  690.      Note: The clients that had the underlying mount point mounted will
  691.      get problems accessing it after the restart.
  692.  
  693.   4. The date is wildly off on one or both machines (this can mess up
  694.      make)
  695.  
  696.      Fix: Get the date set right.
  697.  
  698.      The HOWTO author recommends using NTP to synchronize clocks.  Since
  699.      there are export restrictions on NTP in the US you have to get NTP
  700.      for debian, redhat or slackware from
  701.      ftp://ftp.hacktic.nl/pub/replay/pub/linux or a mirror.
  702.  
  703.   5. The server can not accept a mount from a user that is in more than
  704.      8 groups.
  705.  
  706.      Fix: decrease the number of groups the user is in or mount via a
  707.      different user.
  708.  
  709.   8.  FAQs
  710.  
  711.   This is the FAQ section.  Most of it was written by Alan Cox.
  712.  
  713.   1. I get a lot of 'stale nfs handle' errors when using Linux as a nfs
  714.      server.
  715.  
  716.      This is caused by a bug in some oldish nfsd versions.  It is fixed
  717.      in nfs-server2.2beta16 and later.
  718.  
  719.   2. When I try to mount a file system I get
  720.  
  721.          can't register with portmap: system error on send
  722.  
  723.   You are probably using a Caldera system.  There is a bug in the rc
  724.   scripts.  Please contact Caldera to obtain a fix.
  725.  
  726.   3. Why can't I execute a file after copying it to the NFS server?
  727.  
  728.      The reason is that nfsd caches open file handles for performance
  729.      reasons (remember, it runs in user space). While nfsd has a file
  730.      open (as is the case after writing to it), the kernel won't allow
  731.      you to execute it. Nfsds newer than  spring 95 release open files
  732.      after a few seconds, older ones would cling to them for days.
  733.  
  734.   4. My NFS files are all read only
  735.  
  736.      The Linux NFS server defaults to read only. RTFM the ``exports''
  737.      and nfsd manual pages. You will need to alter /etc/exports.
  738.  
  739.   5. I mount from a linux nfs server and while ls works I can't read or
  740.      write files.
  741.  
  742.      On older versions of Linux you must mount a NFS servers with
  743.      rsize=1024,wsize=1024.
  744.  
  745.   6. I mount from a Linux NFS server with a block size of between
  746.      3500-4000 and it crashes the Linux box regularly
  747.  
  748.      Basically don't do it then.
  749.  
  750.   7. Can Linux do NFS over TCP
  751.  
  752.      No, not at present.
  753.  
  754.   8. I get loads of strange errors trying to mount a machine from a
  755.      Linux box.
  756.  
  757.      Make sure your users are in 8 groups or less. Older servers require
  758.      this.
  759.  
  760.   9. When I reboot my machine it sometimes hangs when trying to unmount
  761.      a hung NFS server.
  762.  
  763.      Do not unmount NFS servers when rebooting or halting, just ignore
  764.      them, it will not hurt anything if you don't unmount them.  The
  765.      command is umount -avt nonfs.
  766.  
  767.   10.
  768.      Linux NFS clients are very slow when writing to Sun and BSD systems
  769.  
  770.      NFS writes are normally synchronous (you can disable this if you
  771.      don't mind risking losing data). Worse still BSD derived kernels
  772.      tend to be unable to work in small blocks. Thus when you write 4K
  773.      of data from a Linux box in the 1K packets it uses BSD does this
  774.  
  775.                read 4K page
  776.                alter 1K
  777.                write 4K back to physical disk
  778.                read 4K page
  779.                alter 1K
  780.                write 4K page back to physical disk
  781.                etc..
  782.  
  783.   9.  Exporting filesystems
  784.  
  785.   The way to export filesytems with NFS is not completely consistent
  786.   across platforms of course.  In this case Linux and Solaris 2 are the
  787.   deviants.  This section lists, superficially the way to do it on most
  788.   systems.  If the kind of system you have is not covered you must check
  789.   your OS man-pages.  Keywords are: nfsd, system administration tool, rc
  790.   scripts, boot scripts, boot sequence, /etc/exports, exportfs.  I'll
  791.   use one example throughout this section: How to export /mn/eris/local
  792.   to apollon read/write.
  793.  
  794.   9.1.  IRIX, HP-UX, Digital-UNIX, Ultrix, SunOS 4 (Solaris 1), AIX
  795.  
  796.   These OSes use the traditional Sun export format.  In /etc/exports
  797.   write:
  798.  
  799.   ______________________________________________________________________
  800.   /mn/eris/local -rw=apollon
  801.   ______________________________________________________________________
  802.  
  803.   The complete documentation is in the exports man page.  After editing
  804.   the file run exportfs -av to export the filesystems.
  805.  
  806.   How strict the exportfs command is about the syntax varies.  On some
  807.   OSes you will find that previously entered lines reads:
  808.  
  809.   ______________________________________________________________________
  810.   /mn/eris/local apollon
  811.   ______________________________________________________________________
  812.  
  813.   or even something degenerate like:
  814.  
  815.   ______________________________________________________________________
  816.   /mn/eris/local rw=apollon
  817.   ______________________________________________________________________
  818.  
  819.   I recommend being formal.  You risk that the next version of exportfs
  820.   if much stricter and then suddenly everything will stop working.
  821.  
  822.   9.2.  Solaris 2
  823.  
  824.   Sun completely re-invented the wheel when they did Solaris 2.  So this
  825.   is completely different from all other OSes.  What you do is edit the
  826.   file /etc/dfs/dfstab.  In it you place share commands as documented in
  827.   the share(1M) man page.  Like this:
  828.  
  829.   ______________________________________________________________________
  830.   share -o rw=apollon -d "Eris Local" /mn/eris/local
  831.   ______________________________________________________________________
  832.  
  833.   After editing run the program shareall to export the filesystems.
  834.  
  835.   10.  PC-NFS
  836.  
  837.   You should not run PC-NFS.  You should run samba.
  838.  
  839.   Sorry: I don't know anything about PC-NFS.  If someone feels like
  840.   writing something about it please do and I'll include it here.
  841.  
  842.