概述:目前使用openwrt系统的路由方案,现在实现路由器下设备可以挂载路由器的nfs共享目录,并且实现在同一个交换机下的设备和路由器,设备可以挂载路由器的nfs共享目录(跨网段挂载)。
具体实现方案:
1,编译内核时,开放nfs功能
内核开放nfs功能,这个就不细讲太多,主要就是make menuconfig下配置文件系统中的网络文件系统下,打开nfs server相应功能编译到内核。然后烧写固件到设备路由器。
2,安装nfs-kernel-server
opkg install nfs-kernel-server
3,配置共享挂载目录
在/etc/exports 设置共享挂载目录及权限等配置。如:
/tmp *(rw,fsid=0,no_subtree_check,no_root_squash,insecure,sync)
保存退出,重启nfs服务
/etc/init.d/nfsd restart
这时,在路由器下的设备,我们使用mount命令挂载我们设置的共享目录
sudo mount -t nfs -o nolock 192.168.80.1:/tmp /mnt
这时发现在路由器下的设备,已经可以成功挂载。 然后我们和路由器同级的同一个交换机下的设备去挂载路由器的共享目录,发现挂载失败。
4,配置firewll文件,即防火墙文件(openwrt系统自己专用的),开放端口和端口映射。
通过官网资料:官网资料链接
The portmap service uses port 111 on both TCP and UDP, nfsd standard are ports between 32777 and 32780 on both TCP and UDP.
可以知道portmap为固定端口111,nfsd服务标准端口在32777-32780之间,如rpc.mountd rpc.statd 等。
在/etc/services文件中我们可以找到nfs为固定端口2049
由以上资料我们可以知道,nfs服务总共需要用到的端口为111 2049 32777 32778 32779 32780 这六个端口。
因此我们在防火墙中开放这几个端口,官网示例:
在/etc/config/firewall文件中添加如下内容:
config rule
option src wan
option dest_port 2049
option target ACCEPT
option proto tcpudp
config rule
option src wan
option dest_port 111
option target ACCEPT
option proto tcpudp
config rule
option src wan
option dest_port 32777
option target ACCEPT
option proto tcpudp
config rule
option src wan
option dest_port 32778
option target ACCEPT
option proto tcpudp
config rule
option src wan
option dest_port 32779
option target ACCEPT
option proto tcpudp
config rule
option src wan
option dest_port 32780
option target ACCEPT
option proto tcpudp
在防火墙中映射这六个端口:
官网示例:
在/etc/config/firewall文件中添加如下内容:
config redirect
option src wan
option src_dport 2049
option dest lan
option dest_port 2049
option proto tcpudp
option target DNAT
config redirect
option src wan
option src_dport 111
option dest lan
option dest_port 111
option proto tcpudp
option target DNAT
config redirect
option src wan
option src_dport 32777
option dest lan
option dest_port 32777
option proto tcpudp
option target DNAT
config redirect
option src wan
option src_dport 32778
option dest lan
option dest_port 32778
option proto tcpudp
option target DNAT
config redirect
option src wan
option src_dport 32779
option dest lan
option dest_port 32779
option proto tcpudp
option target DNAT
config redirect
option src wan
option src_dport 32780
option dest lan
option dest_port 32780
option proto tcpudp
option target DNAT
配置修改好,保存设置,重新启动firewall
$ /etc/init.d/firewall restart
10网段交换机下设备挂载交换机下路由器nfs共享目录。
这里挂载,因为路由器lan口ip为192.168.80.1,这里我们挂载要使用wan口ip挂载
$ sudo mount -t nfs -o nolock 192.168.10.12:/tmp /mnt
此时,发现交换机下设备挂载路由器共享目录成功。