NFS Server And Client On OpenSUSE 11.3
I do not issue any guarantee that this will work for you! 1 Preliminary NoteI'm using two OpenSUSE systems here:
2 Installing NFS
server:
On the NFS server we run:
yast2 -i nfs-kernel-server
Then we create the system startup links for the NFS server and start it:
chkconfig --add nfsserver
/etc/init.d/nfsserver start
client:
On the client we can install NFS as follows:
yast2 -i nfs-client
3 Exporting Directories On The Server
server:
I'd like to make the directories /home and /var/nfs accessible to the client; therefore we must "export" them on the server.When a client accesses an NFS share, this normally happens as the user nobody. Usually the /home directory isn't owned by nobody (and I don't recommend to change its ownership to nobody!), and because we want to read and write on /home, we tell NFS that accesses should be made as root (if our /home share was read-only, this wouldn't be necessary). The /var/nfs directory doesn't exist, so we can create it and change its ownership to nobody and nogroup:
mkdir /var/nfs
Now we must modify /etc/exports where we "export" our NFS shares. We specify /home and /var/nfs as NFS shares and tell NFS to make accesses to /home as root (to learn more about /etc/exports, its format and available options, take a look atchown nobody:nogroup /var/nfs
man 5 exports
)
vi /etc/exports
Whenever we modify /etc/exports, we must run
exportfs -a
afterwards to make the changes effective.4 Mounting The NFS Shares On The Client
client:
First we create the directories where we want to mount the NFS shares, e.g.:
mkdir -p /mnt/nfs/home
Afterwards, we can mount them as follows:mkdir -p /mnt/nfs/var/nfs
mount 192.168.0.100:/home /mnt/nfs/home
You should now see the two NFS shares in the outputs ofmount 192.168.0.100:/var/nfs /mnt/nfs/var/nfs
df -h
client:~ # df -h
andFilesystem Size Used Avail Use% Mounted on /dev/sda2 12G 1.3G 9.8G 12% / devtmpfs 245M 132K 245M 1% /dev tmpfs 247M 4.0K 247M 1% /dev/shm /dev/sda3 18G 172M 17G 2% /srv 192.168.0.100:/home 12G 1.5G 9.6G 14% /mnt/nfs/home 192.168.0.100:/var/nfs 12G 1.5G 9.6G 14% /mnt/nfs/var/nfs client:~ #
mount
client:~ # mount
/dev/sda2 on / type ext4 (rw,acl,user_xattr) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) debugfs on /sys/kernel/debug type debugfs (rw) devtmpfs on /dev type devtmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,mode=1777) devpts on /dev/pts type devpts (rw,mode=0620,gid=5) /dev/sda3 on /srv type ext4 (rw,acl,user_xattr) securityfs on /sys/kernel/security type securityfs (rw) none on /proc/fs/vmblock/mountPoint type vmblock (rw) 192.168.0.100:/home on /mnt/nfs/home type nfs (rw,addr=192.168.0.100) 192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,addr=192.168.0.100) client:~ # 5 TestingOn the client, you can now try to create test files on the NFS shares:
client:
touch /mnt/nfs/home/test.txt
Now go to the server and check if you can see both test files:touch /mnt/nfs/var/nfs/test.txt
server:
ls -l /home/
server:~ # ls -l /home/
total 4 drwxr-xr-x 6 administrator users 4096 Jul 19 17:26 administrator -rw-r--r-- 1 root root 0 Sep 14 20:47 test.txt server:~ #
ls -l /var/nfs
server:~ # ls -l /var/nfs
(Please note the different ownerships of the test files: the /home NFS share gets accessed as root, therefore /home/test.txt is owned by root; the /var/nfs share gets accessed as nobody, therefore /var/nfs/test.txt is owned by nobody.)total 0 -rw-r--r-- 1 nobody nogroup 0 Sep 14 20:47 test.txt server:~ # 6 Mounting NFS Shares At Boot TimeInstead of mounting the NFS shares manually on the client, you could modify /etc/fstab so that the NFS shares get mounted automatically when the client boots.
client:
Open /etc/fstab and append the following lines:
vi /etc/fstab
man nfs
To test if your modified /etc/fstab is working, reboot the client:
reboot
After the reboot, you should find the two NFS shares in the outputs of
df -h
client:~ # df -h
andFilesystem Size Used Avail Use% Mounted on /dev/sda2 12G 1.3G 9.8G 12% / devtmpfs 245M 132K 245M 1% /dev tmpfs 247M 4.0K 247M 1% /dev/shm /dev/sda3 18G 172M 17G 2% /srv 192.168.0.100:/home 12G 1.5G 9.6G 14% /mnt/nfs/home 192.168.0.100:/var/nfs 12G 1.5G 9.6G 14% /mnt/nfs/var/nfs client:~ #
mount
client:~ # mount
/dev/sda2 on / type ext4 (rw,acl,user_xattr) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) debugfs on /sys/kernel/debug type debugfs (rw) devtmpfs on /dev type devtmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,mode=1777) devpts on /dev/pts type devpts (rw,mode=0620,gid=5) /dev/sda3 on /srv type ext4 (rw,acl,user_xattr) securityfs on /sys/kernel/security type securityfs (rw) rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) 192.168.0.100:/home on /mnt/nfs/home type nfs (rw,sync,hard,intr,addr=192.168.0.100) 192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,sync,hard,intr,addr=192.168.0.100) none on /proc/fs/vmblock/mountPoint type vmblock (rw) client:~ #
=====================================================================
Linux Highly Availability(HA) NFS servers
Here are the steps to prepare automated NFS failover. Server setup details: Hostname: ServerNFS01 IP Address: 10.10.10.11 Hostname: ServerNFS02 IP Address: 10.10.10.12 Linux HA Virtual Hostname: servernfs01 IP Address 10.10.10.10 NFS Client Hostname NFSclient01 IP Address: 10.10.10.13 Require RPM: nfs-utils util-linux heartbeat portmap The /data directory is a Linux HA share drive sitting on /dev/sdb1(ext3) and contains NFS share drive. Create a new partition using fdisk $ fdisk /dev/sdb Format /dev/sdb1 as ext3 $ mkfs.ext3 /dev/sdb1 Create new folder /data $ mkdir /data Linux HA configuration file: $ /etc/ha.d/ha.cf logfile /var/log/ha-log logfacility local0 node servernfs01 node servernfs02 keepalive 2 warntime 30 deadtime 60 initdead 120 udpport 694 ucast eth0 10.10.10.11 ucast eth0 10.10.10.12 auto_failback off respawn hacluster /usr/lib/heartbeat/ipfail watchdog /dev/watchdog $ /etc/ha.d/authkeys auth 2 2 sha1 NFS_test! $ /etc/ha.d/haresources servernfs01 10.10.10.10\ Filesystem::/dev/sdb1::/data::ext3 \ service $ cat /etc/ha.d/resource.d/service
Code:
---------------------------------------------------------------------------------------------------------------
# Script START here
# service – Linux HA stop and start script
#
usage(){
# Spit out usage message
#
cat <
USAGE:
$(basename $0) start
$(basename $0) stop
MSG
exit
}
# Main
#
if [ "$(id -u)" != 0 ]; then
echo "Error: Must be root to run this program."
exit
fi
if [ "$#" != 1 ];then
usage
fi
case $1 in
'start')
echo -n Starting NFS . . .
#Restarting NFS server
/etc/init.d/nfsserver restart
#Virtual IP
/sbin/sm-notify -v 10.10.10.10
;;
'stop')
echo -n Stopping NFS . . .
#Stopping NFS server
/etc/init.d/nfsserver stop
#Virtual IP
/sbin/sm-notify -v 10.10.10.10
;;
esac
# Script END here
---------------------------------------------------------------------------------------------------------------
Virtual IP Address Information: eth0:0 Link encap:Ethernet HWaddr 00:50:56:BA:7B:CC inet addr:10.10.10.10 Bcast:10.10.225.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:177 Base address:0x1424 Move existing NFS server files to Linux HA share drive $ mv /var/lib/nfs /data $ mv /etc/exports /data Create a symbolic link for NFS server $ ln -s /data/nfs /var/lib/nfs $ ln -s /data/exports /etc/exports $ cat /etc/exports /data 10.10.10.0/255.255.255.0(rw,no_root_squash,no_all_squash,sync) For ServerNFS01 & ServerNFS02, you’re require $ chkconfig nfsserver off $ chkconfig portmap on $ chkconfig nfsboot off $ chkconfig nfs off $ chkconfig heartbeat on Please make sure you have NFS services ON for your NFS client machine – NFSclient01 $ chkconfig nfs on Let’s start TESTING …. 1. Login to NFSclient01 and type mkdir /data ; mount -t nfs 10.10.10.10:/data /data 2. Type mount and you should see /data mounted on NFS. 10.10.10.10:/data on /data type nfs (rw,addr=10.10.10.10) 3. Power Off ServerNFS01 immediately. 4. Linux HA will take over by ServerNFS02. 3. Type ifconfig on ServerNFS02 and you should able to see virtual IP address – 10.10.10.10(please wait for a while to see it running). 4. Type /etc/init.d/nfsserver status and you should see NFS server running on node2. 5. Go back to NFSclient01, type ls -l /data or mount and you should see as usual which is mounted on virtual IP address 10.10.10.10 on ServerNFS02.
===================================================================
Sharing resources
is an important task in networks. There are numerous ways are used to
share the files and directories over the network. In the Linux Operating
system, Network File System Server enables the user to share their
files and directories within the network environment. To install Network
File System (NFS), your system must satisfy the following requirements
|
| Your uid and gid will be different. You will use these values in the next step. |
Now set up the locations and settings to share. These are referred to as exports and are configured in the /etc/exports file. Modify this file to configure access to the directory being used for this pattern.
/home/nfs/bi43pbfrs lnxpb*(rw,all_squash,anonuid=501,anongid=501)
| The /etc/exports file will need to contain values that pertain to your systems. Ensure you are using the correct host pattern, uid, and gid. |
The following table examines each part of the line in more detail:
| /home/nfs/bi43pbfrs | Indicates the directory being shared |
| lnxpb* | Allows any host that begins with "lnxpb" to mount this share |
| rw | Allows reading and writing rights to this mount |
| all_squash | Squashes all user accounts that try to mount this share |
| anonuid | Sets the anonymous user ID used by all accounts that try to mount this share |
| anongid | Sets the anonymous group ID used by all accounts that try to access this share |
> exportfs -a
> showmount -e lnxpb06
| Be sure to substitute your NFS Server hostname for "lnxpb06". |
You will see output similar to the following:
Export list for lnxpb06:
/home/nfs/bi43pbfrs lnxpb*
/home/nfs/bi43pbfrs lnxpb*
NFS client configuration
Once you have the NFS server running and configured, mount the NFS share on the client machines. In our pattern, the lnxpb04 and lnxpb05 machines are the BI 4.0 server machines, and these two machines need these shares mounted.For more information on NFS Client configuration, refer to your operating system documentation:
- Red Hat 6 - Storage Administration Guide - NFS Client Configuration.
- SUSE Administration Guide - Chapter 27.4 Configuring Clients
- Log into lnxpb04 as root.
- Create the directory to use for the mount point. Run the following command:
> mkdir -p /opt/sap/bi4/bi43pbfrs
- Run the following commands to create the user sapbi and assign it the password Sapbi*123:
> useradd -s /bin/bash -m sapbi
> passwd sapbi
Changing password for sapbi.
New Password: Sapbi*123
Reenter New Password: Sapbi*123
Password changed.
- Change ownership of the newly created directory to be sapbi. Run the following command:
> chown sapbi /opt/sap/bi4/bi43pbfrs
- Run the following command to modify the /etc/fstab file:
> vi /etc/fstab
- Add the following line to the end of the fstab file:
lnxpb06:/home/nfs/bi43pbfrs /opt/sap/bi4/bi43pbfrs nfs defaults 0 0

