5

I am trying to hide my Samba server from my LAN completely but am unable to do so. I managed to hide the folders but not the server itself. What I mean is this, when I open Finder on my Mac there is a list of Shared networks, my Raspberry Pi is listed there as RASPBERRY. <-- I'd assume that's the NetBIOS name.

I read that I have to disable the nmbd server on the samba server. I tried adding disable netbios = yes to my [Global] in /etc/samba/smb.conf but this did not work.

I also tried editing my rc/init scripts <- that launches the nmbd server but I get an empty file with nano editor. I guess I am doing something wrong there.

I also tried:

1) sudo systemctl stop smbd

2) sudo systemctl disable smbd

^Those two completely destroyed my Samba server, making me unable to connect at all. After reversing those commands it still did not work, luckily I had a recent backup & copied my Samba config file.

I tried other things too but all older posts are from 2011.

Can someone help me? I don't know how to do it.

Here's the source of part of my post: https://www.samba.org/samba/docs/current/man-html/nmbd.8.html


Terminal results from netstat -ln.

<code>netstat -ln</code> <--**RESULT:**

16
  • 1
    The answer to this is over my head I'm afraid, but it occurs to me that it might have to be dealt with in the Bonjour/Zero Config networking setup in your Mac... have you looked in that direction? Your post has got me curious though... I've just set up a Samba share on my RPi, and sometimes I see it in Finder, and sometimes I don't. I'll investigate further & post again if I learn anything.
    – Seamus
    Commented Jun 2, 2018 at 13:00
  • 1
    Oh, one other thing: You're looking at Samba docs for ver 4.8, and you've probably got ver 4.5.12 on your RPi. pi@raspberrypi3b:~ $ nmbd --version Version 4.5.12-Debian
    – Seamus
    Commented Jun 2, 2018 at 13:23
  • 1
    I may have something... do this from the cmdline after you've stopped nmbd: netstat -an | grep 137 Does it show anything?
    – Seamus
    Commented Jun 3, 2018 at 1:02
  • 1
    Is nmbd running? (sudo ps -e | grep nmbd)
    – Seamus
    Commented Jun 3, 2018 at 13:23
  • 1
    Ach! I just noticed, you're using netstat -an , instead of netstat -ln. See man netstat for the diff, but the l option means list the active listeners. I changed that in the answer... Run that, and hopefully you'll see nothing listening
    – Seamus
    Commented Jun 3, 2018 at 15:37

1 Answer 1

8

I hope this helps:

The Short Answer:

  1. Add the following line in the Global section of /etc/samba/smb.conf:

    disable netbios = yes

  2. Prevent nmbd from starting at boot time with the following command:

    pi@raspberrypi3b:~ $ sudo update-rc.d nmbd disable

You can verify that this disables nmbd with netstat -ln | grep 137 and netstat -ln | grep 138. Ports 137 & 138 are two ports used by netbios.

Here's how I got to the Short Answer:

pi@raspberrypi3b:~ $ sudo ps -e | grep nmbd  
6555 ?        00:00:00 nmbd 
pi@raspberrypi3b:~ $ netstat -ln | grep 137 
udp        0      0 192.168.1.255:137       0.0.0.0:*
udp        0      0 192.168.1.27:137        0.0.0.0:*                          
udp        0      0 192.168.1.255:137       0.0.0.0:*                 
udp        0      0 192.168.1.28:137        0.0.0.0:*                 
udp        0      0 0.0.0.0:137             0.0.0.0:*

pi@raspberrypi3b:~ $ netstat -ln | grep 138 
udp        0      0 192.168.1.255:138       0.0.0.0:*  
udp        0      0 192.168.1.27:138        0.0.0.0:*                          
udp        0      0 192.168.1.255:138       0.0.0.0:*                 
udp        0      0 192.168.1.28:138        0.0.0.0:*                 
udp        0      0 0.0.0.0:138             0.0.0.0:*

