Hosts file can only be used to associate a domain name with an IP; it cannot map IP to IP.
Altering IPs can be done by a firewall. On Linux, the default firewall is controlled by iptables commands. "man iptables" is the documentation. Google "explain iptables" for introductory explanations.
Specifically, you want to change OUTGOING requests from your PC to an IP address (
<my_ip_address>), so that they instead go to a different IP address, in this case 127.0.0.1. You want to perform NAT (Network Address Translation), given the "destination IP" (
<my_ip_address>; e.g. 188.8.131.52), changing it to a different "destination IP" (127.0.0.1).
Try this (in place of 184.108.40.206, put the ip_address that needs to be altered):
iptables -t nat -A OUTPUT -p all -d 220.127.116.11 -j DNAT --to-destination 127.0.0.1
-t nat = table for translating one address to another
-A OUTPUT = append to the list of rules for locally-generated, outgoing, packets. SECURITY WARNING: Make sure the rule includes this OUTPUT directive. If you don't, the rule would create a possible security hole, because matching Incoming packets from remote locations would also be directed to localhost.
-p all = apply to all protocols (tcp, udp, and icmp).
-d 18.104.22.168 = the original IP address that the packet was going to (its destination).
-j DNAT = if the rule matches (in this case, if an outgoing packet has destination IP 22.214.171.124), then handle it with DNAT, which alters the destination.
--to-destination 127.0.0.1 = tells DNAT what to do; replace the original destination with "127.0.0.1".
(NOTE: If you had a more complex situation, such as intercepting requests for specific web pages, an alternative solution might be to use "proxy" software.)