Ensure that you replace "lnxpb06" with the name of your NFS server.
The following table examines each part of the line in more detail:
lnxpb06 Hostname of the NFS server /home/nfs/bi43pbfrs Directory path on the NFS server /opt/sap/bi4/bi43pbfrs Mount location on the NFS client nfs File system type defaults Options for the mount (in this case, the defaults of the NFS server) 0 0 Dump frequency / pass number - Run the following command to mount the newly created mount point:
> mount -a
- Run the following command to check whether the mount is available:
> mount
You will see output similar to the following:…
…
lnxpb06:/home/nfs/bi43pbfrs on /opt/sap/bi4/bi43pbfrs type nfs (rw,vers=4,addr=10.165.28.122,clientaddr=10.165.28.125)
- Change to the sapbi user and ensure you can read and write to that new mount point. Run the following commands:
> su - sapbi
> cd /opt/sap/bi4/bi43pbfrs/
> touch a
> rm a
> ls -alrt
You will see output similar to the following:total 8
drwxr-xr-x. 7 sapbi root 4096 Mar 20 10:22 .
drwxr-xr-x. 2 nobody root 4096 Mar 20 10:52 .
- Repeat steps 1-9 on the lnxpb05 machine.
- Create the directories for your input and output files. Run the following command on either lnxpb04 or lnxpb05:
> cd /opt/sap/bi4/bi43pbfrs/
> mkdir frsinput frsoutput
> ls -al
You will see output similar to the following:total 8
drwxrwxr-x. 86 sapbi nobody 4096 Jun 21 15:58 frsinput
drwxrwxr-x. 5 sapbi nobody 4096 Apr 4 19:28 frsoutput
Once lnxpb04 and lnxpb05 have these mount points set up, you can point both of your Input/Output File Repository Servers to the shared location. This ensures that the system remains active in the event that one of your file repository servers goes down. We cover this in detail in the File Repository Setup section.
=========================================================================
Ubuntu Linux NFS Server installation and Configuration
A. In order to set NFS server you need to install the following packages:
=> nfs-kernel-server - Linux NFS Server
=> nfs-common - NFS Common programs
=> portmap - The RPC portmapper
Ubuntu Linux install NFS Server
Use apt-get command to install all required packages:$ sudo apt-get install nfs-kernel-server portmap nfs-commonSharing directory with /etc/exports
The NFS file systems being exported / shared using /etc/exports file. You need to specify directory (file system) to share with rest of the nfs client computers. The file /etc/exports serves as the access control list for file systems which may be exported to NFS clients.$ sudo vi /etc/exportsTo export /data directory to 192.168.1.0/24 network enter the following in /etc/exports file:
/data 192.168.1.0/24(rw,rsync)To export /sales to hostname tom and jerry, enter:
/sales tom(ro,sync) jerry(ro,sync)To export /users to 192.168.1.0/24 in read write format, enter:
/users 192.168.1.0/24(ro,sync) jerry(rw,fsid=0,insecure,no_subtree_check,async)Where,
- rw : Allow clients to read as well as write access
- ro : Read only access
- insecure : Tells the NFS server to use unpriveledged ports (ports > 1024).
- no_subtree_check : If the entire volume (/users) is exported, disabling this check will speed up transfers.
- async : async will speed up transfers.
$ sudo /etc/init.d/nfs-kernel-server restartNow your NFS sever is sharing /sales and /data directories.
How do I access shared directories from Linux client computer?
Login to Linux desktop system and enter the following command to mount shared directories. First, create a mountpoint on your client computer:# mkdir /mnt/dataMount the server:
# mount nfs-server:/data /mnt/dataYou can also use following syntax for NFS client version 4:
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/data /mnt/dataOR
# mount -t nfs4 -o proto=tcp,port=2049 192.168.1.100:/data /mnt/dataWhere,
- 192.168.1.100 : NFS Server IP address
- proto=tcp,port=2049 : Force to use TCP protocol i.e. mount the NFS filesystem using TCP. The numeric value of the port to connect to the NFS server on. If the port number is 0 (the default) then query the remote host’s portmapper for the port number to use. If the remote host’s NFS daemon is not registered with its portmapper, the standard NFS port number 2049 is used instead.
How do I access my files?
To access shared files use regular commands or GUI file manager:$ cd /mnt/data
$ ls
$ mkdir office
$ pwdSee Linux NFS client how to for more information.
To see mounted file system and available disk space use df command:
$ df -hOutput:
Filesystem Size Used Avail Use% Mounted on /dev/sda2 92G 23G 65G 26% / varrun 1013M 128K 1013M 1% /var/run varlock 1013M 0 1013M 0% /var/lock udev 1013M 84K 1013M 1% /dev devshm 1013M 0 1013M 0% /dev/shm /dev/sda1 98G 22G 77G 23% /media/sda1 /dev/sda5 274G 29G 245G 11% /share /dev/sdb2 230G 4.9G 213G 3% /backup.iscsi nfs-server:/data/ 230G 31G 188G 14% /mnt/data
How do I see all shared directories from client computer?
Use showmount command to query the mount daemon (NFS Server) on a remote host for information about the state of the NFS server on that machine:$ showmount -a ==================================================================================== NFS Server Setup – Ubuntu 11.04 – For Home
NFS is really handy tool for easily exporting a directory to remote machines. Particularly useful on a home network between two linux devices. I’m going to run through how simple this is to install and configure.
Word to the wise, a future post will go into more depth of setting up nfs in a corporate environment, but right now all we care about is opening a scratch area on your home machine.
First things first. We need to install the NFS server application for ubuntu. So open a terminal window. We are going to do this through apt-get. That’s ubuntu package manger, performs the same function as Redhat/Fedora/CentOS yum application.
Now you have a terminal open. Type the following
sudo apt-get install nfs-kernel-server
When prompted select Y to complete the installation.
Next step to choose the directory you want to share out. In this case for example we will create a shared area called /export/shared
sudo mkdir /export/We chmod 777 here to open up the directory. This is inadvisable for nearly all other locations on your system apart from /tmp. 777 makes everything within this directory accessible to edit or delete.
sudo mkdir /export/shared
sudo chmod 777 /export/shared
Next we get into the meat of exporting this directory. Open the following file
sudo gedit /etc/exports

