Tool-BarfreeBSD ArticlesSearch Our SiteHOMEfreeBSD LinksContribute to FreeBSD HelpFreeBSD FilesFreeBSD Script Corner

What happened to rc.local in FreeBSD

    • Are you wondering where apache or other ports are starting from?
    • Are you wondering where to put your custom startup commands?
    • Are you wondering the fastest way to configure some common FreeBSD features?

    Look no further than /etc/rc.conf or /usr/local/etc/rc.d.


If you're used to just being able to add lines to a file called /etc/rc.local and have them execute at boot-up then you're probably wondering what happened to it in FreeBSD. Well, it's been replaced by a directory called /usr/local/etc/rc.d - The /etc/rc startup script file searches this directory for .sh files (shell scripts) and executes them.

If you're running any ports like apache, mysql or openssh, you'll notice their .sh files in this directory. This is also where you would put any custom scripts that you want run at boot up. Simply create a shell script with a .sh extension and save it in /usr/local/etc/rc.d.

Here's what /etc/rc does:

echo -n 'Local package initialization:'
    for dir in ${local_startup}; do 
        if [ -d "${dir}" ]; then
            for script in ${dir}/*.sh; do
                if [ -x "${script}" ]; then
                    (set -T
                     trap 'exit 1' 2
                     ${script} start)

Where does it get ${local_startup} from? It gets it from rc.conf of course, see below.


There are many features that FreeBSD includes that are enabled simply by adding a line to one file.

The /etc/defaults/rc.conf file contains a list of variables and their values. Some of these variables include:

  • hostname - To set your hostname.
  • natd_enable - To enable natd.
  • ifconfig_interface - To set your TCP/IP settings on your network interface
  • named_enable - To enable DNS
  • sshd_enable - To enable the ssh server
  • static_routes - To enter static routes
  • ppp_enable - To enable PPP
  • local_startup - To define startup script directory (see above)
  • See the file and "man rc.conf" for many more options

 If you want to over-ride any of the values in this file, you need to create a file called /etc/rc.conf with your desired values. This file is *usually* created during FreeBSD's install and contain the ifconfig and hostname settings that you specify initially. Any additions you make to your over-ride file will take affect on the next reboot.

 It is actually the /etc/rc file that does all of the work. In the case of /usr/local/etc/rc.d it looks for the "local_startup" directory in rc.conf and runs any .sh files in that directory. For all of the above variables (and a lot more), rc searches the rc.conf files for the approriate values and acts upon them. It calls, rc.firewall, rc.i386 and a couple others to accomplish this. Here's an example with named (DNS) server. In your rc.conf file, you set the following values:


named_enable="YES"        # Run named, the DNS server (or NO).
named_program="named"       # path to named, if you want a different one.
named_flags="-q"         # Flags for named

On boot-up, the /etc/rc file calls /etc/, which runs the following:


case ${named_enable} in
        echo -n ' named';    ${named_program:-named} ${named_flags}

 As you can see, the script deterimines if you want to run named (if named_enable="YES"). It then executes whatever is in named_program (named by default) with named_flags as its flags (options). So, using our variables above, it would execute:


named -q

 Seems a little cumbersome just to execute a simple command, huh? Well if you think about how scalable and structured this feature is, you'll realize how simple it makes things. The rc files take care of the details for you.

More information on these files can be found in the appropriate man pages.


© 1997 - 20013 Defcon1, , Copyrights for all materials on this web site are held by the individual authors, artists, photographers or creators. Materials may not be reproduced or otherwise distributed without permission of and the content's original author.

Tool-Bar-2Defcon1  Webmail