1

I wrote a program that does packet communication with a server and something has been in the back of my head for sometimes : When I analyze packets with WS I can see in the header first off two MAC addresses. One is my laptop MAC and the other one seems to be my router's MAC (would you please confirm) while I would have assumed that the other MAC would be the server's MAC.

The ip versions of the conversation I use is ipv4. the source ip is my IP under the network (which I have no problem with) however the destination ip is the server's IP which at first I was fine with, but now that I believe the MAC is my router's I would have assumed the destinaton IP to be my router (but then how would my router know when to send the packet.. so yeah.).

I have browsed around and I couldn't find what I wanted to discover which is when are the packets edited on the fly, if they are. When I received a packet the destination is my laptop's MAC and the sourc is my router's MAC which only makes sense if the packet was modified by my router when he received it, assuming then that the server doesn't even know my laptop's MAC. Then I guess that between the server and my router, the packet's IPs are 1/server ip and 2/router ip, but once the packet reaches the router the router's ip is replaced by my laptop's ip under the network, yes ?

If you could confirm or deny those assumptions and maybe point me to a website which holds these infos I'd be very gratefull.

1
  • I wrote a article series that discusses everything that happened to get a packet from one server to another, whether through a switch, or router, or directly. I think you would find it helpful. You can read it here: Packet Traveling.
    – Eddie
    Commented May 6, 2016 at 21:17

1 Answer 1

1

You need to understand that a layer-2 frame, which contains the MAC addresses, is only good on the LAN on which it was created. On that LAN, it will not be modified (except that a trunk may add a VLAN tag, for the trunk only).

Layer-3 devices, like routers, strip off the layer-2 frame to get to the layer-3 packet. When the router sends the packet out a new interface, it will create a new frame for the new link. Depending on the layer-2 protocol on the new link, there may or may not be MAC addresses. If it is a protocol which uses MAC addresses, the new frame will have the router's MAC address of that interface for the source address, and the next hop MAC address on that LAN for the destination MAC address. This happens at each hop since the MAC addresses are only valid for the LAN where the MAC address is connected.

Your host will encapsulate the packet in a frame with its MAC address as the source address, and the server's MAC address as the destination address only if the server is on the same layer-2 LAN. If a packet is destined for a different layer-3 network, the destination MAC address in the frame is the MAC address of the gateway configured in your host.

IP addresses in a packet don't change unless you have NAT configured somewhere in the path. One of the primary drivers for IP was end-to-end connectivity that NAT breaks. NAT is a kludge to conserve IPv4 addresses until we can get converted to IPv6.

2
  • Okay, so my router hides both my laptop's MAC and my laptop's network ip (which I however see on WS) and depending on the level 2 layer protocol the router sometimes gives its own MAC. You haven't talked about ips but it's fair to assume router always hides laptop's ip and always shows the router's ip (so that the server knows where to answer). I guess this makes sense as the internet traffic would otherwise be significantly higher because of useless infomation. Thank you. Commented May 6, 2016 at 15:28
  • IP addresses in a packet don't change unless you have NAT configured somewhere in the path. One of the primary drivers for IP was end-to-end connectivity that NAT breaks. NAT is a kludge to conserve IPv4 addresses until we can get converted to IPv6. A layer-3 device, like a router, will always strip off the layer-2 frame for packets which traverse it.
    – Ron Maupin
    Commented May 6, 2016 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.