Skip to main content
Welcome guest. | Register | Login | Post

Windows/Linux host name integration

4 replies [Last post]
free-zombie's picture
Joined: 2006-03-08

Windows machines communicate over the NetBIOS and SMB protocols, and use NetBIOS to resolve each others' names. On UNIXoid systems like GNU/Linux, names are usually only resolved via DNS and /etc/hosts (Windows supports both of there techniques as well, though /etc/hosts is someplace else). This means that if you have a bunch of Windows machines and a linux machine, the windows machines will be able to call each other by name (can be tested with the PING command in a DOS prompt), but cannot be resolved from the linux machine. If you are in a windows network, you usually install Samba sooner or later, which allows you to share files with the windows machines and allows the windows machines to ping you by name, NOT the other way round. This is, puzzlingly, the default setup on all distributions I've seen.

To fix this, make sure you have a file /lib/ or similar. On Debian GNU/Linux 3.1, this is located in the winbind package, but it could be part of samba in other distributions. Then, open /etc/nsswitch.cond in a text editor you are capable of using as root and look for a line like

hosts:          files dns

and add wins to it:

hosts:          files dns wins

Voilà, you should now be able to ping a windows machine by host name or use the name in any program really.

This trick is documented, but little known. Trying to fix this problem, I came across an ancient but extremely valuable LQ thread without which I would never have found the solution.

libervisco's picture
Joined: 2006-05-04
Well, I gotta give it to

Well, I gotta give it to the LQ, one of the first and still most popular forums. Not that we can't be better. Eye

Anyway, this looks like something that would fit the tips section in blogs, but well, it's ok now.

Thanks for sharing!

free-zombie's picture
Joined: 2006-03-08
the whole thing with DNS

You can also have a DNS server act as a proxy like that. This can be central for all the network and can combine NetBIOS proxying with OpenDNS or OpenNIC connectivity.

The DNS server software I chose for this setup is PowerDNS for its ability to get domain names from programs written in any language, including shell. PowerDNS is available in Debian GNU/Linux 3.1 as pdns. (on other distributions, make sure the PowerDNS recursor is installed) So, here comes the script I wrote for it:

# PowerDNS PipeBackend nmblookup glue script
# Copyright (C) 2007 Thomas Jollans
# Ditributed under the terms of the WTFPL 


# your workgroup or domain name, makes xxx.$MYDOMAIN equivalent to xxx .
# TTL in seconds (time how long a domain name is cached)
TTL=900 # 15 minutes
# where to log to

echo >>$LOGFILE $$ started
read -r line0
if [[ "`echo $line0`" != "HELO 1" ]]; then echo FAIL ;fi
echo -e "OK\tNetBIOS back-end is alive and well"
echo >>$LOGFILE $$ shaken hands: "'$line0'"

while true
    read line
    echo >>$LOGFILE $$ query: "'$line'"
    case ${quest[0]}
        PING)   echo END
        Q)      name=`echo ${quest[1]} | sed "s/\.$MYDOMAIN\$//i"`
                echo >>$LOGFILE $$ $name
                if echo $name | grep -s '\.' >/dev/null; then echo END
                    addr=`nmblookup ${name} | grep -v 'querying\|failed' | awk '//{ print $1 }'`
                    echo >>$LOGFILE $$ looking up $name; result: ${addr-none}
                    if [[ -z "$addr" ]]; then echo END
                    elif [[ ${quest[3]} = ANY ]]; then
                      echo -e "DATA\t${quest[1]}\tIN\tA\t${TTL}\t1\t${addr}"
                      echo -e "DATA\t${quest[1]}\tIN\tMX\t${TTL}\t1\t${addr}\t0"
                      echo END
                    elif [[ ${quest[3]} = A ]]; then
                      echo -e "DATA\t${quest[1]}\tIN\tA\t${TTL}\t1\t${addr}"
                      echo END
                    elif [[ ${quest[3]} = MX ]]; then
                      echo -e "DATA\t${quest[1]}\tIN\tMX\t${TTL}\t1\t${addr}\t0"
                      echo END
                      echo END
        "")       exit 7;;
        *)      echo END ;;

now you need to get the DNS server to use this information. Add the following lines to /etc/powerdns/pdns.conf:



and set the following in /etc/powerdns/recursor.conf:


Now (re)start the two servers, on Debian with

# /etc/init.d/pdns-recursor restart
# /etc/init.d/pdns restart

and test the setup with


If it works, add the machine to all /etc/resolv.conf files you can find to make it the default name server. It will return addresses (IPv4 only?) for the Windows machines in your workgroup and everything the name servers in the server's resolv.conf know.
If it doesn't, ask here.

Information on how to configure the name server on DHCP-connected clients to come

free-zombie's picture
Joined: 2006-03-08
libervisco wrote: Anyway,
libervisco wrote:

Anyway, this looks like something that would fit the tips section in blogs, but well, it's ok now.

Right... originally I wanted to ask about this, but when I found the answer I just used the open window Eye

free-zombie's picture
Joined: 2006-03-08
It is not entirely unlikely

It is not entirely unlikely that you use DHCP to configure your network. In fact, if you did not manually set IP adresses to use on the network and have a permanently running router of sorts, then you almost certainly do. DHCP is also used to get name servers to use, and thus the "DHCP client" overwrites /etc/resolv.conf and thus any name servers you man have manually set.
There are two common GNU/Linux DHCP clients: dhclient and dhcpcd.

dhclient is the more full-featured of the two; it allows you to set extra name servers to add to resolv.conf by adding a line like

prepend domain-name-servers;

to /etc/dhclient.conf.

dhcpcd is extremely basic; it allows no customization of /etc/resolv.conf whatsoever. It only has a command-line option -R