I have an Ubuntu PC with ufw firewall (GUI version). I have added the preset Samba service, in and out, and even tried adding the ports manually (135-139, 445, UDP and TCP, in and out), but it still blocks samba.

I am trying to access a share on another PC on my LAN. If I disable ufw, it works fine. It must be still blocking something and I can't figure it out. Any ideas?

I'm on Ubuntu 11.04 beta 2.

6 Answers 6


Mike's sudo ufw allow Samba works like a charm.

I personally prefer restricting to my private subnet, so for others who like the same, use:

$ sudo ufw allow from to any app Samba

Also, try running sudo ufw app list for a list of other apps you can use as short-hand to the required ports (eg. Postfix, OpenSSH, etc). Makes your firewall rules list a lot easier to read and maintain.

  • 2
    I like to add a "comment 'passing samba from local'" (without outer quotes) to the end of the ufw command line as a reminder so that when you do sudo ufw status numbered (or whatever) you can see why the rules are there.
    – pbhj
    Commented Sep 22, 2016 at 20:01
  • 2
    Samba application rules are not installed by default
    – wakeup
    Commented May 29, 2017 at 17:49

To allow samba with ufw use the following command

sudo ufw allow Samba

See the links given to you by other users for additional information.

  • 6
    Samba application rules are not installed by default
    – wakeup
    Commented Jun 13, 2017 at 9:23
  • you can install Samba with sudo apt install samba, then you will be able to use the command sudo ufw allow Samba Commented Nov 21, 2023 at 23:23

As I found no ufw profile for Samba 4 AD DC I set up my own which worked for me (opens the ports as listed in the Samba Wiki: Ports for Samba 4 as AD DC) and is easier to manage :

  1. Create a new file: /etc/ufw/applications.d/samba-ad-dc with the following content

     title=Samba 4 AD DC
     description=Samba 4 as domain controller
  2. Now add it to ufw with one of the following commands:

    • `sudo ufw allow from to any app samba-ad-dc` if you want to only allow it on your network
    • sudo ufw allow samba-ad-dc if you want to allow it for every network

If you enter sudo ufw status verbose it will output something like the following

To                         Action      From
--                         ------      ----
53 (samba-ad-dc)           ALLOW IN
88 (samba-ad-dc)           ALLOW IN
135/tcp (samba-ad-dc)      ALLOW IN
137/udp (samba-ad-dc)      ALLOW IN
138/udp (samba-ad-dc)      ALLOW IN
139/tcp (samba-ad-dc)      ALLOW IN
389 (samba-ad-dc)          ALLOW IN
445/tcp (samba-ad-dc)      ALLOW IN
464 (samba-ad-dc)          ALLOW IN
636/tcp (samba-ad-dc)      ALLOW IN
3268/tcp (samba-ad-dc)     ALLOW IN
3269/tcp (samba-ad-dc)     ALLOW IN
49152:65535/tcp (samba-ad-dc) ALLOW IN
  • This should be the answer.
    – wakeup
    Commented May 29, 2017 at 17:50

Try this:

As root, open /etc/default/ufw

Look for the line like this:

IPT_MODULES="nf_conntrack_ftp nf_nat_ftp nf_conntrack_irc nf_nat_irc"

Add nf_conntrack_netbios_ns to the line so that it looks like this:

IPT_MODULES="nf_conntrack_ftp nf_nat_ftp nf_conntrack_irc nf_nat_irc nf_conntrack_netbios_ns"

Now reload the firewall:

sudo ufw reload
  • 3
    echo 1 > /proc/sys/net/netfilter/nf_conntrack_helper is also necessary with newer kernels
    – Ayell
    Commented Apr 15, 2018 at 23:02
  • 1
    FWIW that will probably fail as the user doesn't have access to that file. Instead, echo 1 | sudo tee /proc/sys/net/netfilter/nf_conntrack_helper should work.
    – pbhj
    Commented Nov 22, 2020 at 0:15

You can use logging to find out if you're blocking a port that should not be blocked.

tail -f /var/log/ufw.log

Some extra information in case you havened tried it already: ufw manual , ufw wiki

  • Helped me. The client used the external IPv6 address in my case so the allow rules were not working to my surprise. Commented Oct 21, 2020 at 15:41

I had the same problem.

Here's what I suggest: After installing Gufw, make sure you log out of your account and then log back in.

It worked for me.

In general, whenever you have a problem with software you just installed, try the above suggestion first.

You will be surprised as to how often it cures the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .