How a switch forwards a packet to the internet


Results 1 to 10 of 10

Thread: How a switch forwards a packet to the internet

  1. #1
    Join Date
    Apr 2003
    Location
    Oklahoma
    Posts
    559

    How a switch forwards a packet to the internet

    Not really linux-focused, but oh well...

    I was thinking of something this morning, and it's pretty simple, but it's got me stumped. How does a switch (level 2) get a packet onto the internet? Say for instance, my box is connected to a 24 port switch that is connected to a router that goes to the isp. How do my packets get forwarded to justlinux.com? I understand the whole filter vs. forward thing, and how switches learn MACs to build their table. But the thing that gets me is, when all the people connected to a switch are surfing the net, aren't their frames all addressed to the switch itself?

    I have come down to:

    1. The MAC used on the frames is not that of the switch, but the default gateway (router).

    2. Switches used in this capacity are really level 3 switches.

    3. Something else happens...

    Anyone care to inform me? Thanks.

  2. #2
    Join Date
    Apr 2003
    Location
    UK
    Posts
    1,180
    I'm pretty sure it's number 1. Your computer sends the packets to the default gateway to go out onto the internet, so they would be addressed to the router, I'm sure your computer doesn't actually know about the existence of the switch and I didn't think switches had MAC addresses (though I could be wrong on that).

  3. #3
    Join Date
    Apr 2003
    Location
    Oklahoma
    Posts
    559
    Yeah, I'm pretty sure it's #1, but all of the examples I could find (including the textbook I'm using to study with) are lan examples; and while I know that's kind of "the point" (switches are for lans, routers are for connecting lans) I would still like to know how the process works.

    The computer definitely isn't going to know the mac address of a remote site; so what mac address is used when the frame is created and sent to the switch? I'm guessing it's the address of the router, as mentioned, and that the switch is transparent (why not; it's really just a bridge).

    Guess I'm just looking for some affirmation here.

  4. #4
    Join Date
    Jan 2005
    Location
    NYC
    Posts
    6
    I've been staring at your question for a little while now... I'm not sure what you're asking.

    Is your question about how routers or switches operate or is it "how do routers know where to foward a packet based on the IP address" lets say from point A to point B to point C.

    EDIT: Looking at your question again I think I understand what you're asking.

    If you replace the switch with a hub(they only relay packets) in your scenario then #1 would be right but since your using a switch things get a little more complicated because they maintain a MAC address table for the devices connected to it.

    Actually now you've got me thinking....
    Last edited by BetaTron; 06-10-2005 at 02:35 PM.

  5. #5
    Join Date
    Apr 2003
    Location
    UK
    Posts
    1,180
    It uses the MAC address of the router and then the router addresses it for the next part of it's journey.

  6. #6
    Join Date
    Mar 2002
    Location
    Pennsylvania, USA
    Posts
    1,713
    I think if there's one line in your question that is throwing you off it's:

    when all the people connected to a switch are surfing the net, aren't their frames all addressed to the switch itself?
    If you're surfing the net, none of your packets will be addressed directly to the switch itself. Any packets sent to the Internet by your machine will have a destination IP address of some host on the Internet and a destination MAC address of the default gateway. The switch will forward the packet out the correct port that the router is attached to. As far as your computer is concerned, it knows nothing about the existence of the switch or a hub(unless the switch is using 802.11q VLANs which is another subject).

    A strictly layer 2 switch can have a MAC address and IP address, but they are just used for access for configuration or monitoring if the switch supports it. They are never used in the switches process of forwarding packets.
    If God hadn't meant for us to use GUI tools, there wouldn't have been a Xerox PARC.

  7. #7
    Join Date
    May 2003
    Posts
    227
    This is bringing back bad memories of preparing for the CCNA....

    Long story short, this comes down to layer 2 switching vs layer 3 routing. Google will give you more information then you ever wanted to know about these 2 things...

  8. #8
    Join Date
    Jan 2004
    Posts
    23
    Quote Originally Posted by cowanrl
    I think if there's one line in your question that is throwing you off it's:



    (unless the switch is using 802.11q VLANs which is another subject).
    Even if your machine is included in a vlan broadcast domain, it will still be oblivious to the actual network architechture(spelling?). The only device on the network that is concerned with VLANs are switches and routers.

    Admstng's idea is pretty good.....you are better off just going to cisco's website or better yet copping a copy of any of the numerous books pertaining to the CCNA.

  9. #9
    Join Date
    Apr 2003
    Location
    Oklahoma
    Posts
    559
    I've currently got two Cisco Press books to help me prepare for CCNA certification. And google turned up a ton of hits, with many pointing to cisco's site. The problem was, all of the information I could find at the time dealt with how a switch works at layer 2; i.e. building a table, types of frame processing, etc. I never found any complete description of how an ip packet goes from computer to switch to internet.

    After a while I found the answer staring me in the face, and it was virtually identical to cowanrl's advice: the bridge/switch is tranparent to the devices connected to it. Therefore the ip packet is given a mac address of the gateway/router, not the switch, and neither device (computer or gateway) knows about the switch.

    I thought it was a dead issue (not to mention uninteresting to most) so I never bothered to check back in.

  10. #10
    Join Date
    Aug 2002
    Location
    Western NY
    Posts
    1,116
    I'll try to give a quick overview..

    Host A - 192.168.0.15
    gateway - 192.168.0.1

    Both plugged into a normal layer 2 switch with no layer 3 capabilities.

    Host A has a default route pointed to the gateway.

    Host A wants to send a DNS request to 4.2.2.1. So first Host A is first going to need to send a arp request that is broadcasted on the switch basically saying who has 192.168.0.1 (Asking for the MAC address of the gateway). If the gateway is up it will respond back telling Host A I have this IP, and here is my MAC address. Any other host on the network will just drop the arp request and not respond if it doesnt have that IP. Host A will then add that MAC/IP address combo into its arp cache og the gateway. It will then be able to communicate with the gateway by sending packets to the MAC address that it responded with.

    At the switch level (2) every device talks to MACs, and not to their IPs.

    So anyway now that Host A knows the MAC of the gateway it can now send packets to that device. The gateway will in turn route the packet to the destination IP 4.2.2.1 that Host A wanted to communicate with in the first place. At each hop each router also has its own arp cache that it has built in the same way.
    Join #justlinux on irc.freenode.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •