如何仅通过主机名而非hostname.local访问Ubuntu Server
Hey there, let's work through this hostname issue together. Since you can reach ubuntuserver via its IP and ubuntuserver.local (which relies on mDNS/Avahi), but not just the bare ubuntuserver hostname, here are targeted fixes based on your multi-OS setup:
1. Fix Windows Hosts (firstwin/secondwin) Resolution
Windows uses NetBIOS/WINS or LLMNR to resolve bare hostnames by default, and Ubuntu Server 16.04 doesn't include the required Samba components out of the box to respond to these queries.
- Install the necessary packages:
sudo apt-get update && sudo apt-get install samba winbind - Restart the NetBIOS name service to apply changes:
sudo systemctl restart nmbd
After this, your Windows machines should be able to resolve ubuntuserver directly using the bare hostname.
2. Fix Ubuntu Desktop (ubuntudesktop) Resolution
Ubuntu 17.10 typically uses systemd-resolved which supports LLMNR (Link-Local Multicast Name Resolution) for local hostname resolution. Let's ensure your server has LLMNR enabled:
- Edit the systemd-resolved config file:
sudo nano /etc/systemd/resolved.conf - Find the
LLMNRline, uncomment it, and set it toyes:LLMNR=yes - Save the file (Ctrl+O, Enter) and exit (Ctrl+X), then restart the service:
sudo systemctl restart systemd-resolved
If that doesn't work, check if your local router supports DHCP-based DNS registration. Ensure your server sends its hostname to the DHCP server:
- Edit the DHCP client config:
sudo nano /etc/dhcp/dhclient.conf - Make sure this line exists (uncomment if needed):
send host-name "ubuntuserver"; - Restart networking to apply:
sudo systemctl restart networking
3. Double-Check Hosts File Details
Even though you mentioned your hosts file is correct, it's worth verifying the server's /etc/hosts has a line mapping its local IP to the hostname, like:
192.168.x.y ubuntuserver
This ensures the server recognizes its own hostname locally, which can help with some resolution flows.
4. Test to Diagnose Further
If the above fixes don't work, run these tests to narrow down the issue:
- On
ubuntudesktop, rundig ubuntuserverornslookup ubuntuserverto see if a DNS server is returning an IP. If you getNXDOMAIN, DNS isn't resolving the hostname. - On a Windows machine, run
nbtstat -A <ubuntuserver-IP>— if you seeubuntuserverlisted, the NetBIOS service is working; if not, recheck the Samba installation.
内容的提问来源于stack exchange,提问作者alculete

