Port 138 NETBIOS-DGM
Port 138 is the IANA-assigned netbios-dgm port for NETBIOS Datagram Service (TCP / UDP).
What is port 138 used for?
Port 138 is assigned to netbios-dgm and uses TCP / UDP. The IANA registry describes the service as “NETBIOS Datagram Service”. It sits in the well-known range, which operating systems reserve for core network services, so software expects it at this number by default.
Ports are the transport-layer address a service listens on. A client that wants to reach netbios-dgm connects to port 138. A TCP connection is refused when nothing is listening, while a UDP request simply goes unanswered. That is why a port conflict appears whenever two processes try to bind the same number.
Use the commands below to confirm whether port 138 is actually in use before you change firewall rules. Blocking the port stops new inbound traffic at the firewall, but it does not stop a local process from listening, and it does not remove the service from the machine.
Browse all Windows networking ports
Source: IANA Service Name and Transport Protocol Port Number Registry.
Check and block port 138
Copy-ready commands for the protocols assigned to this port. Run the check first, then block only what should not be reachable.
Check on Linux
sudo ss -tlpn 'sport = :138'
sudo ss -ulpn 'sport = :138'Check on Windows
Get-NetTCPConnection -LocalPort 138 -State Listen -ErrorAction SilentlyContinue
Get-NetUDPEndpoint -LocalPort 138 -ErrorAction SilentlyContinueBlock with UFW
sudo ufw deny 138/tcp
sudo ufw deny 138/udpBlock with iptables
sudo iptables -A INPUT -p tcp --dport 138 -j DROP
sudo iptables -A INPUT -p udp --dport 138 -j DROPThese commands are examples for a typical host. Check the listener before you change firewall rules, and persist iptables rules with iptables-save or netfilter-persistent. On Windows, use Windows Defender Firewall or New-NetFirewallRule for persistent blocks. The iptables rules here cover IPv4; mirror them with ip6tables if IPv6 is enabled.
Is port 138 safe to expose?
NetBIOS datagram service is not designed for hostile networks and can be used for spoofing and reconnaissance. Treat this port as sensitive. Restrict it to trusted networks or a VPN, require authentication and logging, and never expose it directly to the public internet without a hardened gateway in front.
Where port 138 is usually used
Most traffic on port 138 falls into these scenarios. The demo below is a safe way to confirm the listener before you change anything.
- Windows file sharing, printing and domain services inside a LAN.
- Admin tools enumerating shares, printers or RPC endpoints.
- Incident response checking whether lateral-movement ports are reachable.
Watch NetBIOS datagrams
NetBIOS datagram service is connectionless; watch UDP 138 on the host or a span port.
sudo tcpdump -ni any udp port 138
Common problems with port 138
Connection refused or timed out
Refused usually means the host is reachable but nothing is listening on port 138. A timeout more often means a firewall drop, a wrong host or a service bound to a different interface.
Port already in use
Find the process holding the port with sudo ss -tlpn 'sport = :138' or sudo lsof -i :138. Stop that process or configure it to bind another port; killing it without identifying it can take down a production service.
Firewall rule did not survive a reboot
UFW and Windows Firewall keep rules across restarts. Raw iptables rules do not: save them with iptables-save or the netfilter-persistent package, and re-apply after upgrades that reset the ruleset.
The port is blocked but still reachable
A firewall rule filters inbound traffic; it does not close the listener. Confirm with the check command above and bind the service to 127.0.0.1 when only local clients need it.
Port 138 at a glance
| Port number | 138 |
|---|---|
| Service name | netbios-dgm |
| Transport protocol | TCP / UDP |
| Category | Windows networking |
| Range | Well-known port (0–1023) |
| Risk level | High |
| Registered assignee | Not listed |
| Registry description | NETBIOS Datagram Service |
| Source | IANA Service Name and Transport Protocol Port Number Registry |
Frequently asked questions
What is port 138 used for?
Port 138 (NETBIOS-DGM) uses TCP / UDP. NETBIOS Datagram Service.
How do I check if port 138 is open?
On Linux run `sudo ss -tlpn 'sport = :138'` and `sudo ss -ulpn 'sport = :138'`. On Windows run `Get-NetTCPConnection -LocalPort 138 -State Listen -ErrorAction SilentlyContinue` and `Get-NetUDPEndpoint -LocalPort 138 -ErrorAction SilentlyContinue` in PowerShell. If the port is open, the output shows a process listening on port 138; empty output usually means nothing is bound to it.
How do I block port 138?
With UFW run `sudo ufw deny 138/tcp` and `sudo ufw deny 138/udp`. With iptables run `sudo iptables -A INPUT -p tcp --dport 138 -j DROP` and `sudo iptables -A INPUT -p udp --dport 138 -j DROP`. Persist the iptables rules with your distribution's netfilter-persistent or iptables-save tooling so they survive a reboot.
Is port 138 safe to expose?
NetBIOS datagram service is not designed for hostile networks and can be used for spoofing and reconnaissance. Nevertheless, treat this port as sensitive. Restrict it to trusted networks or a VPN, require authentication and logging, and never expose it directly to the public internet without a hardened gateway in front.
Related ports
Primary data: IANA Service Name and Transport Protocol Port Number Registry.
Last reviewed 2026-10-30 · Methodology · About · Privacy