Networking – What’s the difference between DHCP and NAT? Are they mutually exclusive

dhcpnat;networkingrouter

I know this is a rather basic question, but I'm struggling to find sources online to clarify it.

As I understand it, in NAT, the router which connects the private network to the public internet has one IP address, which all traffic for the private network is directed to; the router then uses port numbers to figure out which device on the private network the traffic is for. In contrast, with DHCP, each device on the network is assigned it's own public IP address which traffic for it is directed to.

My confusion stems from hearing that both can be used simultaneously, which seems to contradict the idea that with NAT, there is only one IP address for the entire private network whereas with DHCP, there is an IP address for each device on the network. If they are mutually exclusive, where is each typically used?

Please feel free tear apart the above statements if you think it will help :).

Edit: The answer below explains it really well – I was being dumb and not realising that DHCP can assign any "type" of IP address, it's just a protocol for devices to join a network?

Best Answer

NAT is a way to translate traffic in several ways. The simplest in home routers is to make everything seem like they’re behind the same IP address. This means any outbound connection from the local network is taken in, its source address is set to the router’s public address, a new port is allocated and the modified packet is sent forward. When there’s a packet back the same thing is done in reverse and the packet is sent to the original device.

NAT doesn’t need to be between private and public networks. It can also be between two public networks or two private ones. It just diverts traffic and doesn’t know anything about public or private.

DHCP is completely unrelated to this. It is a way for devices to shout to the local network asking for an IP address and other related information (like the gateway address, name servers etc) to be given to them. Again, a home router usually has a server to serve the clients in the local network. Without a DHCP server you’d need to set all IP addressed by hand to each device (or use the automatic IP system in Windows, for example, but that is only for local networks, not internetworking). The devices can not communicate using IP unless they have IP addresses and since practically all communications is over IP it’s needed.

The IP address given isn’t necessarily public. Maybe this causes the confusion to you. It’s any address that’s defined in the DHCP pool, or maybe even a static one for that specific device.

So you can have DHCP allocating IP addresses and never use a NAT. It just gives IPs from the pool and that’s that. You can also have NAT without DHCP. You can set fixed IPs, or you can use NAT to divert traffic through a firewall to some other machine etc. It doesn’t need anything from DHCP.

In home networks both are useful since there’s pretty much always only one external IP and users don’t want to manually set fixed IP addresses. So DHCP gives them local private IPs and NAT translates connections so that they look like they come from the same address.

Related Question