Scroll to the end of the file and add the following
/export/shared *(rw)Again this is for a home environment where you don’t need to work about locking down a share to intruders. This exports this directory to all hosts and it is read write.
Save your file and exit.
Now we must tell the NFS server we are ready to export this directory. From the terminal do the following
sudo /etc/init.d/nfs-kernel-server startThis may through some complains but to test that these files are now exported we need to do the following.
sudo showmount -eYou should see you directory listed here, if not something has gone wrong. Re-try these steps from the start. On the client side, the system you are sharing these files with, in this example another ubuntu system. We need to follow these steps.
To make a quick temporary connection:
sudo mkdir /sratchNow you should be able to enter this directory and view its contents, add content or delete.
sudo showmount -e nfsserver
sudo mount nfsserver:/export/shared /scratch
cd /scratchTo make a permanent connection that will survive a reboot we need to edit a file
touch testfile
ls
sudo cp /etc/fstab /etc/fstab.bkup1 – Creates a back upThis file can look a bit overwhelming if you are not used to its contents. So MAKE A BACK UP.
sudo gedit /etc/fstab
Within the file the format is given and it is basically this
Device Mount Type Options Dump PassSave file and quit. From the terminal type this to bring the mount to life
nfsserver:/export/shared /scratch nfs default 0 0
sudo mount -aThis command reloads /etc/fstab. Your NFS mount will not survive a reboot.
To start your nfs server automatically on each reboot:
sudo update-rc.d portmap defaults
sudo update-rc.d nfs-common defaults
sudo update-rc.d nfs-kernel-server defaults
===================================================================
NFS is an ancient old way of sharing folders on a network . But this is possible on a LINUX only network.And in such a network NFS is always preferred as it has a lot of advantages over samba.NFS is pretty easy to setup in ubuntu linux.Just type in a few commands and a few settings and your done.So here's how you setup NFS in your ubuntu linux machine :
SERVER CONFIGURATION :
Step 1 : Go to the Terminal(Applications->Accessories->Terminal)
Step 2 : And type sudo apt-get install nfs-kernel-server nfs-common portmap to install nfs server
Step 3 : After the installation is done, you need to configure portmap , do this by typing sudo dpkg-reconfigure portmap . Ensure that You Select NO to bind Local loopback Address.

