According to this blog post, it should be easy:
# nbd-server MyFile.dat
# nbd-client localhost /dev/nbd0
Trouble is... that doesn't actually work.
First of all, nbd-server whinges and whines about "no configured exports", unless I explicitly specify a port number and the absolute path to the file. But OK, whatever. (It still complains that this is "deprecated" somehow and that you should really edit the config file instead — which I definitely don't want to do!) It appears to now be serving the block device. (At least, there's now an nbd-server process running, which has TCP/10809 open for listening.)
Trying to get nbd-client to connect, however, is impossible. No matter what arguments I give it, it moans and complains and refuses to do anything! It keeps saying
ERROR: not enough information specified
followed by the usage synopsis. But it won't actually tell me what it's unhappy about. Either with or without a port number specified, I get the same error message. How do I make it actually connect?
(Obviously I'm connecting to the same machine. Eventually I want to do this between machines on the network. But I can't even get it to work locally yet!)
PS. Some examples talk about modprobe nbd-client and modprobe nbd-server. My OpenSUSE machine appears to only have nbd.ko, so I've inserted that. Before that, /dev/nbd0 doesn't even exist. After that, it exists just fine.