Tutorial 05 · FreeBSD

rc.conf and managing services

Enable, start, stop and configure services the FreeBSD way with sysrc and service.

Last updated

FreeBSD services are shell scripts in /etc/rc.d (base system) and /usr/local/etc/rc.d (packages). Whether they start at boot, and with what settings, is controlled by variables in /etc/rc.conf.

1Edit rc.conf safely with sysrc

You can edit /etc/rc.conf by hand, but sysrc avoids typos and duplicates.

sysrc sshd_enable=YES          # set
sysrc sshd_enable              # show
sysrc -a                       # show everything that's set
sysrc -x powerd_enable         # remove a setting
sysrc -c sshd_enable=YES && echo already set

2Start, stop and inspect services

service sshd start
service sshd stop
service sshd restart
service sshd reload
service sshd status
service -e        # list services enabled at boot
service -l        # list all available services

If a service isn't enabled in rc.conf, start refuses to run it. Use the one prefix to run it just this once:

service ntpd onestart
service ntpd onestatus

3Enable and disable shortcuts

service ntpd enable     # same as sysrc ntpd_enable=YES
service ntpd disable

4Find a service's options

Each rc script documents its variables at the top. The base defaults live in /etc/defaults/rc.conf; never edit that file, override in /etc/rc.conf instead.

less /usr/local/etc/rc.d/sshguard
grep ^ntpd /etc/defaults/rc.conf
sysrc ntpd_flags="-g"

5Package settings and load order

Larger configurations can be split into /etc/rc.conf.d/<service> files, which sysrc can target with -f. Boot order is worked out automatically from each script's PROVIDE/REQUIRE lines; rcorder shows the result.

sysrc -f /etc/rc.conf.d/ntpd ntpd_enable=YES
rcorder /etc/rc.d/* /usr/local/etc/rc.d/* | less

← All FreeBSD tutorials