Sometimes a printer and/or the router do not properly register their name with the DNS service.
Option 1 (preferred): Add your printer’ IP address in DHCP reservation page on your router.
Option 2: Configure printer with static IP address, and add that address in “hosts” file on each and every PC.
Sometimes option 1 (above) still needs the help of a hostfile entry.
Location of the hostfile:
Windows 10 – “C:\Windows\System32\drivers\etc\hosts”
Linux – “/etc/hosts”
Mac OS X – “/private/etc/hosts”
On Windows, find the Notepad icon, right-click and select run as administrator. File > Open, and navigate to the path above. Select “All” from the file type to see the file named hosts.
On a new blank line, enter ip address followed by a space then the hostname
For example:
192.168.1.50 HP4200
Save the file. You may have to flush your computer’s dns by running this command at the command prompt:
ipconfig /flushdns
Sources:
https://forums.tomshardware.com/threads/cant-ping-hp-printer-by-hostname.3295319/
https://www.liquidweb.com/kb/edit-host-file-windows-10/