Introduction to NFS configuration of Debian and UbuntuLinux
Source: Internet
Author: User
Article Title: Introduction to NFS configuration of Debian and UbuntuLinux. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux System management, kernel research, embedded systems, open source, and other basic classification NFS (Network File System) you can share directories of different hosts (different OS) over the network-you can mount directories of remote hosts through NFS to access these directories, just like accessing local directories!
Generally, nfs can be used to easily share unix-like systems. However, if you want to share a file between unix-like and windows systems, you have to use samba!
NFS runs on the basis of SUN's Remote Procedure Call (Remote Procedure Call). RPC defines a system-independent method for inter-process communication. Therefore, the NFS server can also be viewed as an RPC server.
Because NFS is an RPC service program, you must map the port before using it-set through portmap. For example, when an NFS client initiates an NFS service request, it must first obtain a port ). Therefore, it first obtains port number through portmap. (not only NFS, but portmap needs to be set before all RPC service programs are started)
Before starting the RPC service (such as NFS), you need to start the portmap service! (For more information about whether nfs and portmap exist in the current system, see the "NFS installation" section.
Several NFS-related files and commands
1./etc/exports
The access to the NFS volume is approved by exports, which enumerate several hostnames that have the right to access the file system on the NFS server.
2./sbin/exportfs
Maintain NFS resource sharing. You can use it to reset the/etc/exports shared directory, uninstall the NFS Server shared directory, or share it again.
3./usr/sbin/showmount
It is used on NFS Server, while showmount is mainly used on Client. Can I use showmount? Zookeeper NFS shared directory resources.
4./var/lib/nfs/xtab
NFS record document: You can view which clients are connected to the NFS host.
The following are not directly responsible for NFS. In fact, they are responsible for all RPC
5./etc/default/portmap
In fact, portmap maps all the RPC service ports. Its content is very simple (detailed later)
6./etc/hosts. deny
Set the host to reject the portmap service
7./etc/hosts. allow
Set the host that allows the portmap service
Install NFS
By default, the NFS server is not installed on Debian/Ubuntu. First, install the NFS service program:
$ Sudo apt-get install nfs-kernel-server
(When nfs-kernel-server is installed, apt will automatically install nfs-common and portmap)
In this way, the host is equivalent to the NFS Server.
Similarly, if the target system is an NFS client, you must install the NFS client program. For Debian/Ubuntu systems, you need to install nfs-common.
$ Sudo apt-get install nfs-commmon
Both nfs-common and nfs-kernel-server depend on portmap!
Configure NFS
NFS is an RPC server program. Portmap is used to map the port numbers of your RPC. Configure portmap first.
Configure portmap
Method 1: edit/etc/default/portmap and remove-I 127.0.0.1.
Method 2: $ sudo dpkg-reconfigure portmap, shocould portmap be bound to the loopback address? Select N.
Configure/etc/hosts. deny
(Prohibit any host (host) from connecting to your NFS server), add:
### NFS DAEMONS
Portmap: ALL
Lockd: ALL
Mountd: ALL
Rquotad: ALL
Statd: ALL
Configure/etc/hosts. allow
Allow hosts you want to establish connections with your NFS server. The following steps allow any host whose IP address starts with 192.168.2 (connected to the NFS server), or specify a specific IP address. See hosts_access (5) and hosts_options (5) on the man page ). Join:
### NFS DAEMONS
Portmap: 192.168.2.
Lockd: 192.168.2.
Rquotad: 192.168.2.
Mountd: 192.168.2.
Statd: 192.168.2.
/Etc/hosts. deny and/etc/hosts. allow set access to portmap. Using these two configuration files is a bit similar to "mask. Currently, all users are prohibited from accessing portmap in/etc/hosts. deny. Then, some users can access portmap in/etc/hosts. allow.
Run $ sudo/etc/init. d/portmap restart to restart portmap daemon.
Configure/etc/exports
The NFS mount directory and permissions are defined by the/etc/exports file.
For example, to share the IP address of 192.168.2. * In the/home/zp/share directory of my home directory, add the following statement at the end of the file:
192.168.2. * The NFS client in the network segment can share the contents of the NFS server/home/zp/share directory. The user has the read and write permissions, and the user's identity after entering the/home/zp/share directory is root
It is best to add sync. Otherwise, a warning will be given when $ sudo exportfs-r is used. sync is the default option of NFS.
Run $ showmount-e to view the NFS server's export list.
If/etc/exports is changed, run $ sudo exportfs-r update.
Run $ sudo/etc/init. d/nfs-kernel-server restart to restart the nfs service.
/Etc/exports is actually the core configuration file of the nfs server. Laruence's Linux private dish lists the writing methods of some exports files.
Test NFS
Try mounting the local disk (assuming the IP address of the local host is 192.128.2.1, Mount/home/zp/share to/mnt)
$ Sudo mount 192.168.2.1:/home/zp/share/mnt
Run $ df to check the result
$ Sudo umount/mnt
Note the read/write permissions of the copied file!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.