I can't find how/where the LAN ip is connected to my machine name such that anyone typing the machine name (host name) will be directed to the IP. I know the machine name is under /etc/hostname/
but how is this name linked to the LAN-IP?
2 Answers
If you haven't taken steps to assign a particular hostname to a particular IP address, it might not be linked at all.
On the internet and enterprise networks, DNS (Domain Name System) is the standard service that ties the names to IP addresses. There are many ways to manage DNS records: they might be managed completely manually, or a DHCP server might be configured to communicate with DNS server to automatically manage DNS records for systems that are getting their network parameters via DHCP, or a Dynamic DNS (DDNS) protocol might be used to allow client hosts to register their own names... or any combination of these approaches. DNS uses both TCP and UDP with port number 53.
In a simple home network, you might not want to make the effort of setting up your own DNS server. Instead, most Linux and MacOS systems now support mDNS (multicast DNS). That requires two components: a system that wishes to be known by other systems must periodically announce itself to the local network segment. In Linux, this is usually done by avahi-daemon
. The other component would be a mDNS resolver; in Linux that can be a plug-in resolver module (e.g. mdns_minimal
or mdns
in /etc/nsswitch.conf
), or built into systemd-resolved
if you use it. mDNS uses UDP only since it's a multicast-based protocol, and it uses port number 5353.
And of course, there's the old-school way of editing the hosts file of each system you have, and adding the IP addresses and corresponding hostnames of each of your systems to each of those files (/etc/hosts
in Linux and MacOS, \Windows\System32\Drivers\etc\hosts
in Windows).
-
1Another possible component is netbios (
samba
/nmblookup
). Commented May 30, 2021 at 22:34 -
@EduardoTrápani Yes, but the usefulness of NetBIOS is diminishing as Microsoft is deprecating SMBv1, which includes NetBIOS. For now you can still manually re-enable SMBv1 but since the deprecation was accelerated for security reasons it's definitely not recommended unless absolutely necessary. The new Windows-compatible replacement protocol for the NetBIOS browsing functionality is WS-Discover; unfortunately it's not yet integrated with Samba but a stand-alone helper project exists.– telcoMCommented May 30, 2021 at 22:47
-
but wouldnt assigning a name to every computer's IP interfere with the DHCP from the router?– user390930Commented May 31, 2021 at 7:06
-
DHCP server may either attempt to dictate what each DHCP client should call itself, or accept the hostname given by the client. If your router also includes a DNS server and it's integrated with the router's DHCP server, then the router's DNS server might also automatically make the information about the registered name of each client and its associated IP to other hosts in your network. But if it doesn't do that (well enough for your requirements), then you may have to replace one or both of those services of the router with your own implementations.– telcoMCommented May 31, 2021 at 7:31
-
For example, you could set up a RasPi as a DHCP and/or a DNS server, disable the respective services from the router, and run your own services in the RasPi. If you want to take over just DNS, you would need to configure the router's DHCP to give the clients the RasPi's IP address as the DNS server address; this is usually doable. You would then be responsible for making sure your DNS server can connect to other DNS servers as needed to resolve any internet hostnames you'll want to connect to.– telcoMCommented May 31, 2021 at 7:46
The LAN IP address is assigned by your Router. It is assigned through what is known as DHCP. You can see what IP Address is assigned by running the following command: ifconfig -a
The line starting with `inet enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.2.100 netmask 255.255.255.0 broadcast 192.168.2.255
By using the following command you can get your current hostname:
hostname MY-LAPTOP
If you want to let other computers on your network you must use the /etc/exports file (on my Fedora system at least) Entries will look like: /STUF/STUFF 192.168.2.103(rw,sync,no_subtree_check) # Use the IP Address of OFFICE1 Client Wired. /STUF/STUFF 192.168.2.104(rw,sync,no_subtree_check) # Use the IP Address of LENOVO-WIFI Client Wifi.
maybe this can help a bit. I use these files in a NFS system I use in my network.
-
/etc/exports
has absolutely nothing to do with name resolution. It's a config file for an NFS server telling it what directories other machines are allowed to access. Name resolution is done by a name resolution service such as DNS or Bonjour/Zeroconf/Avahi/mdns or YP/NIS or LDAP (or other, weirder stuff configured via /etc/nsswitch.conf and installing libnss modules). Most commonly DNS and mdns these days.– casCommented May 31, 2021 at 4:11 -
thanks for your effort and sharing the knowledge. it's not an answer but still quite interesting– user390930Commented May 31, 2021 at 6:59