How do clients connected to a LAN network with a NAT router connecting the network to the internet, identify the NAT router
Typically this information is received during DHCP. DHCP works by broadcasts so it doesn't depend on knowing the IP address of any server to work (consequently, things like rogue DHCP servers can be a problem.)
DHCP can hand out many types of information for hosts to use, one of those is obviously the IP address, and the "router" or default gateway is another. Also typically handed out is the IP address of a DNS server or two.
and hence know where to send their traffic for the wider internet.
The typical way a computer's TCP/IP stack works is this:
- Does the IP address of this outgoing packet fall within the subnet mask of any network interfaces?
- If so, send it out of that network interface to that IP directly (no router involved).
- Otherwise, send the packet to the default gateway.
If your network interface's IP is set to 192.168.55.8, and its subnet mask is 255.255.255.0, then if your system wants to send traffic to any IP from 192.168.55.1 to 192.168.55.254, it will send it to that IP directly out of that NIC.
If you had a second network interface whose IP was 192.168.72.8 and its subnet mask was 255.255.255.0, then if your system wants to send traffic to any IP from 192.168.72.1 to 192.168.72.254, it will send it to that IP directly out of the second NIC.
If the destination IP range doesn't fall within any NIC's subnet ranges, it will send the packet to the default gateway (not changing the destination IP), which is expected to be a router that will resend the packet to the final destination or one hop closer.