We will look at the simplest way to prevent a switch port from talking to another. For something that gives you more options, take a look at private vlans.
It is all about one command under the switch port and that is: 'switchport protected '.
We have a L3 switch (in the middle) that has 2 vlans configured: 10 and 20. In vlan 10 we have 3 ports: Gi0/1 (non protected) and Gi1/1 and Gi1/2 (protected ports). In vlan 20, we have port Gi0/2 (not protected) and port Gi1/3 (protected). For testing, we built 2 SVIs : vlan 10 and vlan 20. IP addressing is in the diagram. The theory states that a protected port cannot talk to another protected port at L2, it can only flow through a L3 device. Let's configure and test.
SW
R0x
Test
interface GigabitEthernet0/1! interface Gi0/2 has the same config with vlan 200 switchport access vlan 100 switchport mode accessinterface GigabitEthernet1/1! interface Gi1/2 has the same config and interface Gi1/3 uses vlan 200 switchport access vlan 100 switchport mode access switchport protectedinterface Vlan100 ! interface Vlan200 uses vlan 200 ip address 10.0.0.254255.255.255.0! ValidationSW#sh int status | i 100|200Gi0/1 connected 100 a-full auto RJ45Gi0/2 connected 200 a-full auto RJ45Gi1/1 connected 100 a-full auto RJ45Gi1/2 connected 100 a-full auto RJ45Gi1/3 connected 200 a-full auto RJ45SW#sh ip int br | i lanVlan100 10.0.0.254 YES NVRAM up upVlan200 20.0.0.254 YES NVRAM up upSW#sh int gi1/1 switchport | i rotectProtected: trueSW#sh int gi1/2 switchport | i rotectProtected: trueSW#sh int gi1/3 switchport | i rotectProtected: trueSW#
! for R01, R02, R03interface FastEthernet0/0 ip address 10.0.0.[1|2|3]255.255.255.0 duplex auto speed autoendR1#sh ip route static20.0.0.0/24 is subnetted, 1 subnetsS 20.0.0.0[1/0] via 10.0.0.254R1#! for R04, R05interface FastEthernet0/0 ip address 20.0.0.[1|2]255.255.255.0 duplex auto speed autoendR4#sh ip route static10.0.0.0/24 is subnetted, 1 subnetsS 10.0.0.0[1/0] via 20.0.0.254R4#
R2#ping 10.0.0.1Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.0.0.1, timeout is 2 seconds:.!!!!Success rate is 80 percent (4/5), round-trip min/avg/max=72/76/84 msR2#ping 10.0.0.2Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.0.0.2, timeout is 2 seconds:!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max=1/3/4 msR2#ping 10.0.0.3Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.0.0.3, timeout is 2 seconds:.....Success rate is 0 percent (0/5)R2#ping 10.0.0.254Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.0.0.254, timeout is 2 seconds:.!!!!Success rate is 80 percent (4/5), round-trip min/avg/max=8/10/12 msR2#ping 20.0.0.1Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 20.0.0.1, timeout is 2 seconds:.!!!!Success rate is 80 percent (4/5), round-trip min/avg/max=20/24/36 msR2#ping 20.0.0.2Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 20.0.0.2, timeout is 2 seconds:.!!!!Success rate is 80 percent (4/5), round-trip min/avg/max=4/12/24 msR2#ping 20.0.0.254Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 20.0.0.254, timeout is 2 seconds:!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max=4/9/16 msR2#
Looks like everything went according to plan. R02 sitting behind Gi1/1 was unable to talk to R03 sitting behind Gi1/2 as expected. According to the theory, the devices can talk to each other if the traffic is routed. That is what we are seeing when R02 can successfully ping R04, although they are both behind protected ports.
What if we actually wanted the protected ports to talk to each other? What if they would be in the same vlan and there is no routing? If you are curious, you can read all about it over here.