I had the same issue with the error as this and this question (both of which I read and understood), the message being:
$ ulimit -n 20000
ulimit: bad limit: Operation not permitted
I encountered this issue on FreeBSD 8.3 after an upgrade from 7.3 and thought it may have had something to do with the upgrade.
I also had all sorts of issues running the command as root and could only run it as a standard user - which is what I wanted in any case.
The issue is that with FreeBSD the command is limit, not ulimit.
When I ran as a normal user:
%limits -n 20000
I got the exact result I wanted which was to increase the openfile limit from 11095 to 20000, or so I thought.
The output was:
Resource limits (current):
openfiles 20000
However when I ran the limit command again the limit is shown back at 11095.
How do I change either the hard/soft limit on a FreeBSD 8.3 box?