局域网中window可以解析hostname,而linux却不可以?

场景如下:
小型局域网,有数台ubuntu,hostname为ubuntu01,02….等等(ubuntu上都装了SAMBA ),其他都是windows。在windows上可以通过hostname(例如ubuntu03)ping通其他主机,而在linux上则不行。如下图,

局域网中window可以解析hostname,而linux却不可以?

局域网中window可以解析hostname,而linux却不可以?

找到些有用的信息,

Windows uses NetBIOS names, and such protocol, being a broadcast one, allows them to find each other without any central server.

Linux machines in modern distros uses natively a protocol called Avahi, which is also a server-independent, broadcast protocol. Local network machines have a suffix .local, so you can ping from Linux to Linux using ping hostname.local, or see them with avahi-discover package. some apps in Gnome use avahi to list machines in the network (for example, the Remote Desktop Viewer)

Installing SAMBA on a Linux machine will assign it a NetBIOS name (or, more technically, will make a Linux machine advertise itself in broadcast requests with their NetBIOS name, which is by default their hostname), and that allows Windows machines to find the Linux ones.

Gotcha: Although Linux machines with Samba will reply to NetBIOS protocol requests, with default settings in distros like Ubuntu it won’t use NetBIOS as a method to resolve names, and that’s why Linux machines can’t “see” each other or the Windows machines. For that, you need to edit /etc/nsswitch.conf file and add wins to the list in this line:

hosts:          files mdns4_minimal [NOTFOUND=return] dns wins mdns4

You may need to install winbind package for the above to work.
So, for the visibility issue, you either install Samba on all Linux machines (and also edit /etc/nsswitch.conf to enable NetBIOS name resolution), or you install Avahi support in Windows machines.

As for file sharing, Samba provides Linux machines file-sharing capabilities with Windows. Theres no need to edit /etc/nsswitch.conf for Linux machines to see shared folders of each other and Windows (and vice-versa) in the “Network” section of Nautilus

上一篇:linux – 使用scp复制文件:连接超时


下一篇:WSL设置Ubuntu主机名