HOWTO: Setting up STUNNEL in FreeBSD

Say, there is a newsserver which offers additional to port 119 a secure connection on port 563. You have an account with your username and password on that newsserver and you would like to use a newsreader which is unable to handle secure connections (e.g. Knode).

For safety reasons stunnel shall run with its own user and its own group. Further a local jail shall be used and a log file shall be created. The last thing we'll need here is the new created port number. In this example we'll use port "12345" and our name of the newsserver is "".

cd /usr/ports/security/stunnel
make install clean

Create stunnels own pid directory and set up name, group and flags:
cd /var/run
mkdir -p stunnel
chown stunnel:stunnel stunnel
chmod 0622 stunnel

Create stunnel configuration file: /usr/local/etc/stunnel/stunnel.conf and write into it:

; create local jail
chroot = /var/run/stunnel

; set own UID and GID
setuid = stunnel
setgid = stunnel

; some debugging stuff useful for troubleshooting
;;;; debug = 7
output = /var/log/stunnel.log

client = yes
;;;;foreground = yes    ; good for debugging
foreground = no     ; good for normal operation
pid = /  ; root directory is the local jail

; localhost listening on port 12345
accept = 12345
connect = ; nntps equals 563 in /etc/services

The following things may or may not be helpful for you. Because I had some problems in shutting down stunnel without creating a couple of zombies, I changed the init script in this way:

edit: /usr/local/etc/rc.d/stunnel
comment out: ${stunnel_pidfile="/var/run/${name}.pid"}
comment out: pidfile=${stunnel_pidfile}

Check out whether a stunnel-start/stop works:
/usr/local/etc/rc.d/stunnel forcestart
/usr/local/etc/rc.d/stunnel forcestop

Edit /etc/rc.conf and add:

The last thing to do is to configure the newsreader client (here Knode).

Port: 119
Username: <empty>
Password: <empty>

Server: localhost (or
Port: 12345
Username: <YourUserName>
Password: <YourPassWord>

stunnel is a powerful tool and there are much more applications possible than that simple newsreader configuration. For more information see . More advanced ideas using stunnel are appreciated.