If you are weird like me you might for some incomprehensible reason need/want/require to have Samba running on your PFSense box but how to go about it?, there’s no default PFSense package for Samba so you would have to do it manually. Well, I found a way.

I was working on setting up a new lab environment on my ESXi box so I could start playing around with Ruby on Rails/Node.js when my ADD kicked in and I got this weird notion to have all my machines show up in the network tab on my Windows workstation (don’t ask), after I got basic Samba running on all my linux boxes I turned my attention to my two PFSense boxes and started pondering if I should put Samba on them as well and after pondering for a whole minute I went fuck it .. why not.  So, here’s how I got Samba 3.6 running on PFSense.

First things first .. don’t be an idiot and take a backup of your config and do this first on a machine that you can fuck around on (no! don’t fuck around on the company pfsense router). Also don’t come crying to me if you fuck something up, I don’t actively monitor this blog so there might be weeks until I bother checking up on the comments and even then I might just ignore the “omg something broke help me!” comments.  If something breaks show a little initiative and Google the problem.

Now, shall we begin.  First go to the shell on the box, either on the console or via ssh, and give these two commands. (exchange i386 for amd64 if you are running 64-bit version)

setenv PACKAGESITE "ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.3-release/Latest/"
pkg_add -r samba36

The first command sets an environmental variable called PACKAGESITE .. no wait, why am I trying to explain what I’m doing. If you are fucking around with PFSense, let alone trying to install something as god awful as Samba on a bloody PFSense box, you should have enough proficiency in Linux/FreeBSD as to know what the basic commands/concepts I use/refer to are. If you don’t understand what I’m doing then for all that is holy reconsider your need to have Samba running on your PFSense box.

That pkg_add command can take few minutes, grab some coffee or tea.  Now, is that finished?.. good.  Then you can start to edit the smb.conf file (/usr/local/etc/smb.conf) and make whatever changes you need. You can do this on the command line via vi or you can do it in the GUI via the Diagnostics->Edit File utility.  Since all I wanted was for the machine to show up in the network list I only changed the workgroup, server string, disabled the printers, disabled all the default shares and added two lines to the default config file:

   netbios name = my-pfsense-box
   map to guest = bad user

After you are done making the changes you require to smb.conf you need to edit /etc/rc.conf.local or create it if it doesn’t exist and add the following to it :

samba_enable="YES"
nmbd_enable="YES"
smbd_enable="YES"
winbindd_enable="YES"

I ran into a bug in the default startup script which makes Samba fail to start after a reboot,  the problem is that Samba tries to create the PID files in a directory which doesn’t exist (more specifically the /var/run/samba directory). Since afaik the /var/run directory is cleaned during shutdown so that samba folder isn’t present at startup which makes the PID file creation to fail.  There are two ways to fix this, either edit the samba startup script and change the “pidfile=”/var/run/samba/${name}${pid_extra}.pid” lines to use a valid path or you can simply create the samba directory during boot and preserve the original startup script.  If you want to create the samba directory then you only need to edit the XML config and add a single line.  So for the lazy : open up /cf/conf/config.xml in the Diagnostic-Edit File (or with vi) and add “<shellcmd>mkdir /var/run/samba</shellcmd>” to the bottom of the system section so it becomes something like this :

...
		<dnsallowoverride/>
		<shellcmd>mkdir /var/run/samba</shellcmd>
	</system>
	<interfaces>
        ...

And thus the PID files can be created successfully.  Lastly we need to copy the startup script to samba.sh with the following shell command for it to start normally during boot:

cp /usr/local/etc/rc.d/samba /usr/local/etc/rc.d/samba.sh

And that’s all. You can try to reboot the box to see if Samba starts automatically.  If you don’t want to/can’t reboot the server at the moment you can start samba manually with the following command :

/usr/local/etc/rc.d/samba start

Also,  you can use service samba status to check if it’s running or not.

Tagged with:
 

2 Responses to Samba 3.6 on PFSense

  1. Lazy caT says:

    ” … and add “mkdir /var/run/samba” to the bottom of the system section … ”
    Не, это работать не будет, до первой же перезагрузки… При перезагрузке, да и при загрузке определенных пакетов pfSense переписывает основной файл конфигурации (/cf/conf/config.xml) по нескольку раз, в этом можно убедится посмотрев “Diagnostics: Configuration History”, при этом он удаляет из config.xml все ненужные строчки, и в том числе. Я нашел другой выход из этой ситуации.
    В файле /etc/rc необходимо найти строку /etc/rc.start_packages и перед ней вписать команду /bin/mkdir /var/run/samba. Вот в этом случае, после перезагрузки, директория будет создаваться всегда. И строка никуда не денется, потому как /etc/rc извне не изменяется.

    eng:
    “… And add” mkdir / var / run / samba “to the bottom of the system section …”
    No, it will not work until the first reboot…
    When you restart, and when loading certain packages pfSense rewrites the main configuration file (/cf/conf/config.xml) several times, this can be ascertained by looking “Diagnostics: Configuration History”, while it removes all unnecessary lines config.xml and including.
    I found another way out of this situation.
    In the file /etc/rc is necessary to find a line in front of her /etc/rc.start_packages and enter the command /bin/mkdir /var/run/samba. But in this case, after the restart, the directory will be created always. And the line is not going anywhere, because the /etc/rc from the outside does not change.

    sorry for translate.google.com :)

  2. GuilleX says:

    Hey man! Thank you very much for the guide, i found it very useful and made my own translated version since i’m from Argentina. Thanks alot!