I have installed and configured a Samba server on CentOS. I can successfully access the server by typing \\\\ip-address\\share
in the address bar of Windows Explorer, but it doesn’t show up in the network list. When I try to connect using the hostname instead of the IP address, Windows gives an error message saying it cannot access \\\\hostname\\share
.
Although I can ping the IP address of the Samba server, I cannot ping the hostname from Windows. However, I am able to ping the hostname from the CentOS server itself.
The Samba server is configured to use DHCP via NetworkManager, and the router has a static IP rule set up for the hostname. Additionally, the hostname is set via the hostnamectl command.
Winbind is enabled and running on the server, but I am unsure if it is properly configured.
The firewall-cmd is active and running, with Samba services open in the public zone.
Finally, I have updated the seLinux settings using the command “sudo setsebool -P samba_enable_home_dirs on
“. Here is a partial dump of the smb.conf file:
[global]
workgroup = WORKGROUP
netbios name = *hidden*
wins support = Yes
encrypt passwords = true
security = user
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = Yes
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = Yes
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = @printadmin root
force group = @printadmin
create mask = 0664
directory mask = 0775
What steps can I take to enable Windows to access the share using the hostname?
EDIT: I am including a dump of the nmcli command output.
connection.id: MyEth
connection.uuid: 4b4c8ef6-def8-3c7f-9c1c-e3bdd39d2ed4
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: --
connection.autoconnect: yes
connection.autoconnect-priority: -999
connection.autoconnect-retries: -1 (default)
connection.auth-retries: -1
connection.timestamp: 1565104013
connection.read-only: no
connection.permissions: --
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries: --
connection.gateway-ping-timeout: 0
connection.metered: unknown
connection.lldp: default
connection.mdns: -1 (default)
-------------------------------------------------------------------------------
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: no
802-3-ethernet.mac-address: B8:27:EB:FF:F8:7D
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist: --
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels: --
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options: --
802-3-ethernet.wake-on-lan: default
802-3-ethernet.wake-on-lan-password: --
-------------------------------------------------------------------------------
ipv4.method: auto
ipv4.dns: --
ipv4.dns-search: --
ipv4.dns-options: \"\"
ipv4.dns-priority: 0
ipv4.addresses: --
ipv4.gateway: --
ipv4.routes: --
ipv4.route-metric: -1
ipv4.route-table: 0 (unspec)
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0 (default)
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
-------------------------------------------------------------------------------
ipv6.method: auto
ipv6.dns: --
ipv6.dns-search: --
ipv6.dns-options: \"\"
ipv6.dns-priority: 0
ipv6.addresses: --
ipv6.gateway: --
ipv6.routes: --
ipv6.route-metric: -1
ipv6.route-table: 0 (unspec)
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.addr-gen-mode: stable-privacy
ipv6.dhcp-duid: --
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
-------------------------------------------------------------------------------
proxy.method: none
proxy.browser-only: no
proxy.pac-url: --
proxy.pac-script: --
-------------------------------------------------------------------------------
firewall config:
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: ssh dhcpv6-client http samba https
ports: 22/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
1 Answer
Introduction
Samba is a popular open-source software suite that enables Windows clients to connect to Linux/Unix servers and vice versa. It provides file and print services, authentication and authorization services, and a central point for managing network resources. While setting up a Samba server on CentOS is relatively easy, connecting to it from a Windows client can sometimes be challenging, especially when using a hostname instead of an IP address. In this blog post, we will explore how to connect to a Samba server via hostname on Windows 10.
Check Hostname Resolution
The first step in troubleshooting Samba hostname resolution issues is to check whether the hostname can be resolved to an IP address. To do this, open the Command Prompt on the Windows client by pressing the Windows key + R, type cmd, and hit Enter. Then, type the following command:
nslookup hostname
Replace “hostname” with the actual hostname of your Samba server. If the command returns an IP address, then the hostname is resolving correctly. If it returns an error message such as “Non-existent domain,” then the hostname is not resolving, and you need to fix it.
One way to fix the hostname resolution issue is to add the Samba server’s hostname and IP address to the Windows client’s hosts file. To do this, open Notepad as an administrator, then open the hosts file located at C:WindowsSystem32driversetchosts
, and add the following line:
IP_address hostname
Replace “IP_address” with the actual IP address of your Samba server and “hostname” with the actual hostname. Save the hosts file and try connecting to the Samba server again using the hostname.
Check Windows Firewall Settings
If the hostname resolution is not the issue, the next step is to check the Windows Firewall settings. By default, Windows Firewall blocks incoming connections to Samba ports, which prevents Windows clients from accessing the Samba server. To allow incoming connections to Samba ports, you need to create a new inbound rule in Windows Firewall.
To create a new inbound rule, open the Control Panel, click on System and Security, then click on Windows Defender Firewall. Next, click on Advanced settings, then click on Inbound Rules. Click on New Rule, select Port, then click on Next. Enter the following information:
- Specific local ports: 139, 445
- Protocol: TCP
- Action: Allow the connection
- Profile: Domain, Private, Public (or whichever profile you want to apply the rule to)
- Name: Samba
Click on Finish to create the new inbound rule. Try connecting to the Samba server again using the hostname.
Check Samba Configuration
If the hostname resolution and Windows Firewall settings are not the issue, the next step is to check the Samba configuration. Make sure that the Samba server’s hostname is correctly configured in the smb.conf
file. Open the smb.conf
file using a text editor such as Nano or Vim and look for the following lines:
workgroup = WORKGROUP
netbios name = hostname
wins support = Yes
Replace “hostname” with the actual hostname of your Samba server. Save the smb.conf
file and restart the Samba service using the following command:
sudo systemctl restart smb
Try connecting to the Samba server again using the hostname.
Check SELinux Settings
SELinux is a security module that provides access control and security policies for Linux systems. It can sometimes interfere with Samba hostname resolution, preventing Windows clients from accessing the Samba server. To check SELinux settings, open the smb.conf
file and look for the following line:
selinux = enforcing
If SELinux is enforcing, try changing it to permissive by replacing the line with:
selinux = permissive
Save the smb.conf
file and restart the Samba service. Try connecting to the Samba server again using the hostname.
Check DNS Settings
If all else fails, the last step is to check the DNS settings. Make sure that the Samba server’s hostname and IP address are correctly configured in the DNS server. You can check the DNS settings using the nslookup command we used earlier. If the command returns an IP address, then the DNS settings are correct. If it returns an error message, then you need to fix the DNS settings.
One way to fix the DNS settings is to add the Samba server’s hostname and IP address to the DNS server’s zone file. The process for doing this varies depending on the DNS server you are using. Consult the documentation for your DNS server for instructions on how to add a new DNS record.
Conclusion
Connecting to a Samba server via hostname on Windows 10 can sometimes be challenging, but by following the steps outlined in this blog post, you should be able to troubleshoot and fix any issues you encounter. Remember to check hostname resolution, Windows Firewall settings, Samba configuration, SELinux settings, and DNS settings. With a little patience and persistence, you should be able to connect to your Samba server using the hostname.