What Ports Need To Be Open For Samba To Communicate With Other Windows/Linux Systems?

by on July 29, 2006 · 6 comments· LAST UPDATED April 2, 2012

in

What ports need to be open for Samba to communicate with other windows/linux systems? I need to configure Linux firewall so I need the exact port TCP and UDP port numbers for SMB/CIFS networking protocol.

You can get list of ports from file called /etc/services. For your ease of use here are ports you need to open for two-way samba communication with Windows and Linux desktop systems.

  • netbios-ns - 137/tcp # NETBIOS Name Service
  • netbios-dgm - 138/tcp # NETBIOS Datagram Service
  • netbios-ssn - 139/tcp # NETBIOS session service
  • microsoft-ds - 445/tcp # if you are using Active Directory

Other ports:

  • Port 389 (TCP) - for LDAP (Active Directory Mode)
  • Port 445 (TCP) - NetBIOS was moved to 445 after 2000 and beyond, (CIFS)
  • Port 901 (TCP) - for SWAT service (not related to client communication)

Command To Find Out Required TCP/UDP Ports For SMB/CIFS Networking Protocol

Type the following command:
$ grep -i NETBIOS /etc/services
Sample outputs:

netbios-ns	137/tcp				# NETBIOS Name Service
netbios-ns	137/udp
netbios-dgm	138/tcp				# NETBIOS Datagram Service
netbios-dgm	138/udp
netbios-ssn	139/tcp				# NETBIOS session service
netbios-ssn	139/udp

Sample iptables Rules

To open Samba communication between 192.168.1.0/24 subnet representing the machines on your network which should operate as clients of the Samba server. Edit /etc/sysconfig/iptables under RHEL/CentOS server. Add the following lines, before the final LOG and ROP lines for the RH-Firewall-1-INPUT chain:

-A RH-Firewall-1-INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 137 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 138 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 139 -j ACCEPT
-A RH-Firewall-1-INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 445 -j ACCEPT

Feel free to change rules as per your setup. Save and close the file. Restart firewall service, enter:
# /sbin/services iptables restart

See this url for Iptables rules for SAMBA/CIFS clients.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 6 comments… read them below or add one }

1 ZeldoR December 7, 2009 at 5:06 pm

Thx. very much, nice overview :)

Reply

2 Scott February 22, 2011 at 11:42 pm

One note:

Ports 137 and 138 are UDP for samba. Cheers,

Reply

3 John Rose April 5, 2013 at 10:06 am

Please explain why $ grep -i NETBIOS /etc/services shows:
netbios-ns 137/tcp # NETBIOS Name Service
netbios-ns 137/udp
netbios-dgm 138/tcp # NETBIOS Datagram Service
netbios-dgm 138/udp
netbios-ssn 139/tcp # NETBIOS session service
netbios-ssn 139/udp
I.e. does above mean that 137/udp etc is not used?

Reply

4 Ben Watson May 3, 2013 at 2:24 pm

Brilliant, thank you.

Reply

5 Fu October 28, 2013 at 9:46 pm

I believe the only ports that are actually used are the ones listed at the top of the article:
netbios-ns – 137/tcp # NETBIOS Name Service
netbios-dgm – 138/tcp # NETBIOS Datagram Service
netbios-ssn – 139/tcp # NETBIOS session service
microsoft-ds – 445/tcp # if you are using Active Directory

The other ports are superfluous.

Reply

6 Fu October 28, 2013 at 9:48 pm

Sorry, I made a mistake. The required ports are actually:

TCP 139 445
UDP 137 138

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: