{"id":3728,"date":"2022-03-17T00:20:13","date_gmt":"2022-03-17T08:20:13","guid":{"rendered":"https:\/\/wonghoi.humgar.com\/blog\/?p=3728"},"modified":"2022-03-17T00:52:39","modified_gmt":"2022-03-17T08:52:39","slug":"ubuntu-cannot-ping-windows-hostnames-out-of-the-box-resolving-netbios-announcements","status":"publish","type":"post","link":"https:\/\/wonghoi.humgar.com\/blog\/2022\/03\/17\/ubuntu-cannot-ping-windows-hostnames-out-of-the-box-resolving-netbios-announcements\/","title":{"rendered":"Ubuntu cannot ping Windows hostnames out of the box (resolving NETBIOS announcements)"},"content":{"rendered":"\n<p>Out of the box, Ubuntu cannot resolve hostnames announced by Windows out of the box. <\/p>\n\n\n\n<p>The internet had many solutions from ditching NETBIOS (winbind, wins) but it involves replacing <code>systemd-resolved<\/code> with the old NetworkManager (systemd-resolved was an extra level of indirection to break VPN ties), which I illustrated in this now deprecated <a href=\"https:\/\/wonghoi.humgar.com\/blog\/2019\/09\/01\/systemd-resolved-dns-resolution-nightmare\/\" data-type=\"post\" data-id=\"1920\">blog post<\/a>. <\/p>\n\n\n\n<p>Having router assign host names you specify often included a <strong>local<\/strong> domain name (must not choose one that conflicts with the internet) such as <code>local<\/code> or <code>lan<\/code>. So the computers are accessed in the format of <code>myPC.local<\/code> or <code>myPC.lan<\/code> depending on the local domain name you picked. However, it doesn&#8217;t take advantage of the hostname announced by Windows computers.<\/p>\n\n\n\n<p>I decided to give the NETBIOS service a second research today and found the missing link to the common solution of installing <code>winbind<\/code> and adding <code>wins<\/code> entry to <code>host<\/code> search order in <code>\/etc\/nsswitch.conf<\/code> (you can put it at the end or earlier if you want). I put it at the end as I wanted it to be the last resort<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">hosts:          files {a bunch of things depending on your system} wins <\/pre>\n\n\n\n<p>Of course having a <code>wins<\/code> entry in the <code>hosts<\/code> search order involves installing winbind make sure the winbind service is running<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install winbind<\/pre>\n\n\n\n<p>The <a rel=\"noreferrer noopener\" href=\"https:\/\/askubuntu.com\/a\/27548\" target=\"_blank\">missing piece<\/a> is editing <code>\/etc\/samba\/smb.conf<\/code> to inject a name resolve order list after installing samba and winbind:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">name resolve order = wins lmhosts bcast<\/pre>\n\n\n\n<p>You will need to install <code>samba<\/code> package first if you haven&#8217;t already installed it (for sharing folders with Windows)<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install samba<\/pre>\n\n\n\n<p>The post said the <code>name resolve order<\/code> section was commented out, but in newer version of samba, the line is simply non-existent. You&#8217;ll have to add it somewhere in <code>\/etc\/samba\/smb.conf<\/code>, I chose to put it right at the beginning of <code>[global]<\/code> section.<\/p>\n\n\n\n<p>Restart the services after editing to reflect the changes and you can start pinging!<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart nmbd smbd winbind<\/pre>\n\n\n\n<p>So in the process above (installing <code>samba<\/code> and <code>winbind<\/code> and editing nsswitch.conf), you&#8217;ve also enabled linux to announce its hostname to Windows, which I&#8217;ve discussed in this blog <a href=\"https:\/\/wonghoi.humgar.com\/blog\/2021\/03\/04\/linux-setup-notes-hostname-to-communicate-with-windows-computer\/\" data-type=\"post\" data-id=\"2352\" target=\"_blank\" rel=\"noreferrer noopener\">post<\/a>.<\/p>\n\n\n\n<p>So to summarize the concepts, <\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>You need to install winbind to add wins to host search list in nsswitch.conf, but it doesn&#8217;t do you anything yet!<\/li><li>Once you installed samba, your linux computer start announcing its hostname to Windows computers<\/li><li>To be able to use the hostnames announced by Windows, i.e. the other direction, you&#8217;ll need to add the <code>name resolve order<\/code> line to <code>smb.conf<\/code> (samba config file) and restart <code>samba<\/code> and <code>winbind<\/code>.<\/li><\/ol>\n\n\n\n<p><\/p>\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_3728\" class=\"pvc_stats all  \" data-element-id=\"3728\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Out of the box, Ubuntu cannot resolve hostnames announced by Windows out of the box. The internet had many solutions from ditching NETBIOS (winbind, wins) but it involves replacing systemd-resolved with the old NetworkManager (systemd-resolved was an extra level of &hellip; <a href=\"https:\/\/wonghoi.humgar.com\/blog\/2022\/03\/17\/ubuntu-cannot-ping-windows-hostnames-out-of-the-box-resolving-netbios-announcements\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_3728\" class=\"pvc_stats all  \" data-element-id=\"3728\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/wonghoi.humgar.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[39,4],"tags":[],"class_list":["post-3728","post","type-post","status-publish","format-standard","hentry","category-linux","category-windows"],"_links":{"self":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/3728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/comments?post=3728"}],"version-history":[{"count":14,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/3728\/revisions"}],"predecessor-version":[{"id":3748,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/posts\/3728\/revisions\/3748"}],"wp:attachment":[{"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/media?parent=3728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/categories?post=3728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wonghoi.humgar.com\/blog\/wp-json\/wp\/v2\/tags?post=3728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}