I have a system which contains a number of raspberry pi's, one of which is a 'master' which must export an nfs to a number of 'slave' devices in the system.

The system will be connected to the end users network; the end user will be able to specify an ip subnet range on which the pi's must communicate.

To cut down on setup complexity for the end user, is it possible to specify in /etc/exports to share with only the local ip address of the pi?

Something like:

/home      local-ip/

To be clear: If the end user sets the ip of the pi's to be in the 10.0.1.x range or the 192.168.5.x range, is it possible for exports to automatically use this range without modifying /etc/exports? I don't want to export to all ip's.

Other info: The user has no communication with the system while in use. The SD card for the pi has a small FAT partition which the end user can mount in a windows computer and modify an interfaces file which is sourced by /etc/network/interfaces to allow them to change the ip. The /etc/exports does not appear to support sourcing from another file.


You are right, /etc/exports can not be sourced by conventional methods - you can however script the contents of the file:

ip_info=$(ip a | grep inet | grep -v "" | cut -d " " -f 6)
range=$(echo $ip_info | sed 's/\.[0-9]\+\//\.0\//g')
echo "/home/              $range(ro)" > /etc/exports
/etc/init.d/nfs-kernel-server restart

Place that with your favorite editor in /root/set_nfs_exports.sh and make it executable

chmod +x /root/set_nfs_exports.sh

and have it executed after the network interface comes up

ln -s /root/set_nfs_exports.sh /etc/network/if-up.d/export-nfs

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.