Installing Samba (for windows file sharing) in FreeBSD

People keep telling me that they have trouble getting Samba to work properly.  I found it difficult to get working properly too, so here’s a guide that should make it a lot easier…

First of all, we need to install it!  Make sure you have updated your Ports tree (see other posts) and then, as root:

cd /usr/ports/net/samba34
make config

This will show the configuration dialog box for options for the port.  Using the space bar and cursor keys, deselect ALL the options, and then enable only these:

AIO_SUPPORT, FAM_SUPPORT, QUOTAS, PAM_SMBPASS, POPT

Press TAB to go to OK and press enter.  Now you can build and install the port with:

make install distclean

It will go off and install dependencies if it needs to.  If you see any other configuration boxes, just accept the defaults and move on.

This takes a while as it has to install quite a few packages/ports, mostly for the file alteration monitor support – but it’s worth it so be patient.  If you already have X/gnome2 installed, this process will be much quicker.

Once the port is installed, we need to make a few changes to the limits within FreeBSD to make samba a little happier…  edit /etc/sysctl.conf and add the following:

kern.maxfiles=25600
kern.maxfilesperproc=16384
net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=65536

And we also need to add another kernel module.  edit /boot/loader.conf and add the following:

aio_load=”YES”

Now, we need to tell samba to start on bootup, edit /etc/rc.conf and add the following:

samba_enable=”YES”
samba_config=”/usr/local/etc/smb.conf”
winbindd_enable=”NO”

And finally, we need to make ourselves a config file.  Edit /usr/local/etc/smb.conf and remove its entire contents.  Replace with the following template:

[global]
server string = Server Name
interfaces = em0
bind interfaces only = Yes
map to guest = Bad User
passdb backend = tdbsam
log file = /var/log/samba34/log.%m
max log size = 500
name resolve order = wins lmhosts bcast host
load printers = No
os level = 10
preferred master = No
domain master = No
dns proxy = No
wins support = No
ldap ssl = no
hosts allow = 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8
hosts deny = 0.0.0.0/0
case sensitive = Yes
level2 oplocks = Yes
oplocks = Yes

[tmp]
comment = Temp Folder
path = /tmp
guest only = Yes
guest ok = Yes
read only = No

Replace ‘interfaces’ with your network interface name (mine is em0)

Your windows netbios name, by default, will be the hostname of your FreeBSD server up to the first dot.  E.g. for test.dan.me.uk the netbios name is TEST.

Reboot to startup samba with all the relevant changes.  Browse to the server and you will see “tmp” share which is a user nobody access to /tmp.

Check the samba documentation on how to define other shares, such as per-user homedir shares.

4 thoughts on “Installing Samba (for windows file sharing) in FreeBSD

  1. sukosevato

    Great guide as usual. Samba is very annoying to get working with that massive config. So the “Edit /usr/local/etc/smb.conf and remove its entire contents.” made me smile :) Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>