14 Replies Latest reply: Oct 4, 2012 1:05 AM by prithivi RSS

    Do switches know subnetting?

    prithivi

      Hello,

       

      1. can switches read an IP address or can they understand IP address? I connected 3 PCs with different subnet mask to switch ports and they were not able to talk to each other, but when they are in the same network, they can communicate.

       

      ip addr | subnet mask | default gateway

      PC1: 10.1.0.6 255.255.255.252 10.1.0.5

      PC2: 10.1.0.10 255.255.255.252 10.1.0.9

      PC3: 10.1.0.14 255.255.255.252 10.1.0.13

       

      in the same network

      PC1: 10.1.0.6 255.255.255.0 10.1.0.5

      PC2: 10.1.0.10 255.255.255.0 10.1.0.9

      PC3: 10.1.0.14 255.255.255.0 10.1.0.13

       

      2. when they are in same network, switch doesn't care whats the default gateway is, all 3 can talk to each other. is it normal working?

       

      if switches operate at layer 2 how they can do this?

       

      thanks in advance

         
        • 1. Re: Do switches know subnetting?
          Sey

          Hi,

          1. can switches read an IP address or can they understand IP address?

          They actually can, but not in the context of your question. Since you're asking about forwarding traffic with a Layer 2 switch, the answer is no - they don't look into IP addresses.

          I connected 3 PCs with different subnet mask to switch ports and they were not able to talk to each other, but when they are in the same network, they can communicate.

          That's exactly what subnetting is for!

          2. when they are in same network, switch doesn't care whats the default gateway is, all 3 can talk to each other. is it normal working?

          Yes, this is normal. A default gateway is used only when you want to move traffic out of the subnet.

          if switches operate at layer 2 how they can do this?

          Layer 2 switches look at MAC addresses. Let's assume that PC1 has a MAC address of 1111.1111.1111, and that of PC2 is 2222.2222.2222

           

          When PC1 wants to talk to PC2, it first checks if PC2 is within its own (PC1's) subnet. If it is, PC1 sends a broadcast ARP request asking "who is 10.1.0.10?". All hosts within the broadcast domain receive this query, process it and discard it - all but PC2 that sees that someone is asking for its IP address. So PC2 sends an ARP reply saying "I'm the host in question, my MAC address is 2222.2222.2222". Now PC1 can build a frame sending it from MAC address 1111.1111.1111 to 2222.2222.2222. The switch receives the frame, looks up the destination MAC address in its MAC table, and forwards the frame out the appropriate port. This is how the frame reaches PC2. Note that the switch did not look at the IP addresses!

          • 2. Re: Do switches know subnetting?
            kcnajaf007

            Hi Prithivi,

             

            This is very much expected behaviour of switches.

             

            What happens here is that when you put all devices on the same subnet and when you try to communicate between these devices, the communication happens my means of broadcasts. i.e the device send arp broadcast asking for who has the destination ip address. For example device with ip address 10.1.0.10 is trying to communicate with 10.1.0.6, it sends a arp broadcast for 10.1.0.6 asking who knows this ip address..Since this is a broadcast message this is received by all the ports on the switch (assuming all ports are on same vlan) and switch ports to which this pc with ip address 10.1.0.6 is connected respond back saying i have this ip address and here is its MAC address. Switch now updated it MAC address table saying MAC address aaaa.bbbb.cccc.dddd is learned from port Fas 0/X. Like wise switch maintain a table for all the devices on the same subnet in its MAC address table. Here you can see that since all devices are on same subnets communications happens only via MAC address and they dont have to use the default gateway. And this is the basic pricipal for L2 communications.

             

            But when the devices are on different ip subnet they will have to use the default gateway as broadcast send will not pass beyond that subnet bountry. Communication here basically happens with ip routing look up to understand where the destiantion ip address resides and traffic will be send on to the interface which is learned by routing look up.

             

            Hope this clarifies your doubt...

            • 3. Re: Do switches know subnetting?
              Paul Stewart  -  CCIE Security

              A layer two switch does understand layer 3 if it is a managed device. However, in the case of a layer 2 managed switch, layer 3 is only used for management. In that case, it still understands subnetting and addressing in order to understand when to use the default gateway for management traffic. A layer 2 switch simply doesn't route traffic. For example, you cannot have two active layer 3 interfaces (or SVIs). You can only have the one you need for management.

              • 4. Re: Do switches know subnetting?
                Shahryar Ali - CCNP R&S / CCDA

                Switches do understand Layer 3 address. its just that they dont do routing based on their understanding of IP addresses. Consider a scenario of 3 VLANS managed by switch. As we know, all the vlans managed by switch should be in different subnet. Try assigning the management IP addresses from same subnet to different VLANS. The switch shouldnt accept it.

                • 5. Re: Do switches know subnetting?
                  prithivi

                  Thank you all, but how does the switch know if a particular host is in a different subnet.

                   

                  1. If a switch has a new IP then it broadcasts right, so is it like if it doesnt get any reply for that broadcast, then it considers that IP is in different subnet?

                  2. or does the switch looks at the subnet mask? or how is it?

                   

                  Note: I haven't assigned any IP to my switch. I just connected 3 PCs, all 3 in different subnet.

                  PC1: 10.1.0.6 255.255.255.252 10.1.0.5 Subnet: 10.1.0.4

                  PC2: 10.1.0.10 255.255.255.252 10.1.0.9 Subnet: 10.1.0.8

                  PC3: 10.1.0.14 255.255.255.252 10.1.0.13 Subnet: 10.1.0.12

                  • 6. Re: Do switches know subnetting?
                    Sey

                    I think you did not read my post above. I spent my time writing it, can you please spend some of your time reading it? I'll be glad to clarify whatever is not clear.

                    • 7. Re: Do switches know subnetting?
                      prithivi

                      Sey wrote:

                       

                      Hi,

                      1. can switches read an IP address or can they understand IP address?

                      They actually can, but not in the context of your question. Since you're asking about forwarding traffic with a Layer 2 switch, the answer is no - they don't look into IP addresses.

                      I connected 3 PCs with different subnet mask to switch ports and they were not able to talk to each other, but when they are in the same network, they can communicate.

                      That's exactly what subnetting is for!

                      => I understand thats what subnetting is for. If those PCs were connected to a router, no doubt for me. Let me rephrase the question. Does subnetting work of above 3 PCs are connected to switch alone?

                      2. when they are in same network, switch doesn't care whats the default gateway is, all 3 can talk to each other. is it normal working?

                      Yes, this is normal. A default gateway is used only when you want to move traffic out of the subnet.


                      if switches operate at layer 2 how they can do this?

                      Layer 2 switches look at MAC addresses. Let's assume that PC1 has a MAC address of 1111.1111.1111, and that of PC2 is 2222.2222.2222

                       

                      When PC1 wants to talk to PC2, it first checks if PC2 is within its own (PC1's) subnet. If it is, PC1 sends a broadcast ARP request asking "who is 10.1.0.10?". All hosts within the broadcast domain receive this query, process it and discard it - all but PC2 that sees that someone is asking for its IP address. So PC2 sends an ARP reply saying "I'm the host in question, my MAC address is 2222.2222.2222". Now PC1 can build a frame sending it from MAC address 1111.1111.1111 to 2222.2222.2222. The switch receives the frame, looks up the destination MAC address in its MAC table, and forwards the frame out the appropriate port. This is how the frame reaches PC2. Note that the switch did not look at the IP addresses!

                       

                      When PC1 wants to talk to PC2, it first checks if PC2 is within its own (PC1's) subnet.

                      how does PC1 checks if PC2 is within its own subnet, my doubt basically lies around this?

                       

                      All hosts within the broadcast domain receive this query

                      =>I understand switches dont divide broadcast domains(except VLANs) and no VLANs configured here. Just 3 PCs are assigned with IP add. and gateways as below and connected to switch ports. There is no configuration done on switch.

                      ip addr | subnet mask | default gateway

                      PC1: 10.1.0.6 255.255.255.252 10.1.0.5

                      PC2: 10.1.0.10 255.255.255.252 10.1.0.9

                      PC3: 10.1.0.14 255.255.255.252 10.1.0.13


                      say if PC1 pings PC2, then here,do all PCs receive the query considering as one broadcast domain?

                      if the answer is NO, then based on which the PC/switch knows about their domain.

                      if the answer is YES, then plz look at my previous post's question


                      I read your post too, thanks Sey for your time, help with the questions above.

                      • 8. Re: Do switches know subnetting?
                        Paul Stewart  -  CCIE Security

                        PC1 would determine if PC2 is in the same subnet by looking at its own routing table. This is derived from the interfaces IP configuration. If it is local, it arps directly. If it is remote, it would use the gateway.

                        • 9. Re: Do switches know subnetting?
                          Sey

                          Okay, now I got the point of your confusion.

                          I understand thats what subnetting is for. If those PCs were connected to a router, no doubt for me. Let me rephrase the question. Does subnetting work of above 3 PCs are connected to switch alone?

                          Yes it does. This is not about switches or routers, it's really about the question: How does a PC decide to send a frame out of its NIC to whatever is connected?

                           

                          The answer lies in building the frame. A PC (much like a router) will do a few recursive route lookups which should come to an outgoing interface in the end! If it doesn't, the frame won't leave the PC's NIC.

                          When PC1 wants to talk to PC2, it first checks if PC2 is within its own (PC1's) subnet.

                          how does PC1 checks if PC2 is within its own subnet, my doubt basically lies around this?

                          This is about binary math. Let's take your example with PC1 (10.1.0.6/30) and PC2 (10.1.0.10/30). So PC1 wants to ping PC2. PC1 needs to decide if this is local communication or not, i.e. if PC2 is within PC1's subnet or not. Let's look at the last octet.

                           

                          6  = 00000110

                          10 = 00001010

                           

                          The blue part belongs to subnet, whereas the green part belongs to host. As we can see, the subnet part is different for 10.1.0.6/30 and 10.1.0.10/30 which means that in order to access PC2, PC1 needs to go to its default gateway which is your case 10.1.0.5. Now let's imagine that there is no default gateway configured on PC1. In this case the frame cannnot be built because PC2 is in another subnet. No frame - no communication, i.e. data won't go out the PC1's NIC. Note that it doesn't matter what is connected to PC1 - a router, a switch, or a directly connected PC2 - the frame won't go there as the packet cannot be encapsulated.

                          say if PC1 pings PC2, then here,do all PCs receive the query considering as one broadcast domain?

                          The ARP broadcast asking about 10.1.0.10 won't go to the switch because PC2 is not within PC1's subnet, so no one will receive it. In order to send a packet to PC2, PC1 will have to build a frame with DG's MAC address as the destination. This means that PC1 will send an ARP request broadcast for 10.1.0.5, and not 10.1.0.10. This broadcast will be received by everyone (PC2, PC3), as everyone must react to frames sent to FF:FF:FF:FF:FF:FF (the broadcast MAC address).

                          if the answer is NO, then based on which the PC/switch knows about their domain.

                          Based on the subnet mask and binary math, as explained above.

                           

                          Please share any doubt you have.

                          • 10. Re: Do switches know subnetting?
                            prithivi

                            When PC1 wants to talk to PC2, it first checks if PC2 is within its own (PC1's) subnet.

                            how does PC1 checks if PC2 is within its own subnet, my doubt basically lies around this?

                            This is about binary math. Let's take your example with PC1 (10.1.0.6/30) and PC2 (10.1.0.10/30). So PC1 wants to ping PC2. PC1 needs to decide if this is local communication or not, i.e. if PC2 is within PC1's subnet or not. Let's look at the last octet.

                             

                            6  = 00000110

                            10 = 00001010

                             

                            The blue part belongs to subnet, whereas the green part belongs to host. As we can see, the subnet part is different for 10.1.0.6/30 and 10.1.0.10/30 which means that in order to access PC2, PC1 needs to go to its default gateway which is your case 10.1.0.5. Now let's imagine that there is no default gateway configured on PC1. In this case the frame cannnot be built because PC2 is in another subnet. No frame - no communication, i.e. data won't go out the PC1's NIC. Note that it doesn't matter what is connected to PC1 - a router, a switch, or a directly connected PC2 - the frame won't go there as the packet cannot be encapsulated.


                             

                            say if both PCs are in the same subnet, here also we use the same IP address. If PC1 compares the IP address like above, it will still show as different but here they are in same subnet

                            PC1 (10.1.0.6/24)

                            PC2 (10.1.0.10/24)

                             

                            Do PCs look at IP address for determining the subnet? This is the first time I have come across this. Plz clarify on this. Thanks

                            • 11. Re: Do switches know subnetting?
                              Sey

                              say if both PCs are in the same subnet, here also we use the same IP address. If PC1 compares the IP address like above, it will still show as different but here they are in same subnet

                              PC1 (10.1.0.6/24)

                              PC2 (10.1.0.10/24)

                              Let me write the whole IP addresses in binary:

                               

                              00001010.00000001.00000000.00000110 = 10.1.0.6/24

                              00001010.00000001.00000000.00001010 = 10.1.0.10/24

                               

                              Note that the subnet part is not different anymore now that you changed subnet mask from /30 to /24.

                               

                              Do PCs look at IP address for determining the subnet?

                              A PC applies its subnet mask to its IP address to find out its subnet address. In this case subnet address is 10.1.0.0/24. Then it takes the destination address 10.1.0.10 and checks its first 24 bits which turn out to be the same. The PC comes to a conclusion that 10.1.0.10 is within its own subnet, so it's going to talk to it directly.

                              • 12. Re: Do switches know subnetting?
                                prithivi

                                That clarifies, Thanks Sey

                                 

                                Two situations here, both PCs configured with default gateway:

                                 

                                2 PCs in different subnet connected to router

                                PC1 pings PC2:

                                PC1->default gateway->router->PC2

                                 

                                2 PCs in different subnet connected to switch

                                PC1 pings PC2:

                                PC1->default gateway-> what happens next...?

                                • 13. Re: Do switches know subnetting?
                                  Sey

                                  2 PCs in different subnet connected to router

                                  PC1 pings PC2:

                                  PC1->default gateway->router->PC2

                                  Default gateway is a router, so if both PCs are connected to the same router at Layer 3 it looks like PC1->router->PC2.

                                  2 PCs in different subnet connected to switch

                                  PC1 pings PC2:

                                  PC1->default gateway-> what happens next...?

                                  Next the packet is routed according to the router's (which is default gateway) routing table.

                                  • 14. Re: Do switches know subnetting?
                                    prithivi

                                    Thank you Sey and all for your response