On your network, every machine should be able to see one another, right? That’s a great idea, until you need to communicate to a Windows machine from a Linux machine via hostname. Out of the box, that’s just not going to happen. You can ping those Windows hostnames from your Linux boxes all you want and it will come back “hostname not found.” Every. Single. Time. If you issue even a ping command, you will see the failed results (Figure A).
There’s a fix for that, one that happens entirely on the Linux side. I’m going to show you how to easily add the necessary components to make this work for you. I will be demonstrating this on both an Elementary OS desktop and an instance of Fedora Server, as the installation process is different.
The fix for Elementary OS (or Ubuntu)
First we’ll take care of Elementary OS. Do note this process is the same for any distribution based on Debian or Ubuntu. In order to enable our Ubuntu-derivative to communicate to Windows, via hostname, we have to install winbind and libnss-winbind. To do that, open up a terminal window and issue the following command:
sudo apt install winbind libnss-winbind
Once that installation completes, open up the file /etc/nsswitch.conf with the command sudo nano /etc/nsswitch.conf and look for the line:
hosts: files mdns4_minimal [NOTFOUND=return] dns
Change that line to:
hosts: files mdns4_minimal [NOTFOUND=return] dns wins mdns4
Save and close the file.
Now issue the same ping command to the hostname, and you should see a response (Figure B).
The fix for Fedora Server
The fix for Fedora Server is quite different. Instead of installing winbind and lbnss-winbind, you open up a terminal and issue the following command:
sudo dnf install samba-winbind-clients
The above command will pick up the necessary dependencies (samba-winbind and samba-winbind-modules). That is all you need to do for Fedora. Once those install, you should be able to ping your Windows machine, via hostname, all you want.
Not just pinging
With this fix in place, you should also be able to connect to Windows shares via hostname and any other service you might need. If you’re working on a network landscape that consists of a mixture of platforms, these little nuances can go a very long way.
Subscribe to the Developer Insider Newsletter
From the hottest programming languages to commentary on the Linux OS, get the developer and open source news and tips you need to know. Delivered Tuesdays and Thursdays