Access Linux Workstation by Hostname on a Windows Network

Most users of linux based laptops will encounter this issue at one point or another. You bring your laptop into a rudimentary residential Windows based network composed of 3 or 4 machines and a router that acts as a gateway and DHCP. All the networked machines can ping each other by their hostnames even though there is no central DNS server (and the router is not set up for it). Your linux machines hostname however will be all but invisible to the windows boxes, even though they will have no problems pinging your IP. Why? Windows boxes broadcast their hostnames using NetBios protocol. If you want to join in the fun, you have to do the same. Fortunately it’s easy. First download samba:

sudo aptitude install samba

Once it is installed and running, edit /etc/samba/smb.conf and put following lines in somewhere in Global Settings section:

workgroup = your_workgtoup
netbios name = your_hostname

The last line is the one that makes the magic happen. You may need to restart samba for the settings to take place. In my case, windows boxes started seeing my linux machine as soon as I saved and closed the smb.conf file. :)
Of course this only works on a regular windows workgroup. If you are working in a windows domain (especially an Active Directory domain) hings get more difficult. Here is all the steps I took to make my linux box visible on the network:

  1. Added following lines to /etc/samba/smb.conf:
    netbios name = your_hostname
    workgroup = your_short_domain_name
    realm =
    password server =
    security = ads
  2. Logged into the Domain Controller (DC) and added a new computer in Active Directory with the same name as my linux box:

    New Computer

  3. Back on linux box I joined the windows domain:
    net ads join -U Administrator
  4. I went back to the DC and checked the entry for my computer – it correctly recognized OS as samba:

    Computer Properties

  5. Added following line to /etc/dhcp3/dhclient.conf to ensure that the host name is sent to the DHCP server every time I renew the lease:
    send host-name "my_hostname";
  6. I went back to the DC and configured the DHCP server to always update DNS records for connecting machines even without being asked:

    DHCP DNS Configuration

  7. Finally, I dropped connection via ifdown, renewed DHCP lease and brought the network up via ifup
  8. Next I went back to the DC and verified that my hostname was added to the local DNS. It should get updated every time you negotiate DHCP lease.

After all that meddling I finally was able to ping my linux box by hostname from machines that were joined to the domain, as well as a windows laptop that was sitting outside the domain but on the same network. It worked using both the short hostname, as well as the format.

Note that when you find yourself in that ad-hoc unorganized windows network again, you still should be visible because of that netbios name parameter in smb.conf

[tags]linux, ubuntu, hostname, samba, smb.conf, dhcp, dns, domain, active directory, ads, server, dhclinent.conf, ping[/tags]

This entry was posted in sysadmin notes and tagged , , . Bookmark the permalink.

4 Responses to Access Linux Workstation by Hostname on a Windows Network

  1. ths UNITED KINGDOM Mozilla Firefox Windows Terminalist says:

    a minor typo: dhc_l_ient.conf

    why would I take that hassle and install samba server just to be visible? I’d rather add a DNS service and let DHCP/DNS take care of it all. Then WINS will resolve netbios names by querying DNS (assuming that netbios name equals DNS hostname).

    Samba will pick up changes to smb.conf after at most 1 minute or you can force a reload of smb.conf with kill -HUP (-1) to the parent smbd process (the one with ppid==1).

    Reply  |  Quote
  2. Luke Maciak UNITED STATES Mozilla Firefox Ubuntu Linux says:

    Thanks! I fixed it.

    Oh, and if you are working in primarily Windows network having samba around might be a good idea. If I want to I can set up samba shares and make it available. And I think smbfs depends on samba – and that’s what I use to mount windows network shares on my machine.

    Reply  |  Quote
  3. Mehdi Karamnejad ISLAMIC REPUBLIC OF IRAN Safari Windows says:

    [quote post=”1984″]why would I take that hassle and install samba server just to be visible?[/quote]
    when u have a problem like mine! check this out
    there are over 100 windows stations on a network ,they are all one subnet and all work with netbios names! there is no dns server and if there is you are not authorised to use dns server,not for performance reasons you decide to migrate one of servers from windows to linux,from now on you have no name in those stupid windows stations! :D here this hint will blast! thanks man

    Reply  |  Quote
  4. Pingback: Set up a home linux server for $30 with PogoPlug | Terminally Incoherent UNITED STATES WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *