As I understand, the hosts file only works for capturing traffic from the computer where the hosts file is located.
No.
First, host name resolution happens when a packet is dissected, not when it's captured, and a capture may be done on one machine and the file read by Wireshark or TShark on a completely different machine, so there's no guarantee that the name resolution will be done on the machine on which the capture is done.
Second, the hosts file is not the system hosts file on the machine on which you're running Wireshark or TShark. There can be two hosts files, the contents of which are combined - a "global" hosts file for Wireshark, installed in the "data file directory" for Wireshark (on macOS, that directory is in the Wireshark application bundle; on Windows, it's in the directory containing the Wireshark executable; on UN*Xes other than macOS, it's probably a directory under /usr
or /usr/local
- it's not, for example, /etc
on UN*Xes), and a "personal" hosts file, stored in the Wireshark preferences directory or in a profile directory under that directory. Current versions of Wireshark/TShark don't use the system host file to do any name resolution, it just uses DNS, name entries stored in pcapng files, and its own host files.
So it will use whatever host file you supply, as per cmaynard's answer, and that will be used for all captures, regardless of what machine the capture was performed on.
"Static" meaning "not using DNS", for example, "using a file"?
Hi! Yes! I am not capturing traces on my computer/network. I am transferring traces to my computer that have been captured on private networks for the purpose of troubleshooting different issues. So their IPs belong to their private internal network, they are different elements(actually they are core equipments in telecom networks). These traces are captured by probes, so there are many nodes in a trace. It would help me to be able to see hostnames instead of IPs, now I have to look at a packet and then just look up that IP in a file to see what I am looking at. So I want to use this mapping file that I could create and somehow be able to see in Wireshark the hostname as well. As I understand, the hosts file only works for capturing traffic from the computer where the hosts file is located.