Monday, April 18, 2016

How to Setup NFS share in Linux

NFS or Network File System is a very convenient way of allowing the data on one Linux host to be accessible on another. The procedure for setting up a NFS share and accessing the same on a client is very simple.

Step 1: Install the nfs utilities and rpcbind (portmap) on the source host.

]# yum install nfs-utils nfs-utils-lib

Step 2: Create a file /etc/exports and enter the following information.

/tmp *(rw,sync,no_root_squash)

In the line above:

/tmp           - The folder to be shared
*              - Allow access to all clients
rw             - Provide read/write access
sync           - The requests are honored only after changes are committed
no_root_squash - Allow root user to access the share

Step 3: Make sure nfs and rpcbind services start at boot. Export the list of shared folders and start these services now.

]# chkconfig rpcbind on
]# chkconfig nfs on

]# exportfs -rv

]# service rpcbind restart
]# service nfs restart

Step 4: To see the list of nfs exports, run:

]# showmount -e localhost

To see the same list from a different host, run:

]# showmount -e <ip address/hostname>

Step 5: Mount and access the contents:

]# mount -t nfs <ipaddress/hostname>:/tmp /mnt/share

How to use wget to Download all files in Linux

wget on Linux is a very useful tool to download files from the web. In its default use, one can download individual files from a directory on the web. However, downloading all files form a HTTP directory may be achieved using the following command.

]# wget -r -nH -nd -np -R index.html* http://example.com/directory/

The arguments in the command above have the following meanigns:

     -r   Recursive download
    -nH   This prevents the creation of directory structure as on the host
    -nH   This ensures that all files are saved in the current direcotry
    -nH   Don't download parent folder when -r option is given
    -nH   Reject list, exclude these file(s) from the download