These two days in the building of an embedded development environment, After configuring the NFS server, encountered a very tangle of errors using mount-tnfs127.0.0.1: homelzgonlinerootfsmnt and mount-tnfs192.168.1.9: homelzgonlinerootfsmnt native mount nfs is no problem, however using mount-tnfs192.168.3.12
These two days, after setting up an embedded development environment and configuring the NFS server, I encountered a very tangled error using mount-t nfs 127.0.0.1: /home/lzgonline/rootfs/mnt and mount-t nfs 192.168.1.9:/home/lzgonline/rootfs/mnt no problem in local nfs mounting. However, mount-t nfs 192.168.3.12
These two days, after setting up an embedded development environment and configuring the NFS server, I encountered a very tangled error.
Mount-t nfs 127.0.0.1:/home/lzgonline/rootfs/mnt and mount-t nfs 192.168.1.9:/home/lzgonline/rootfs/mnt on the local machine, however, when mount-t nfs 192.168.3.12:/home/lzgonline/rootfs/mnt is used, the Development Board cannot be started through nfs mounting, of which 192.128.3.12 and 192.128.1.9 (nfs server) A dming (DMZ) relationship is established between them.
Mount. nfs: access denied by server while mounting 192.168.3.12:/home/lzgonline/rootfs
Baidu and Google have been around for a long time. Most of them say that permission settings are incorrect. In fact, folder permissions are set to 777, and permissions are okay, hosts. deny and hosts. allow retains the default settings, and the firewall is also disabled. All the settings are set, but they are still rejected. It is very depressing and cannot be resolved, after viewing some linux technical forums, I found the problem.
First, run the command to view the error log file.
[Root @ lzgonline init. d] # cat/var/log/messages | grep mount
Jun 29 00:49:04 lzgonline mountd [1644]: refused mount request from 192.168.3.12 for/home/lzgonline/rootfs (/home/lzgonline/rootfs): illegal port 1689
Jun 29 00:51:02 lzgonline mountd [1644]: refused mount request from 192.168.3.12 for/home/lzgonline/rootfs (/home/lzgonline/rootfs): illegal port 1710
Jun 29 01:02:17 lzgonline mountd [1644]: refused mount request from 192.168.3.12 for/home/lzgonline/rootfs (/home/lzgonline/rootfs): illegal port 1916
Jun 29 01:09:51 lzgonline mountd [1644]: refused mount request from 192.168.3.12 for/home/lzgonline/rootfs (/home/lzgonline/rootfs): illegal port 2157
Jun 29 01:17:02 lzgonline mountd [1644]: refused mount request from 192.168.3.12 for/home/lzgonline/rootfs (/home/lzgonline/rootfs): illegal port 2318
The error log shows that mount. nfs: access denied by server while mounting 192.168.3.12:/home/lzgonline/rootfs is denied because an invalid port is used, finally, I found the answer on a linux technology forum:
I googled and found that since the port is over 1024 I needed to add the "insecure" option to the relevant line in/etc/exports on the server. once I did that (and ran exportfs-r), the mount-a on the client worked.
// If the port number is greater than 1024, you must add the insecure option to the mount client in the options related to the configuration file (/etc/exports:
Check the description of the secure option in the exports manual.
[Root @ lzgonline init. d] # man exports
Secure, This option requires that requests originate on an Internet port less than IPPORT_RESERVED (1024). This option is on by default. To turn it off, specify insecure.
// The secure option requires that the mount client request source port be smaller than 1024 (however, the port is usually greater than 1024 when NAT network address translation is used). This option is enabled by default, if you want to disable this option, use the insecure identifier
Modify the configuration file/etc/exports and add the insecure option.
/Home/lzgonline/rootfs * (insecure, rw, async, no_root_squash)
Save and exit
Then restart the nfs service: service nfs restart
Then the problem is solved.
**************************************** **************************************** **
NFS server configuration
I. NFS server configuration, that is, shared publisher
(1) services to be started and software to be installed
1. the NFS server must start two daemons services: rpc. nfsd and rpc. mountd.
Rpc. nfsd: used to manage whether the client PC can log on. Similar to share permissions in windows.
Rpc. mountd: used to manage the file security permissions that can be used by the client pc. For example, share security permissions in windows.
RPC: Because NFS supports many functions, the ports corresponding to NFS functions cannot be fixed. Instead, random ports smaller than 1024 are used.
However, the client must know the port of the server before it can be connected. In this case, the RPC service must be enabled.
The RPC function specifies the port number of each NFS function. And send the information to the client so that the client can connect to the correct port.
When the server starts NFS, it randomly accesses several ports and actively registers with RPC. Therefore, RPC knows the port corresponding to each NFS function.
RPC listens to client requests with port 111 and responds to the correct port. Before starting NFS, RPC must be started first. Otherwise, NFS cannot register with RPC.
2. the NFS server needs to install the nfs main program, nfs-utils and rpc main program portmap.
(2) method of exports Server:
1. NFS file access permission
Because NFS does not have a verification mechanism, client users may encounter permissions when accessing the shared folder on the NFS server:
(1) When the NFS server user list contains the same user name as the client user name, the client can directly access the shared folder. For example, if the client user is khp and the user list of the nfs server (/etc/passwd) also has the user name khp, the user will have the KHP permission ..
(2) When the UID of the client accessing the NFS server is the same as that of the server, but the user name is different, the client will have the same but different user permissions as the server UID.
For example, if the client is 501UID and the user name is khp, access the NFS server. In the NFS server user list (/etc/passwd), if the uid is 501 but the user name is pla, the client khp user can have the same ACL as the NFS server pla.
(3) If the client user UID does not exist in the user list on the NFS server, access the NFS server with anonymous user permissions. That is, the user of nobody.
(4) If the client user is the root user, because each computer has a root user, if not controlled, the NFS server will be very dangerous and will be fully controlled by the client. Therefore, by default, the client with the root user name accesses the NFS server and becomes an anonymous user with the anonymous user permission. Or not.
2. Edit the/etc/exports file. The file does not exist. If it does not exist, create it manually.
/Etc/exports format:
Computers allowed to access the shared directory (option)
Shared Directory: the shared Directory prepared by the nfs server
Computers allowed to access: Which of the following clients are allowed to access the shared client. The available computer name and IP address can also use wildcards.
Option:
(1) rw // read/write. The client has read and write permissions.
(2) The ro // read-only client has only the read permission.
(3) no_root_squash // the root user can access the resources shared by the NFS server without being an anonymous user.
(4) root_squash // the root user becomes an anonymous user.
(5) all_squash // All users become anonymous users
(6) anonuid
(7) anongid // The UID or group ID of all anonymous users is changed to the UID or GID permission set later. All users without a username in the NFS server user list will be anonymous users. Here, the user permissions of these anonymous users are set.
(8) sync // synchronize to the hard disk
(9) async // store data in the memory instead of writing directly to the hard disk
Example:/mnt/export www.elitek.com (rw) // This directory only allows reading and writing on www.elitek.com. Note that there is no space before (rw.
/Mnt/export www.elitek.com (rw) // mnt/export this directory only allows reading and writing on www.elitek.com and allows all other users to read and write. (Rw) there is a space in front.
/Mnt/export * .elitek.com (rw) // allow all computers in the elitek.com domain to read and write the shared folder.
3. exportfs command. You can change the settings (command directory/usr/sbin/exportfs)
Exportfs [-avu] [-o option] [director]
-A: Share all paths in exprotfs.
-U: cancels the export outbound path.
-V: Shared display to the screen during export
-O option: some options
-R: Remount the settings in exports.
For example, exportfs-a ro/tmp/user // stores all exports in the/tmp/user directory, but the user can only read data.
4./var/lib/nfs/* tab // store the log file. etab records the complete permission settings for the directories shared by NFS. . Xtab records the client data that has been connected to NFS
5. rpcinfo [-p] [ip | computer name] // view the registration status of the RPC service
6. Run netstat-ultn to check which ports are open.
Ii. client-side settings
As an NFS client, you must first run the nfslock and portmap services. /Etc/init. d/nsflock start
/Etc/init. d/portmap start
There are several Mount Methods
(1) command Method
Mount command mounting
1. showmount-e [nfs server computer name | IP address] // view the available shared directory of the nfs server
2. mount nfs Host Name: mount the nfs shared directory to the local directory // mount the directory shared by the nfs server to the local directory. Available IP addresses besides the Host Name
For example, mount 192.168.9.1:/tmp/export // to mount the/tmp/export directory shared by the 192.168.9.1nfs server to the/tmp/export directory of the local machine.
Mount-t nfs-o time = 20 www.linux.com/home/khp/tmp/export // mount the remote nfs server/home/khp to the local/tmp/export directory. The maximum response time is 20 seconds.
3. The unmount command interrupts mounting.
(2) edit/etc/fstab file mounting
/Etc/fstab file details are described in File System Management
1. Format: NFS server and shared directory mount to local directory file format Option
Www.elitek.com:/home/project/tmp/export ro // mount the/home/project directory on the NFS server of www.elitek.com to the/tmp/export directory on the local machine, and read-only. Format: nfs
2. Open the folder. Enter mount/tmp/export to open the mounted file.
(3) mount the nfs file system using autofs
It is mounted only when the file system is accessed.
1. Define the mount point in/etc/auto. master.
2. Then, define the total mount point of the directory in/etc/auto. dirctory defined in auto. master.
That is, a total mount point is defined in the system file/etc/auto. master. Then, set the detailed mount point according to the total mount point file defined in this file.
For example, edit the file vi/etc/auto. master:
/Misc/etc/auto. khp-timeout 60 // that is, the files in/etc/auto. khp will be mounted to the/misc directory.
Edit the file vi/etc/auto. khp to define the mount point.
Myproject-rw, soft, intr www.elitek.com:/home/project // mount the shared directory of the NFS server www.elitek.com:/home/project to the/misc/myproject directory of the local machine.
Note: The/misc/myproject directory is dynamic, not actually exists, but is generated only during access. If you exit, the message is sent. However, the/misc directory must exist.
When the firewall is on, it is sometimes inaccessible. You can use/etc/rc. d/init. d/iptables stop to stop the firewall, or use the iptable command to open the NFS port.