Does NAT Map to the MAC Address, or to the Local IP

dhcpnat;router

I would like to set up NAT to put a service on internet using my Technicolor TG 582 router. I mention the specific router model just to have a reference, but the question goes in general as I may need to use this programming with different routers.

I would like to have the DHCP server assign addresses to the services, but at the same time, use NAT to point to the services.

I have been told by colleagues that if you let DHCP assign the IP to the device, the specific NAT rule will eventually fail, as the DHCP server on the router will, over time, change the assigned local IP, invalidating the NAT port link–which is to the local IP, not to the MAC (physical) address of the device.

Based on this information my practice has been to use a static IP for any services behind the router that are to be accessed from outside. However apparently the router sometimes "identifies" a device by its MAC, and other times by its local IP. My own logic tells me the router should "route" or NAT the specific port request from the outside to the MAC address where I have the service, and not to the IP.

So which is it? The second part of the question would be, if the DHCP server restarts, or, for example, the client device goes offline, then comes back on, will the DHCP server try to maintain the previous local IP assigned to the device, or will it just pick the next available IP?

Best Answer

To answer the question asked:

NAT is a layer 3 networking effect - it happens when packets are routed, whereas MAC addresses are a layer 2 network aspect - they are only meaningful on the local network. So to answer your question, you cannot NAT to a MAC address - the notion of NAT cannot work across layers.

To answer the actual question (how can I use DHCP and ensure NAT still works):

You just need to reserve your IP address in DHCP so that it doesn't change over time. This is bound to the MAC address of your machine. So and tells the DHCP server that if a request for an IP address comes from a specific MAC address, it should be assigned a specific IP address.

Related Question