Often I’ll run into a situation where I need to make an HTTP request for a host name against a server that is at a different IP address than the one the host name resolves to. A common reason for this is to test out changes against a sandbox before deploying the change to production.
curl --resolve google.com:443:18.104.22.168 https://www.google.com/
Internally curl will make sure that google.com resolves to 22.214.171.124 for the purposes of that request. No need to mess around with hosts files or anything else.
For more suggestions in this area check out curl another host.