Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679

    How does a switch know?

    I've just got a switch, plugged everything to it and it worked!

    From what I know, a switch will only send packets to who is supposed to get them. The question is, how does it do that?

    I didn't configure it or tell it the IP address of each machine on the network, so how does it know how to switch?

    Thanks in advance.
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  2. #2
    A switch is basicly a Hub with a few differences...

    A hub sends the packets to everyone basicly a broadcast. If the PCs are tuned to the destination IP (compare to a radio tuned to the right station) it will use them, otherwise it will discard them.

    A switch doesn't broadcast the packests, thus giving a more efficient network.

    The PCs tell the switch the IP that they are using (very simplified) and then the switch will only send the packets for that PC. Since it's not sending those packets to every PC it saves internal network bandwidth.

    Guess that is a basic explaination anyway...
    I reserve the right to be wrong at all times

    phpbb forums without hosting fees

  3. #3
    Join Date
    Jun 2001
    Location
    Chicago, IL
    Posts
    1,953
    To add on what was said. A hub is layer 1(physical), it just resends info. A Switch is layer 2(Data-link). That means it has MAC addresses to work with, since macs are layer 2. So it is able to figure out which mac address, ie which computer gets the info. And that is figured out, assuming IP is being run, by ARP(Address Resolution Protocal).

  4. #4
    Join Date
    Dec 2001
    Location
    Ponchatoula, LA
    Posts
    497
    A Switch is a layer 2 device and knows nothing about IP addresses. It deals with layer 2 addresses or MAC addresses. The way it knows where to send packets is by watching where packets are coming from and learning. When a device sends packets to a switch the switch will remember where they came from.

    Say you have a computer with MAC address 1111 (real MAC addresses are 48 bits) connected to port 1. It wants to send to a computer on port 2 with MAC address 2222.

    The switch looks at the packet received and sees it came from port 1 with a source of 1111 and a destination of 2222. It checks it's MAC table to see if it has 1111 listed yet. If it does not, it adds an entry for MAC address 1111 - port 1.

    The switch does a lookup in it's MAC table for address 2222 to see if it knows what port 2222 is on. If it does not find it the packet is flooded out all ports except the originating port.

    The switch now knows what port MAC address 1111 is on, so if it receives traffic for 1111 it will only send it to port 1. When the computer with MAC address 2222 replies to 1111 the switch sends the traffic only out port 1 and it will also add an entry for MAC address 2222 - port 2 to it's table.

    Eventually the switch will learn what MAC address are on each port.

    Richard
    Enigma Hosting
    "I wasn't speeding, I was qualifying!"

  5. #5
    Join Date
    Jun 2001
    Location
    Chicago, IL
    Posts
    1,953
    " A Switch is a layer 2 device and knows nothing about IP addresses. "

    Dont forget layer 3 switches
    Chicago Electronic Cigarettes: Tobacco Free, Smoke Free. 3 E-Cig Models, 11 flavors, and accessories.
    http://www.chicago-ecigs.com

  6. #6
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    Thank you all for the input

    All I know about networking is theoritical. This is sort of what I was missing here:

    Originally posted by Noldar
    ..
    The way it knows where to send packets is by watching where packets are coming from and learning.
    ..
    I figured that a switch would use MAC addresses, but I didn't know how it collects this information. Anyway, this brings another question to me.

    Are MAC addresses part of the headers?
    How does a machine know the MAC address of another machine in the network from its IP address?
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  7. #7
    Join Date
    Dec 2000
    Location
    Leesburg, VA
    Posts
    3,205
    Originally posted by Ahmad

    Are MAC addresses part of the headers?
    How does a machine know the MAC address of another machine in the network from its IP address?
    All network devices maintain an ARP (Address Resolution Protocol) table. The ARP table is used to map MAC Addresses to IP Addresses. The switch is no different, it uses ARP to buld a network diagram marrying each MAC Address to an IP Address. ARP is only used to exchange information between devices on the same network. Another protocol, for your purposes IP, is used to transport information between networks. So, the MAC address does not need to be included in the header.

    The IP packet header looks like this:

    Code:
    
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 
    |Version|  IHL  |Type of Service|   Total Length                |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |         Identification        |Flags|   Fragment Offset          |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |  Time to Live |    Protocol   |       Header Checksum       |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                       Source Address                                       |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                    Destination Address                                   |
    -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    Last edited by allan; 06-19-2002 at 07:35 PM.

Posting Permissions

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