These are two different things. Setting entries in the hosts file overrides name lookups (ie. DNS). Static routes refers to IP routing.
Here is a brief overview of the process that can hopefully help with your research:
A computer is plugged into the network and communicates with the DHCP server to get an IP address and a variety of other options, including subnet mask and default gateway. Lets assume your IP/subnet is 10.0.0.215/24
, and your router is 10.0.0.1
.
That computer then tries to go to https://google.com. A few things happen here (some steps are omitted for simplicity).
- Your computer reaches out to the DNS server and asks where to find google.com.
- The DNS server responds with one or more addresses. Lets use
142.250.138.139
as an example.
- Your computer sees that
142.250.138.139
is not within the 10.0.0.215/24
subnet, and sends that packet to your router instead (10.0.0.1).
- Your router then reaches out on the WAN to continue routing the packet through your ISP's network until it reaches the destination.
The hosts file overrides steps 1 and 2. Static routes override step 3.
Now lets say you have two networks: 10.0.0.0/24
and 192.168.1.0/24
. Router A (10.0.0.1
) doesn't know about 192.168.1.0/24
, but another router on your network does. We'll call this router B, and it is connected to both networks on 10.0.0.200
and 192.168.1.200
. If you want your computer at 10.0.0.215
to access computer B at 192.168.1.10
, you need a static route. Your computer somehow needs to know that it should send traffic destined for 192.168.1.0/24
to 10.0.0.200
instead of 10.0.0.1
. This is what the static routes option (DHCP option 33) can accomplish.