The OSI model is kind of conceptual -- the layers don't always correspond directly to the structure of a network packet. A TCP packet has 3 headers:
+-+-+-+-+-+-+-+-+--+- | Ethernet header | +-+-+-+-+-+-+-+-+--+- | IP header | +-+-+-+-+-+-+-+-+--+- | TCP header | +-+-+-+-+-+-+-+-+-+-+ | packet contents | +-+-+-+-+-+-+-+-+-+-+
the Ethernet header contains a source/destination MAC address. A switch can use that MAC address to send packets to the device with the matching MAC address.
"layer 3" means "IP". Routers on the internet use a packet's IP address to decide which router to send the packet to next.
layer 4 load balancers will take TCP/UDP packets and forward them to another machine. For TCP connections, they need to keep track of what's in the connection and forward the entire TCP stream to the same machine.
layer 1 is the "physical layer" -- it's the wireless signals / network cards / cables that allow the bytes in a packet to be sent from one device to another
For example, a layer 7 load balancer will use the Host:
header to determine which website to serve.
the port is in layer 4. network equipment that's responsible for handling a certain layer usually leaves information in higher layers alone.
the MAC address is in layer 2. when a router sends a packet to the next hop, it often needs to set the MAC address to the address of the machine it's sending the packet to.
in general, changing lower layers is fair game. For example, a HTTP load balancer will usually change the IP address.
in general a TCP or (layer 4) load balancer only changes the lower layers, (like IP address / port). It won't look at the contents of the TCP stream being forwarded at all.
2 common uses for this:
in real life people only really talk about layers 1, 2, 3, 4, and 7. If you Google you'll find TONS of results for "layer 4 proxy" and "layer 7 proxy" but basically none for 5/6.