Accepted answer is correct for old versions of Ubuntu. But now I am using Ubuntu 22, and after trying this option (was working fine in my previous ubuntus on my raspberry pi) seems that is not valid any more.
According to this link.
the /etc/default/nfs-* files are ignored by the NFS server or client
in Ubuntu 22.04.
That means that the proposed solution of @Jar is not longer valid.
What must be done now, is editing /etc/nfs.conf
and according to this link. Update this config:
[mountd]
#port=0
Uncommenting the line #port=0
and replacing the port with the desired number (i.e. 13025 following the other examples).
[mountd]
port=13025
After this, restart the server:
systemctl restart nfs-serve
And ensure that the port 13025
now is correctly opened with rpcinfo -p
giving and output such as:
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100005 1 udp 13025 mountd
100005 1 tcp 13025 mountd
100005 2 udp 13025 mountd
100005 2 tcp 13025 mountd
100005 3 udp 13025 mountd
100005 3 tcp 13025 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
Now must work as expected. Obviusly, remeber to open your firewall to the ports 2049
, 111
, 13025
. As explained on the previous answers:
ufw allow from 192.168.1.0/24 to any port 111
ufw allow from 192.168.1.0/24 to any port 2049
ufw allow from 192.168.1.0/24 to any port 13025