Hi, since kernel 2.6 there's a neat way of setting the ports used by lockd/nlockmgr. /etc/conf.d/nfs could define two values: RPCLOCKD_UDPPORT=0 RPCLOCKD_TCPPORT=0 where 0 is the default, which makes the kernel allocate a dynamic port. the values can eb set by simply using two sysctl-commands: sysctl -w fs.nfs.nlm_udpport=$RPCLOCKD_UDPPORT sysctl -w fs.nfs.nlm_tcpport=$RPCLOCKD_TCPPORT This must be executed after loading the nfsd module (which is currently not done by any /etc/init.d/nfs-script, see Bug 64709) and before starting any servers. Since these values don't exist until the nfsd-module it loaded, this cannot be done /etc/sysctl.conf. On the other hand, the other ports are also defined in /etc/conf.d/nfs, so why don't configure the lockd-ports there too. Having static ports is very important for firewalled systems. Reproducible: Always Steps to Reproduce:
Here's a patch, although it doesn't check for the kernel-version yet: # diff -u nfs-5 /etc/init.d/nfs --- nfs-5 2004-07-15 02:06:24.000000000 +0200 +++ /etc/init.d/nfs 2004-10-07 00:31:02.944810936 +0200 @@ -64,6 +64,11 @@ } start() { + modprobe nfsd >/dev/null 2>&1 + + sysctl -q -w fs.nfs.nlm_udpport=$RPCLOCKD_UDP + sysctl -q -w fs.nfs.nlm_tcpport=$RPCLOCKD_TCP + # This is the new "kernel 2.6 way" to handle the exports file if grep -q nfsd /proc/filesystems &>/dev/null; then if ! grep -q "nfsd /proc/fs/nfs" /proc/mounts &>/dev/null; then
here's a much better test, that checks if the kernel has support for the sysctl-values: # diff -u nfs-5 /etc/init.d/nfs --- nfs-5 2004-07-15 02:06:24.000000000 +0200 +++ /etc/init.d/nfs 2004-10-07 00:48:08.467907728 +0200 @@ -63,7 +63,24 @@ wait $1 } +set_lockd_port() { + local type="$1" + local port="$2" + + if sysctl "fs.nfs.nlm_${type}port" >/dev/null 2>&1 + then + ebegin "Setting lockd $type-port" + sysctl -q -w "fs.nfs.nlm_${type}port=$port" + eend $? "Your kernel doesn't support this" + fi +} + start() { + modprobe nfsd >/dev/null 2>&1 + + set_lockd_port udp "$RPCLOCKD_UDP" + set_lockd_port tcp "$RPCLOCKD_TCP" + # This is the new "kernel 2.6 way" to handle the exports file if grep -q nfsd /proc/filesystems &>/dev/null; then if ! grep -q "nfsd /proc/fs/nfs" /proc/mounts &>/dev/null; then
i dont understand why you dont put your nfs module into modules.autoload and then put those settings into your sysctl.conf
@vapier: This is something that doesn't have to be done, but it's a great service for gentoo-admins. I also think, that there's no better place to this, than /etc/init.d/nfs: - /etc/init.d/local is started after /etc/init.d/nfs, and it the lockd has already been, the sysctl-stuff has no effect, and so /etc/conf.d/local.start is the wrong place - /etc/sysctl.conf is used by /etc/init.d/bootmisc. That doesn't depend on /etc/init.d/modules, and therefor the nsfd-module isn't loaded, and so the sysctl-command in /etc/init.d/bootmisc will fail, since the setting aren't available yet, since the nfsd module hasn't been loaded yet - with the ports set in /etc/init.d/nfs and changed ports in /etc/conf.d/nfs, /etc/init.d/nfs restart should also correctly set the port-numbers and they will even be used, by the just restarted lockd/nlockmgr.
bootmisc needs localmount which needs checkfs which needs modules so if you have nfsd in your modules.autoload, everything will work correctly
OK, i agree, but still, many users don't know that those sysctl-paramters exist, and it took me an hour googling, and having the ports in /etc/conf.d/nfs would be a thing, where an admin will find them within seconds ...
or, how about i add some comments to the top of the conf.d/nfs file explaining that if they wish to set the ports, they should make sure nfsd is built into the kernel/in modules.autoload and they should update /etc/sysctl.conf
Oh well, put some hints in /etc/conf.d/nfs about sysctl.conf and modules.autoload.d and close this bug. Admins who want to change the ports will look into /etc/conf.d/nfs and therefor find the hints, although this is the minimum of userfriendlyness ;-)
added not to conf.d file in cvs
*** Bug 124889 has been marked as a duplicate of this bug. ***
/etc/conf.d/nfs # If you wish to set the port numbers for lockd, # please see /etc/sysctl.conf ... /etc/sysctl.conf ... # TCP Port for lock manager # fs.nfs.nlm_tcpport = 32768 # UDP Port for lock manager # fs.nfs.nlm_udpport = 32768 above didn't mention anything about put nfsd in modules.autoload
*** Bug 124882 has been marked as a duplicate of this bug. ***
added a note even though that seems kind of obvious to me :P