> For the complete documentation index, see [llms.txt](https://netsec.nerd-cafe.ir/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://netsec.nerd-cafe.ir/network-engineering/comptia-network+/n10-007/switches.md).

# Switches

Nerd Cafe

### <mark style="color:blue;">**Introduction to Network Switches**</mark>

A <mark style="color:red;">**network switch**</mark> is a fundamental device in networking that connects multiple devices within a local area network (LAN) and manages data traffic efficiently. Unlike hubs, which <mark style="color:red;">**broadcast**</mark> data to all devices, switches <mark style="color:red;">**forward**</mark> data only to the specific device that needs it, reducing network congestion and improving performance.

### <mark style="color:blue;">**Lesson 1: Understanding Network Switches**</mark>

#### <mark style="color:green;">**1.1 What is a Network Switch?**</mark>

A <mark style="color:red;">**network switch**</mark> is a multi-port device that uses <mark style="color:red;">**MAC addresses**</mark> to forward data frames to the correct destination. It operates at <mark style="color:red;">**Layer 2 (Data Link Layer)**</mark> of the OSI model, but some advanced switches can also function at <mark style="color:red;">**Layer 3 (Network Layer)**</mark>, performing routing functions.

#### <mark style="color:green;">**1.2 Key Features of a Network Switch**</mark>

* **MAC Address Learning:** Switches build a MAC address table by learning the source MAC addresses from incoming frames.
* **Frame Forwarding:** Based on the MAC address table, switches send frames only to the intended recipient.
* **Collision Domain Separation:** Each port of a switch creates a separate collision domain, unlike hubs, which share a single collision domain.
* **Full-Duplex Communication:** Switches support full-duplex communication, allowing simultaneous sending and receiving of data.
* **VLAN Support:** Virtual LANs (VLANs) segment networks logically, improving security and efficiency.

#### <mark style="color:green;">**1.3 Types of Network Switches**</mark>

1. **Unmanaged Switch**: Basic plug-and-play switch with no configuration options.
2. **Managed Switch**: Allows customization, VLANs, security settings, and traffic monitoring.
3. **Layer 2 Switch**: Operates at the Data Link Layer, forwarding based on MAC addresses.
4. **Layer 3 Switch**: Has routing capabilities and can forward data based on IP addresses.
5. **PoE (Power over Ethernet) Switch**: Supplies power to connected devices like IP cameras and VoIP phones.

### <mark style="color:blue;">**Lesson 2: Practical Setup of a Network Switch**</mark>

<figure><img src="https://2804731566-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLOszSitBb46QATDLUtW4%2Fuploads%2FiTIVfOqIkp4YPn21gdX6%2F0504-topology.png?alt=media&amp;token=7c257e60-9d5c-4c7f-88c2-f9b5fe01ac96" alt=""><figcaption><p>Topology</p></figcaption></figure>

#### <mark style="color:green;">**2.1 Required Equipment**</mark>

* A **network switch** (managed or unmanaged)
* **Ethernet cables (Cat5e, Cat6, or Cat7)**
* Devices such as **computers, routers, and access points**
* (For managed switches) A **PC with a web browser or terminal** for configuration

#### <mark style="color:green;">**2.2 Step-by-Step Setup**</mark>

**Step 1: Physical Connection**

1. **Power on the switch** and ensure the LED indicators are working.
2. **Connect devices** to the switch using Ethernet cables.
3. **Connect the switch to a router** if internet access is needed.

**Step 2: Basic Testing**

1. Check if the devices <mark style="color:red;">**get an IP address**</mark> (if DHCP is enabled on the router).
2. Use the <mark style="color:red;">**ping command**</mark> to test connectivity between devices:

```bash
ping 192.168.1.10
```

### <mark style="color:blue;">**Lesson 3: Configuring a Managed Network Switch**</mark>

#### <mark style="color:green;">**3.1 Accessing the Switch**</mark>

1. <mark style="color:red;">**Find the switch's IP address**</mark> (usually in the user manual or assigned by DHCP).
2. Open a web browser and enter the IP address.
3. <mark style="color:red;">**Login**</mark> with default credentials (admin/admin or admin/password).
4. Change the default <mark style="color:red;">**username and password**</mark> for security.

#### <mark style="color:green;">**3.2 Creating VLANs (Virtual LANs)**</mark>

VLANs separate traffic logically, increasing security and reducing congestion.

1. **Navigate to VLAN Settings.**
2. Create VLANs (e.g., VLAN 10 for HR, VLAN 20 for IT).
3. Assign ports to VLANs.
4. Save and apply settings.

```
Switch>en
Switch>enable 
Switch#configure terminal 
Switch(config)#vlan 10
Switch(config-vlan)#name HR
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#name IT
Switch(config-vlan)#exit
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport mode access 
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#interface fastEthernet 0/2
Switch(config-if)#switchport mode access 
Switch(config-if)#switchport access vlan 20
Switch(config-if)#^Z
Switch#write memory 
Building configuration...
[OK]
Switch#
```

#### <mark style="color:green;">**3.3 Enabling Port Security**</mark>

To prevent unauthorized access, enable <mark style="color:red;">**port security**</mark> on switch ports.

```
Switch#configure terminal 
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport port-security 
Switch(config-if)#switchport port-security maximum 2
Switch(config-if)#switchport port-security violation shutdown 
```

### <mark style="color:blue;">**Lesson 4: Troubleshooting a Network Switch**</mark>

#### <mark style="color:green;">**4.1 Common Issues and Solutions**</mark>

<table><thead><tr><th width="226">Issue</th><th width="253">Possible Cause</th><th>Solution</th></tr></thead><tbody><tr><td>No network connectivity</td><td>Bad cable or incorrect port</td><td>Replace the cable, check port connections</td></tr><tr><td>High network latency</td><td>Congested ports</td><td>Enable Quality of Service (QoS)</td></tr><tr><td>Intermittent connectivity</td><td>Duplex mismatch</td><td>Set correct duplex settings</td></tr><tr><td>Unauthorized devices</td><td>Security threat</td><td>Enable port security</td></tr></tbody></table>

#### <mark style="color:green;">**4.2 Checking MAC Address Table**</mark>

To see the MAC addresses learned by a switch:

```
Switch#show mac-address-table 
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----

  10    0030.f280.261b    STATIC      Fa0/1
  20    0030.a3a5.9637    DYNAMIC     Fa0/2
Switch#
```

#### <mark style="color:green;">4.3 Checking VLAN Configuration</mark>

```
Switch#show vlan brief 

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/3, Fa0/4, Fa0/5, Fa0/6
                                                Fa0/7, Fa0/8, Fa0/9, Fa0/10
                                                Fa0/11, Fa0/12, Fa0/13, Fa0/14
                                                Fa0/15, Fa0/16, Fa0/17, Fa0/18
                                                Fa0/19, Fa0/20, Fa0/21, Fa0/22
                                                Fa0/23, Fa0/24
10   HR                               active    Fa0/1
20   IT                               active    Fa0/2
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    
Switch#
```

### <mark style="color:blue;">**Conclusion**</mark>

* Network switches are essential in LANs, enabling <mark style="color:red;">**efficient data transfer**</mark>.
* <mark style="color:red;">**Managed switches**</mark> offer more control, security, and VLAN segmentation.
* <mark style="color:red;">**Basic troubleshooting**</mark> and <mark style="color:red;">**security settings**</mark> are crucial for a stable network.

### <mark style="color:blue;">Keywords</mark>

`Network switch`, `Ethernet switch`, `Layer 2 switch`, `Layer 3 switch`, `VLAN`, `MAC address table`, `Port security`, `Managed switch`, `Unmanaged switch`, `PoE switch`, `Network topology`, `Collision domain`, `Full-duplex`, `Packet forwarding`, `Network segmentation`, `Switch configuration`, `STP (Spanning Tree Protocol)`, `QoS (Quality of Service)`, `Trunking`, `Switch troubleshooting`, `نتورک پلاس`
