how does my router know about my hostname and how to find out others computer's hostnames?

I have a cisco router by which I connect my 2 pcs running ubuntu to the internet. I get the ip address by DHCP. When I check the list of pcs connected to the router, the router admin page shows ip addresses alongside hostnames. It seems that by using DHCP the router has somehow been able to catch the hostnames from "/etc/hostname" or /etc/hosts", am I right? The thing is that if I change the name of my pc by editing the file "/etc/hostname" and even "/etc/hosts", the router still stores the previous hostname, even when reset, how can I make the router store the updated hostname?

On the other hand, how can I find out the hostnames of the computers connected to my network? nmap doesn't seem to do the job. Do I have to set up a domain for all the computers in the network? How could I do this?


Solution 1:

When your PC is turned on, it uses the DHCP protocol to request an IP address and network settings, and part of the information provided by the PC is its name. The DHCP server remembers this and adds it to its internal DNS database. This works when the same computer (your Cisco router) acts as both DHCP and DNS server.

See DHCP (Dynamic Host Configuration Protocol) Basics

 DHCPREQUEST 
 …
 DHCP: Host Name              = JUMBO-WS

Or MS Technet: Appendix D: DHCP Packets

DHCP Request

The remainder of the frame (300 or 548 bytes) is the DHCP Discover portion. Its details include:

- The Host Name - lists the computer name of the client computer.