TechKnowSurge
Cisco CCNA 3.1 Cisco CCNA 3.2 Cisco CCNA 1.13 Cisco CCNA 1.6
VideoNetworkFree

L2 and L3 Walkthrough

A detailed walkthrough of how data travels across a multi-device network, tracing the full path of an SSH connection through Layer 2 and Layer 3 processes including routing table lookups, ARP resolution, and frame encapsulation.

Complete this video to capture a CTF flag worth 1 point.

About this video

Routing tables are not exclusive to dedicated routers. Layer 3 switches and end-user devices such as laptops also maintain routing tables, and every outbound packet is evaluated against that table to determine where it should be sent. When a destination address falls outside the local subnet, the packet is forwarded to the default gateway, but before that can happen the sending device must resolve the gateway's MAC address through an ARP broadcast. This ARP exchange also allows intermediate switches to populate their MAC address tables, mapping source addresses to specific ports for efficient frame forwarding. As a packet travels through the network, each Layer 3 device, whether a Layer 3 switch or a dedicated router, receives the incoming frame, verifies its integrity using the frame check sequence, and strips the Layer 2 header before consulting its own routing table. The device identifies the longest matching route, determines the next hop, and issues a new ARP request if the next hop's MAC address is not already known. A new Layer 2 header and trailer are then constructed and attached to the existing IP packet before it is forwarded, with the specific Layer 2 protocol depending on the link type, Ethernet on LAN segments, PPP or HDLC on serial WAN connections. This process repeats at every hop along the path. The IP header persists throughout the journey, with only the time-to-live field and checksum updated at each router, while the Layer 2 encapsulation is rebuilt from scratch at every hop to suit the outgoing interface's link protocol. Once the packet reaches the final router, a last ARP request resolves the destination device's MAC address, the packet is delivered into the local network, and the destination device processes the payload. In the case of an SSH connection, a TCP handshake completes the session establishment. The entire sequence, spanning multiple devices that may be thousands of miles apart, occurs in fractions of a second.

What you'll learn

What's covered

Layer 2 & 3 Walkthrough

Aligned to

Cisco CCNA
3.1 Interpret the components of routing table
3.2 Determine how a router makes a forwarding decision by default
1.13 Describe switching concepts
1.6 Configure and verify IPv4 addressing and subnetting

Key terms

Packet
A unit of data formatted for transmission over a network, containing a header, payload, and sometimes a trailer.
Router
A network device that forwards data packets between networks based on IP addresses.
Routing Table
A database stored in a router that lists known network destinations, the metric (cost) to reach them, and the next-hop address or outgoing interface to forward packets toward those destinations. Routers consult this table for every packet they forward.
Default Gateway
The router that a device uses to send traffic to destinations outside its local network.
Address Resolution Protocol
ARP
A protocol used to map an IP address to a physical MAC address on a local network.
Media Access Control
MAC
A sublayer of the Data Link layer that controls how devices on a network gain access to a medium and transmit data.
Layer 2
The Data Link layer of the OSI model, responsible for MAC addressing and frame delivery on a local network.
Layer 3
The Network layer of the OSI model, responsible for logical addressing and routing packets between networks.
Encapsulation
The process of wrapping data with protocol headers as it passes down the layers of the OSI model.
Point-to-Point Protocol
PPP
A data link protocol used to establish a direct connection between two nodes.
Switch
A network device that connects devices within a LAN and forwards traffic based on MAC addresses.
Time to Live
TTL
A value in a packet that limits its lifespan on a network, preventing it from circulating indefinitely.

Topics

Networking Osi Model Packet Routing Arp Layer 2 Switching Frame Encapsulation Ssh

Transcript

We've taken a much more in-depth look into the router and how the router routes information. We've talked about routes, and we've talked about routing tables. This layer 2 and layer 3 walkthrough is a summary of a lot of the concepts we've learned up until now, so let's step back and see the big picture.

Every device has a routing table

We know that our routers have routing tables, but remember, our layer 3 switch is a routing device as well, and it has a routing table too. So does our PC. When we get onto our PC we can do a route print and see all of the routes that are on our PC, so our laptop has a routing table on it as well.

Let's talk about how this demo laptop would send, let's say it's trying to create an SSH connection to this switch right here. What would that look like, and what would be the process that it would go through?

Building the routing table and finding the destination

