Connecting to an SMB/CIFS service on a non-standard port like 4445 requires explicit configuration in the client command or mount options, as default tools expect port 445. This article explains how to correctly specify the port parameter in Linux commands and Windows network paths to resolve connection timeouts and refused connections without altering firewall rules unnecessarily.
Understanding SMB Port Defaults
Server Message Block (SMB) protocol traditionally operates over TCP port 445 for direct hosting. When administrators configure SMB services on alternative ports such as 4445, they are typically doing so to bypass firewalls that block standard SMB traffic or to isolate specific services. Client-side software does not automatically detect these changes; it must be explicitly instructed to target the new port. Failure to do so results in immediate connection failures because the client attempts to reach the default endpoint where no service is listening.The Role of Firewall Rules
Before troubleshooting client syntax, ensure the server side is actually listening on the expected port. Usenetstat -tlnp | grep 4445 or ss -tlnp | grep 4445 on the server to verify the daemon is bound to the interface. If the service is not listed, check your firewall configurations. While this article focuses on client connectivity, a blocked inbound rule on the server will mimic client misconfiguration symptoms. For broader network troubleshooting context, see Troubleshooting: No Internet on QEMU VM despite Connection Present for similar diagnostic patterns regarding network stack verification.
Troubleshooting SMB Connections on Linux
Linux clients use thesmbclient utility or the cifs-utils package for mounting shares. The syntax for specifying a non-standard port differs between interactive testing and persistent mounts.
Using smbclient
When usingsmbclient for manual access, you must append the port number to the server address. The standard format uses the -p flag followed by the port number. For example, to connect to a share named public on server 192.168.1.50 using port 4445, the command is:
smbclient //192.168.1.50/public -U username -p 4445
If you omit the -p 4445 argument, the tool defaults to port 445. A common error is assuming the IP address alone is sufficient. Always verify the output for "Connection refused" or "NT_STATUS_CONNECTION_REFUSED," which indicates the client hit the wrong port or the server rejected the handshake.
Mounting with cifs-utils
For permanent mounts in/etc/fstab, the mount.cifs driver requires the port= option within the mount parameters. The line should resemble:
//192.168.1.50/public /mnt/smb cifs credentials=/etc/smbcreds,uid=1000,gid=1000,port=4445 0 0
Ensure there are no spaces around the equals sign in the port=4445 parameter, as this can cause parsing errors during the mount process. After updating /etc/fstab, test the configuration with sudo mount -a. Check dmesg for detailed kernel messages if the mount fails silently.
Windows Client Configuration
Windows handles non-standard SMB ports differently depending on whether you are accessing via File Explorer or mapping a drive through PowerShell.UNC Path Syntax
The Universal Naming Convention (UNC) path supports port specification directly in the string. When navigating to a network location, use the following format:\\192.168.1.50\public:4445
Note the colon separator between the IP address and the port number. If you enter only \\192.168.1.50\public, Windows attempts to use port 445. This method works for both File Explorer navigation and shortcut targets. However, some older applications may not parse the UNC path correctly if it contains a port number, requiring alternative access methods.
PowerShell and Net Use
Command-line tools likenet use do not support port specification directly in the traditional syntax. Instead, you must rely on the UNC path format within the command or use PowerShell cmdlets. For net use, you can often pass the UNC path directly:
net use Z: \\192.168.1.50\public:4445 /user:username password
If this fails due to legacy command limitations, consider using PowerShell's New-SmbMapping cmdlet, which offers more granular control over SMB sessions. Ensure that the Windows Firewall allows outbound traffic on port 4445, as corporate environments often restrict non-standard ports.
Diagnostics and Verification
If connections still fail after verifying syntax, perform basic network diagnostics. Usetelnet 192.168.1.50 4445 or nc -zv 192.168.1.50 4445 to test raw TCP connectivity. A successful connection returns a confirmation message, while a failure indicates a network block or service downtime.
For users experiencing intermittent drops, check for MTU mismatches or IPv6 interference. If your network utilizes IPv6, ensure that the SMB service is not inadvertently binding to an IPv6 address while the client queries IPv4. In complex network setups involving packet filtering, refer to Explicitly Dropping IPv6 Packets with ip6tables to understand how layer 3 filters might impact SMB stability.
Avoid exposing SMB ports directly to the internet. Non-standard ports provide security through obscurity but do not replace encryption. Always use SMB 3.0+ with encryption enabled if traversing untrusted networks.
Frequently Asked Questions
Why does my SMB connection timeout on port 4445?
Timeouts usually indicate that the packet is being dropped by a firewall rather than actively refused. Verify that the server’s firewall allows inbound TCP traffic on port 4445. Additionally, ensure your client’s local firewall permits outbound connections to non-standard high ports.Can I use a hostname instead of an IP address with a custom port?
Yes, most modern SMB clients support hostnames in the UNC path or command line arguments. Replace the IP address with the DNS name, ensuring the colon and port remain attached, such as\\server.local\share:4445. Name resolution must succeed before the SMB handshake begins.
Does changing the SMB port affect performance?
Changing the port itself has negligible impact on throughput. Performance issues arise from network latency, SMB version negotiation, or encryption overhead. Ensure both client and server agree on SMB 3.0 or higher for optimal speed and security features.How do I fix permission denied errors on a custom port?
Permission errors are unrelated to port numbers. They stem from incorrect usernames, passwords, or share-level ACLs. Verify your credentials match those configured on the SMB server. Use the-U flag in Linux or explicit user parameters in Windows to ensure correct authentication context.