These 3 commands tell us that nmbd is running under pid 6555, and that ports 137 & 138 are in use. We believe that nmbd is the user of these ports. Without knowing precisely how to disable nmbd at this point, let's determine the effect of setting the option disable netbios = yes in /etc/smb.conf. After making that change, restart samba to have it re-read smb.conf:

pi@raspberrypi3b:~ $ sudo /etc/init.d/samba restart 
[ ok ] Restarting nmbd (via systemctl): nmbd.service. 
[ ok ] Restarting smbd (via systemctl): smbd.service. 

pi@raspberrypi3b:~ $ netstat -ln | grep 137
udp        0      0 192.168.1.255:137       0.0.0.0:*                 
udp        0      0 192.168.1.27:137        0.0.0.0:*                 
udp        0      0 192.168.1.255:137       0.0.0.0:*                 
udp        0      0 192.168.1.28:137        0.0.0.0:*                 
udp        0      0 0.0.0.0:137             0.0.0.0:* 

pi@raspberrypi3b:~ $ netstat -ln | grep 138 
udp        0      0 192.168.1.255:138       0.0.0.0:*  
udp        0      0 192.168.1.27:138        0.0.0.0:*                          
udp        0      0 192.168.1.255:138       0.0.0.0:*                 
udp        0      0 192.168.1.28:138        0.0.0.0:*                 
udp        0      0 0.0.0.0:138             0.0.0.0:*

CONCLUSION: Adding the option disable netbios = yes to smb.conf doesn't stop broadcasts on ports 137 and 138. Let's stop nmbd, and determine the effect:

pi@raspberrypi3b:~ $ sudo ps -e | grep nmbd  
6555 ?        00:00:00 nmbd 
pi@raspberrypi3b:~ $ sudo kill 6555 
pi@raspberrypi3b:~ $ sudo ps -e | grep nmbd 
pi@raspberrypi3b:~ $ netstat -ln | grep 137 
pi@raspberrypi3b:~ $ netstat -ln | grep 138

CONCLUSION: Stopping nmbd stops activity on ports 137 and 138. Now, we must learn how to prevent nmbd from being started at boot time.

Where is nmbd started?

pi@raspberrypi3b:~ $ ls -l /etc/init.d | grep nmbd 
-rwxr-xr-x 1 root root 2064 Mar  5 13:30 nmbd 

CONCLUSION: nmbd startup script is in /etc/init.d and therefore controlled by update-rc.d

After reading man update-rc.d and postings in other forums, it seems there is some question as to exactly how to do this; i.e. which of the following commands should be used? :

sudo update-rc.d nmbd disable

-- OR --

sudo update-rc.d -f nmbd remove

Since disable sounds less permanent than remove, try that first :)

sudo update-rc.d nmbd disable  
pi@raspberrypi3b:~ $ sudo reboot

...

Finally, let's check to make sure activity on ports 137 and 138 has been stopped, and that nmbd is not running:

pi@raspberrypi3b:~ $ sudo ps -e | grep nmbd 
pi@raspberrypi3b:~ $ netstat -ln | grep 137 
pi@raspberrypi3b:~ $ netstat -ln | grep 138 
pi@raspberrypi3b:~ $

This appears to have done the deed. Let me know if this does what you needed.

2
  • Hi, I did what you suggested: 1. Leave the disable netbios = yes in smb.conf in [GLOBAL] section. 2. sudo update-rc.d nmbd disable 3. sudo reboot 4. sudo ps -e | grep nmbd 5. netstat -ln | grep 137 <-- Result unix 2 [ ACC ] SEQPACKET LISTENING 13717 /var/run/bluealsa/hci0 6. netstat -ln | grep 137 <-- result: none. It gave me the same outcome as sudo systemctl disable nmbd, which stops the NetBIOS broadcasting but doesn't stop the IP from doing so. Thanks for your suggestion though!
    – May
    Commented Jun 3, 2018 at 13:09
  • The edit of Jun 5 should address that.
    – Seamus
    Commented Jun 19, 2018 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.