First of all, it needs an IP address. The management IP address of this machine over here is 10.2.0.5, so that's where it's trying to get to. Now what it does is it builds this routing table, and one of the things it will do is a process called ANDing. It does ANDing with what its IP address is and what its network mask is, to figure out what network, what local area network, it's on — and it's on VLAN 10. So one of the first things that happens when you turn on a machine is it will build this routing table on this machine right here.

Then any packets that are being sent out from it, it's going to compare the destination IP address — in this case 10.2.0.5 — to its routing table, and then it's going to find where it should send it. In some cases it's just the local network, and then it needs to send it on its local network, specifically to that specific MAC address. Other times it's going to be on another network. Remember, if it's sending to demo Pi 1, that's on the same network, but if it's sending to demo Pi 2 or 3, those are on different networks.

If it's going to another network, what it's going to find is the longest match on the routing table, and look at where it's supposed to be sent to. In many cases it's going to be sent to the default gateway, and that's what we're going to for this one right here. Since it is a network that's outside the realm of VLAN 10, it already knows that it needs to send this packet to the default gateway.

ARP: finding the MAC address of the default gateway

But what is the MAC address of the default gateway? What it will need to do is find out what the MAC address of the default gateway is. For this machine right here it's 10.1.10.34, and its default gateway is 10.1.10.1, which is the IP address that's on this layer 3 switch.

So it's going to try to reach this layer 3 switch. What it will do is send out an ARP request, an address resolution protocol request, because what is set up on that machine is a default gateway, and that default gateway is 10.1.10.1. Since it needs to send it to its local area network, it needs to find out the MAC address that it's going to send it to. So it's going to form an ARP request and send it out, and that ARP request is going to say, hey, what is the MAC address of 10.1.10.1? It will broadcast that out.

What this switch is going to do is see that that's part of VLAN 10, and it's going to broadcast it out on VLAN 10, to include this trunk line. It's going to make it up to this switch, and this switch is going to take that in on VLAN 10 and say, oh, that's looking for 10.1.10.1, I will go ahead and reply to that. So it will send out a reply and say, I am 10.1.10.1, and here is my MAC address.

So now this machine right here is going to have the MAC address of the default gateway, and it's going to have an IP address of this switch over here, which is 10.1 — excuse me, 10.2.0.5. That is the information that it's going to use to build the packet.

What the switches learned along the way

One thing to note about when this ARP request and process took place: the frame that was sent through switch 2 — switch 2 recorded the source MAC address from that frame, and so it knows what port this laptop is on, and it is port 34. So it knows that this demo laptop is on port 34. Also, when the response came back from switch 1, switch 1 had sent a response that came in on a port, and it recorded that as well. It is port 47, and it knows that switch 1, or at least the MAC address that came across, is on port 47, and it will record that in the MAC address table.

Building and sending the SSH request

Now that it has the information, it's going to create the request. If this is an SSH request, somewhere in that payload is going to be the SSH information on making the request. This has an SSH client on here, and this has an SSH server on here, and the SSH server is going to have port 22 open on this device, so it'll be listening on this device.

So what this demo laptop will do is send out a request to this switch over here, and it's going to be an SSH request. It needs to create that IP information, and the destination IP address is going to be the IP address of this server right here, so it will include that in the destination IP address inside of that packet.

Now it's formed this packet, but it needs to send this packet across the local area network so that it can get to the default gateway on switch 1. It's going to be sent across this ethernet connection. Switch 2 will take a look at the destination MAC address and say, I know what port that is on, that came in on port 47, so I'm going to send it out port 47, I'm going to forward it on to that next switch.

The layer 3 switch routes it on

Switch 1 is going to receive that. It's going to take a look at the destination MAC address and say, oh, that belongs to me, that is a packet that I need to do something with. So what it will do is remove that layer 2 information. Remember that layer 2 — I'm skipping a few pieces of information here, there's TCP connections and there's other types of things that are going on with this — but it does have a trailer, and it's going to do the consistency check on that to make sure that this frame is correct. So there are some other actions that are happening here.

It's going to take this in and say, yeah, this belongs to me, I'm going to do the frame consistency check on here and process this. And now I need to figure out where it's going to go. I'm a router, I need to figure out where it's going to go, so I'm going to take a look at the IP address. It's going to reference its routing table and it's going to see that this IP address belongs to this network over here. I'm going to look for the longest match, and the next hop will be this router right here.