Step 4 : Once thats done, just restart Portmap by typing sudo /etc/init.d/portmap restart
HOW TO SHARE FOLDERS WITH NFS SERVER :
THE COMMAND LINE WAY :
Step 1 : You would need to edit the /etc/exports file for this, so in the terminal type sudo gedit /etc/exports
Step 2 : gedit should open up with the exports file.
Step 3 : Now to add a shared folder say /home/prash/test to be accessible by only one pc say 192.168.1.10 and say it has to be read-write.Then you add the line /home/prash/test 192.168.1.10(rw,no_root_squash,async) to the end of exports file.
If you want to share a folder say /home/prash/test again but this time say you want it to be read only and you want every pc on the network to have access to it, then add the following line /home/prash/test *(ro,async) . * stands for all.
Step 4 : Save the file with all changes and restart nfs server by typing sudo /etc/init.d/nfs-kernel-server restart at the terminal
THE GUI WAY :
Step 1 : This is a pretty easy way, very easy to figure out, right click on a Folder you want to share and click on Share Folder
Step 2 : Then Under Share Through select Unix Networks(NFS) .

Step 3 : Then click on Add , now if you want to specify a hostname or an ip address, you may do so, if you want all pcs on your network to access it, then just leave it blank.Under Host Settings Check or Uncheck Read Only depending on how you want it.

Step 4 : Click On OK . and restart NFS server by typing sudo /etc/init.d/nfs-kernel-server restart at the terminal.
CLIENT CONFIGURATION :
Step 1 : Now once your done with the sharing, you need to configure your client to connect to the shares, Now open your Terminal(Applications->Accessories->Terminal) on the client machine
Step 2 : And type sudo apt-get install portmap nfs-common to install the client
Step 3 : Now you can Mount the folder manually by typing in the commands manually in the terminal itself
Step 4 : Say you want to mount the /home/prash/test folder of the server machine in the /home/user/Desktop/share folder which is in the client machine.In that case, you first need to ensure that the share folder is created in the desktop.Then you type in the following command sudo mount x.x.x.x:/home/prash/test /home/user/Desktop/share .Here in this case x.x.x.x is the ip address or host name of the NFS Server machine
NOTE : To know the ip address of the NFS server machine , type ifconfig in the NFS server machine's terminal.You should typically see an output where there is an ip of the form 192.168.1.x or 192.168.0.x .That would be the NFS server machine's ip.
Now Incase you want your client machine to automatically mount the folder at startup so you dont have to type in the mount command always.Then Do the Following
Step 1 : In your terminal type sudo gedit /etc/fstab
Step 2 : The fstab file should now open in gedit
Step 3 : Now taking the above example in Step 4 , add the following line to the fstab file x.x.x.x:/home/prash/test /home/user/Desktop/share nfs rsize=8192,wsize=8192,timeo=14,intr . You obviously need to edit this line , depending on your situation
Step 4 : Now save this file and you should be good to go!!
NOTE : If you have a firewall installed , then you need to open the following ports 2049,111 and 32771
========================================================================
NFS configuration ubuntu
The Network File System is certainly one of the most widely used network services. Network file system (NFS) is based on the Remote procedure call which allows the client to automatically mount remote file systems and therefore transparently provide an access to it as if the file system is local.If you still have some questions after reading this article please try our new LinuxCareer Forum.
2. Scenario
In this scenario we are going to export the file system from the an IP address 10.1.1.50 ( NFS server ) host and mount it on an a host with an IP address 10.1.1.55 ( NFS Client ). Both NFS server and NFS client will be running Ubuntu Linux.3. Prerequisites
At this point, we assume that the NFS service daemon is already installed on your system, including portmap daemon on which NFS setup depends.If you have not done so yet simply install nfs-common package on both NFS client and NFS server using using apt-get tool.
# apt-get install nfs-commonThe command above will fetch and install all support files common to NFS client and NFS server including portmap.
Additionally we need to install extra package on our NFS server side.
apt-get install nfs-kernel-serverThis package is the actual NFS daemon listenning on both UDP and TCP 2049 ports.
Execute rpcinfo -p to check correctness of your NFS installation and to actually confirm that NFS server is indeed running and accepting calls on a port 2049:
# rpcinfo -p | grep nfs
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
Furthermore, before we start exporting and mounting NFS directories,
your system needs to actually support network file system. To check
whether your system supports NFS grep /proc/filesystems and search for
nfs.# cat /proc/filesystems | grep nfs nodev nfs nodev nfs4If you do not see any output it means that NFS is not supported or the NFS module have not been loaded into your kernel. To load NFS module execute:
# modprobe nfsWhen installed correctly, the NFS daemon should be now listening on both UDP and TCP 2049 port and portmap should be waiting for instructions on a port 111.
At this point you should have portmap listening on both NFS server and NFS client:
rpcinfo -p | grep portmap
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
4. Server export file
All directories we want to share over the network using NFS need to be defined on the server side of this communication and more specifically they need to be defind with /etc/exports file. In the next section you will see most common NFS exports:4.1. Most common exports options
Here are the most common NFS export techniques and options:| /home/nfs/ 10.1.1.55(rw,sync) | export /home/nfs directory for host with an IP address 10.1.1.55 with read, write permissions, and synchronized mode |
| /home/nfs/ 10.1.1.0/24(ro,sync) | export /home/nfs directory for network 10.1.1.0 with netmask 255.255.255.0 with read only permissions and synchronized mode |
| /home/nfs/ 10.1.1.55(rw,sync) 10.1.1.10(ro,sync) | export /home/nfs directory for host with IP 10.1.1.55with read, write permissions, synchronized mode, and also export /home/nfs directory for another host with an IP address 10.1.1.10 with read only permissions and synchronized mode |
| /home/nfs/ 10.1.1.55(rw,sync,no_root_squash) | export /home/nfs directory for host with an IP address 10.1.1.55with read, write permissions, synchronized mode and the remote root user will be treated as a root and will be able to change any file and directory. |
| /home/nfs/ *(ro,sync) | export /home/nfs directory for any host with read only permissions and synchronized mode |
| /home/nfs/ *.linuxcareer.com(ro,sync) | export /home/nfs directory for any host within linuxconfig.org domain with a read only permission and synchronized mode |
| /home/nfs/ foobar(rw,sync) | export /home/nfs directory for hostname foobar with read, write permissions and synchronized mode |
4.2. Edit exports file
Now that we have familiarized our selfs with some NFS's export options we can define our first NFS export. Open up your favorite text editor, for example, vim and edit /etc/exports file by adding a line /home/nfs/ *(ro,sync) which will export /home/nfs directory for any host with read only permissions. Instead of text editor you can simply insert your NFS export line into /etc/exports file using echo command:# echo '/home/nfs/ *(ro,sync)' > /etc/exports # tail -1 /etc/exports /home/nfs/ *(ro,sync)Be sure that the directory you are about to export by NFS exists. You can also create a file inside the /home/nfs directory which will help you troubleshoot once you mount /home/nfs/ remotely.
# touch /home/nfs/nfs-test-fileNOTE: The default behavior of NFS kernel daemon is to include additional option to your export line which is "no_subtree_check". Be aware of this fact when you attempt to configure your NFS exports further.
4.3. Restart NFS daemon
Once you have edited /etc/exports file you need to restart your NFS daemon to apply any changes. Depending on your Linux distribution the restarting procedure of NFS may differ. Ubuntu and Debian users:# /etc/init.d/nfs-kernel-server restartRedhat and Fedora users
# /etc/init.d/nfs restartIf you later decide to add more NFS exports to the /etc/exports file, you will need to either restart NFS daemon or run command exportfs:
# exportfs -ra
5. Mount remote file system on client
First we need to create a mount point:# mkdir /home/nfs_localIf you are sure that the NFS client and mount point are ready, you can run the mount command to mount exported NFS remote file system:
# mount 10.1.1.50:/home/nfs /home/nfs_localIn case that you need to specify a filesystem type you can do this by:
# mount -t nfs 10.1.1.50:/home/nfs /home/nfs_localYou may also get and an error message:
mount: mount to NFS server failed: timed out (retrying).This may mean that your server supports higher NFS version and therefore you need to pass one extra argument to your nfs client mount command. In this example we use nfs version 3:
# mount -t nfs -o nfsvers=3 10.1.1.50:/home/nfs /home/nfs_localIn any case now you should be able to access a remote /home/nfs directory locally on your NFS client.
# ls /home/nfs_local/ nfs-test-file # cd /home/nfs_local/ # ls nfs-test-file # touch test touch: cannot touch `test': Read-only file systemThe above output proves that a remote NFS export is mounted and that we can access it by navigating to a local /home/nfs_local/ directory. Please notice that the touch command reports that the filesystem is mounted as read-only which was exactly our intention.
6. Configure automount
To make this completely transparent to end users, you can automount the NFS file system every time a user boots a Linux system, or you can also use PAM modules to mount once a user logs in with a proper username and password. In this situation just edit /etc/fstab to mount system automatically during a system boot. You can use your favorite editor and create new line like this within /etc/fstab:10.1.1.50:/home/nfs /home/nfs_local/ nfs defaults 0 0as before you also use echo command to do that:
# echo "10.1.1.50:/home/nfs /home/nfs_local/ nfs defaults 0 0" >> /etc/fstab # tail -1 /etc/fstab 10.1.1.50:/home/nfs /home/nfs_local/ nfs defaults 0 0
7. Conclusion
The Network File System comes with tons of export options. What has been shown here, just barely scratches the surface of NFS. Please visit Linux NFS-HOWTO hosted by linux documentation project or NFS homepage for more details.8. Appendix A
Following section of this NFS tutorial is going to be devoted to RedHat and Fedora Linux systems which by default block all incoming traffic to a NFS server by engaging firewall using iptables rules. For this reason when the firewall is running on your NFS server, you might get this error when mounting NFS filesytem:mount.nfs: mount to NFS server '10.1.1.13' failed: System Error: No route to host.
This error message has nothing to do with your NFS configuration, all what needs to be done is either turn off the firewall or add iptables rules to allow traffic on portmap port 111, nfs port 2049 and random ports for other nfs services.
There are two solutions to this problem: easy solution is to turn off the firewall completely and the right solution to add appropriate iptables rules.
8.1. Turn off firewall on Redhat like systems:
The easiest solution is to just turn off the firewall. This will automatically grant access to the nfs daemon to anyone. I would suggest this solution only for testing purposes of your NFS configuration. Enter the following command to stop firewall and clean up all iptables rules:# service iptables stopNow when your NFS settings are correct you should be able to mount nfs filesystem from you client machine.
8.2. Add iptables rules to allow NFS communication
This is a more complex but right solution to the above problem. First we need to set static port for nfs services such as rquotad, mountd, statd, and lockd by editing /etc/sysconfig/nfs file. Add or uncomment following lines in your /etc/sysconfig/nfs file:LOCKD_TCPPORT=32803 LOCKD_UDPPORT=32769 MOUNTD_PORT=892 STATD_PORT=662Restart you NFSD daemon with following commands:
# /etc/init.d/nfs restart # /etc/init.d/nfslock restartUse rpcinfo command to confirm a validity of your new ports settings:
# rpcinfo -p localhost
The output should be similar to the one below:
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 999 rquotad
100011 2 udp 999 rquotad
100011 1 tcp 1002 rquotad
100011 2 tcp 1002 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 mountd
100024 1 udp 662 status
100024 1 tcp 662 status
Save your current iptables rules into iptables-rules-orig.txt :# iptables-save > iptables-rules-orig.txtCreate file called iptables-nfs-rules.txt with the following content:
*filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [2:200] :RH-Firewall-1-INPUT - [0:0] -A INPUT -j RH-Firewall-1-INPUT -A FORWARD -j RH-Firewall-1-INPUT -A RH-Firewall-1-INPUT -i lo -j ACCEPT -A RH-Firewall-1-INPUT -p icmp -m icmp --icmp-type any -j ACCEPT -A RH-Firewall-1-INPUT -p esp -j ACCEPT -A RH-Firewall-1-INPUT -p ah -j ACCEPT -A RH-Firewall-1-INPUT -d 224.0.0.251 -p udp -m udp --dport 5353 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2049 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 111 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m state --state NEW -m udp --dport 111 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m state --state NEW -m udp --dport 2049 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 32769 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m state --state NEW -m udp --dport 32769 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 32803 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m state --state NEW -m udp --dport 32803 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 662 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m state --state NEW -m udp --dport 662 -j ACCEPT -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 892 -j ACCEPT -A RH-Firewall-1-INPUT -p udp -m state --state NEW -m udp --dport 892 -j ACCEPT -A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited COMMITApply new rules with iptables-restore, where the single argument will be an iptables-nfs-rules.txt file:
NOTE: this will create a new set of iptables rules. If you have already defined some iptables rules previously, you may want to edit iptables-rules-orig.txt and use it with iptables-restore command instead.
# iptables-restore iptables-nfs-rules.txtSave these new rules, so you do not have to apply new rules for nfs daemon next time you restart your server:
# service iptables saveNow your server is ready to accept client nfs requests. Optionally, you may restart iptables rules / firewall with the following command:
# service iptables restart
=============================================
Setting up a Fedora NFS server
Setting up a Linux NFS (Network File System) server has never been anything challenging. However there are a few security issues worth having a look at: especiall the firewall-part of the business.In the following guide, we are going to have a look at a convenient way of creating an NFS server from behind Fedora’s built-in iptables firewall.
Setting up the NFS Configuration files
/etc/exports
The /etc/exports file is for storing information about your NFS shares: the name of the folder to share, the IP address(es) of hosts to access your share and the rights connected to your share.A typical /etc/exports file should look like this:
An exports file consists of 2 columns and at least 1 row./usr/local 192.168.0.1(ro) 192.168.0.2(ro) /home 192.168.0.1(rw) 192.168.0.2(rw)
Each row corresponds to a folder (a share, if you like), where the columns contain the settings to the folder of their row.
The first column contains the full path on the computer to the folder you wish to share, the second column is for the IP addresses of the hosts you are sharing to. The letters in brackets are for the privileges. For example, ro stands for “read only” and rw is for “read and write”. For further options, you might want to visit http://nfs.sourceforge.net/nfs-howto/ar01s03.html.
In the example, you are sharing your /usr/local and your /home folder to 192.168.0.1 and 192.168.0.2. Both machines have read-only privileges on the first, and read and write priviliges on the second folder.
/etc/hosts.deny
This file is for listing the hosts that are not allowed to access your shares. As the /etc/hosts.allow (see the next title) overwrites this file it is best to list all servers here. Enter the following to this file:With your /etc/hosts.deny set like this and without an /etc/hosts.allow, no machines are allowed to see your NFS shares.portmap:ALL lockd:ALL mountd:ALL rquotad:ALL statd:ALL
/etc/hosts.allow
To allow your machine(s) to access your NFS shares, add the following lines to your file, and replace the IPs with the IP(s) of your machine(s).If you have only one machine to grant access to, delete the comma and the numbers behind.portmap: 192.168.0.1 , 192.168.0.2 lockd: 192.168.0.1 , 192.168.0.2 rquotad: 192.168.0.1 , 192.168.0.2 mountd: 192.168.0.1 , 192.168.0.2 statd: 192.168.0.1 , 192.168.0.2
Setting up NFS to work from behind Fedora’s iptables firewall
/etc/sysconfig/nfs
This file controls the ports which NFS is going to use. Copy the following lines into the file. Doing so is not a security risk, as you are likely to be behind a router (if you want to use network file sharing), and this doesen’t (yet) mean opening the ports in the firewall.LOCKD_TCPPORT=48620 LOCKD_UDPPORT=48620 MOUNTD_PORT=48621 STATD_PORT=48622 RQUOTAD=no RQUOTAD_PORT=48623
Getting configuration files (tested on Fedora Core 5)
Download and save these configuration files to a tool folder in your home.- nfs_firewallopen (used to open your firewall for nfs and portmap ports)
- nfs_servicestart (used to start nfs services)
- nfstart (to execute the 2 scripts above)
- nfs_firewallclose (used to close your opened nfs and portmap ports)
- nfs_servicestop (used to stop nfs services)
- nfstop (to execute the 2 scripts above)
For setting up an NFS client, see http://nfs.sourceforge.net/nfs-howto/ar01s04.html.sh ~/tool/nfstart
==================================================================
Fedora Core DNS Server using BIND
Setting and configure
BIND as and Domain Name Sever (DNS) on Fedora Core Linux machine.
1. DNS (domain name system)
Correspondence of IP address and hostname
The /etc/hosts file example
# IP Address Hostname Alias
127.0.0.1 localhost
192.168.42.1 apple www
192.168.42.2 desk desk.domain.cxm
Installation of BIND
BIND (Berkeley Internet Name
Domain)
[root@tenouk ~]#
mount /mnt/cdrom
[root@tenouk ~]#
cd /mnt/cdrom/RedHat/RPMS
[root@tenouk ~]#
rpm –Uhv bind-9.2.0-8.i386.rpm
[root@tenouk ~]#
rpm –Uhv caching-nameserver-7.2.1.noarch.rpm
[root@tenouk ~]#
cd /
[root@tenouk ~]#
umount /dev/cdrom
Setting of client and server
edit the resolf.conf file to
enable the client or server to find the DSN server.
[root@tenouk ~]#
vi /etc/resolv.conf
search kimura.com
nameserver 10.10.0.235
Definition of IP address of DNS server which client uses
Setting the DNS server.
[root@tenouk ~]#
vi /etc/named.conf
// generated by named-bootconf.pl
options {
directory "/var/named";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;
};
//
// a caching only nameserver config
//
controls {
inet 127.0.0.1 allow { localhost; } keys { rndckey; };
};
zone "." IN {
type hint;
file "named.ca";
};
zone "localhost" IN {
type master;
file "localhost.zone";
allow-update { none; };
};
zone "0.0.127.in-addr.arpa" IN {
type master;
file "named.local";
allow-update { none; };
};
// The following code is added
zone "kimura.com" IN {
type master;
file "named.kimura.com";
allow-update { none; };
};
zone "0.10.10.in-addr.arpa" IN {
type master;
file "named.10.10.0";
allow-update { none; };
};
include "/etc/rndc.key";
[root@tenouk ~]#
cp /var/named/named.local /var/named/named.10.10.0
[root@tenouk ~]#
vi /var/named/named.10.10.0
$TTL 86400
@ IN SOA jmtist20.kimura.com. root.jmtist20.kimura.com. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS jmtist20.kimura.com.
235 IN PTR jmtist20.kimura.com.
236 IN PTR compaq.kimura.com.
[root@tenouk ~]#
cp /var/named/named.local /var/named/named.kimura.com
[root@tenouk ~]#
vi /var/named/named.kimura.com
$TTL 86400
@ IN SOA jmtist20.kimura.com. root.jmtist20.kimura.com. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS jmtist20.kimura.com
IN MX 10 jmtist20.kimura.com
jmtist20 IN A 10.10.0.235
compaq IN A 10.10.0.236
Start BIND service
Start, stop and restart the
named service.
[root@tenouk ~]#
/etc/rc.d/init.d/named start
[root@tenouk ~]#
/etc/rc.d/init.d/named stop
[root@tenouk ~]#
/etc/rc.d/init.d/named restart
or
[root@tenouk ~]#
/sbin/service named start
[root@tenouk ~]#
/sbin/service named stop
[root@tenouk ~]#
/sbin/service named restart
Setting automatic start for
named on runlavel 3 and runlevel 5..
[root@tenouk ~]#
/sbin/chkconfig --level
35 named on
Confirmation of automatic start.
[root@tenouk ~]#
/sbin/chkconfig --list named
Confirmation of bind.
Use the command example below
to test your DNS server functionality.
[root@tenouk ~]#
ping 10.10.0.235
[root@tenouk ~]#
ping 10.10.0.236
[root@tenouk ~]#
ping jmtist20
[root@tenouk ~]#
ping compaq
[root@tenouk ~]#
ping jmtist20.kimura.com
[root@tenouk ~]#
ping compaq.kimura.com
[root@tenouk ~]#
nslookup jmtist20.kimura.com
[root@tenouk ~]#
nslookup compaq.kimura.com
[root@tenouk ~]#
nslookup 10.10.0.235
[root@tenouk ~]#
nslookup 10.10.0.236
Note:
SOA - Start of authority
NS - Name server
A - Address record
PTR - Pointer record
MX - Mail exchanger
Keywords: configure dns, setup dns, setup bind, linux dns server, fedora core dns
server, setup dns server, fedora Bind server, fedora dns server.











No comments:
Post a Comment