This is another ethernet connection right here, so as ethernet works, it's going to need to know the MAC address of whatever IP address it has in its routing table. It has some sort of IP address of who it's going to communicate to, and now it needs to know a MAC address, so it's going to do an ARP request, and then this router is going to respond back with the MAC address on this interface.

The layer 3 switch now has the destination IP address where it's going to — in fact it's got the whole packet — and it also has the MAC address of the next hop that it needs to send this off to. Now that this layer 3 switch has that information, it's going to send that out onto this line, destined for the MAC address of this interface.

Across the point-to-point link

Guess what's going to happen on this router. This router is going to receive that information, it's going to take a look at the MAC address, and it's going to do the consistency check to make sure it's correct. Once it determines that yes, that MAC address is destined for me, it doesn't need that information anymore, it gets rid of that layer 2 information. Then it can take a look at the IP address. It sees that the IP address is destined for this network, it looks it up on the routing table to see what network that is and what the next hop is, and it sees that the next hop is going to be right here.

It knows that this line right here needs to exit out this serial 0 1 0 interface, and it sees that this line right here is a point-to-point protocol. So what it's going to do — we have our IP header here, and we have our payload, the data that's transferring, or in this case the SSH connection that needs to establish — it's going to attach that layer 2 header and trailer, but it's going to take the form of the point-to-point protocol, because that is the layer 2 protocol that's working on this network. We know that the address of that is not a MAC address, it's all ones.

So it's going to send it along the line here, and since this is point to point, it's just going to make it over to this other destination.

The HDLC hop

Guess what this router does. It takes that layer 2 information, makes sure it's destined for it, does that consistency check to make sure that it's truly destined for this router and that nothing has been corrupted along the way. Once it has that information it's going to drop that information, and now it has this packet. It's going to take a look at the IP information, it's going to look up into its router table, and it's going to see that it is destined for this network right here and that the next hop it's going to go to is this router right here.

So now what it needs to do is reform — well, you'll still have that IP address header with it. There is something that changes in that IP address header too: there's a time to live and a consistency check with that as well, so there are some changes that happen with that IP. The data for the most part stays the same. It needs to add a new layer 2 header to it and a new layer 2 trailer to it, but in this case right here it's an HDLC line, and since it's an HDLC line, the address in this layer 2 header is going to be just all ones, and it's going to add that to it. It will send it out its interface.

Final hop onto the destination network

This router will then receive it. It will once again do the consistency check, make sure that nothing has changed in it, and take a look at that layer 2 header to make sure it is truly destined for router 3 — and in fact it sees that yes it is. It doesn't need this layer 2 information anymore, so it gets rid of that.

Now what it needs to do is take a look at this IP information and look inside the routing table to try to find its longest match. It's going to see that the longest match is actually a directly connected network, and so it knows 10.2.0.5, so it needs to send it into the network. For that it will need to know what the MAC address is, because this is an ethernet network. So what it will do is another ARP request, and say out there, hey, who belongs to 10.2.0.5? That gets broadcast out, and then this switch is going to reply back with the MAC address of the switch.

So now the router has the IP address where it's going to go to, because that's part of the packet that it's trying to forward, and it now has a MAC address that it can put into this layer 2 header. It does the calculation for the trailer, and now it can send it into this network.

It hits this switch. The switch gets it, makes sure that the layer 2 address is destined for itself, that it's supposed to receive that, and then it says, oh yes, I'm supposed to receive that. It does the consistency check once again and then gets rid of that information because it doesn't need it anymore. It checks the IP, does a similar check with the IP, and says yes, this is destined for 10.2.0.5. Then it doesn't need that information anymore, and it takes a look at the payload. We know that there's a TCP header or UDP header with these as well, so it's going to take a look at that information, and then in this case SSH is the payload, and it's going to establish that connection.

That was all the communication that happened here in a split second. It happens really fast, and it goes back and forth, because if it's a TCP connection it goes back and forth and establishes a connection. So there's a back and forth that happens with this stuff really fast, at incredible speeds.

That is the process and the interplay between layer 2 and layer 3, and how it communicates between these devices despite these devices being possibly countries apart, thousands of miles apart.

About TechKnowSurge

TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.

Explore free tools and programs →