> 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/router.md).

# Router

Nerd Cafe

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

A <mark style="color:red;">**network router**</mark> is a critical device in networking that connects multiple networks and directs data packets between them. It plays a key role in ensuring efficient communication between devices on different networks, including the internet.

In this lesson, we will cover:

* What is a Router?
* Router Functions
* Types of Routers
* Routing Tables and Protocols
* Configuring a Router (Practical)
* Troubleshooting Routers

### <mark style="color:blue;">**1. What is a Router?**</mark>

A <mark style="color:red;">**router**</mark> is a device that forwards data <mark style="color:red;">**packets**</mark> between networks. It operates at <mark style="color:red;">**Layer 3 (Network Layer)**</mark> of the OSI model and determines the best path for data to travel.

#### <mark style="color:green;">**Example:**</mark>

When you visit `www.google.com`, your home router forwards your request to the ISP, which then routes it to Google’s servers.

#### <mark style="color:green;">**Key Components of a Router:**</mark>

* **CPU (Processor):** Handles data processing.
* **Memory (RAM, ROM, Flash, NVRAM):** Stores configuration and temporary data.
* **Interfaces (Ports):** Ethernet ports for connecting devices.
* **Routing Table:** Maintains network paths.

### <mark style="color:blue;">**2. Router Functions**</mark>

A router performs several key functions:

#### **2.1 Packet Forwarding**

* Uses the **routing table** to determine the best path.
* Works with **IP addresses** (not MAC addresses like switches).

#### **2.2 Network Address Translation (NAT)**

* Allows multiple devices in a private network to share a single public IP.
* Essential for home and enterprise networks.

#### **2.3 Dynamic Host Configuration Protocol (DHCP)**

* Assigns IP addresses dynamically to devices.

#### **2.4 Firewall and Security**

* Some routers have **firewall** features to block malicious traffic.

#### **2.5 Quality of Service (QoS)**

* Prioritizes certain types of network traffic (e.g., VoIP over regular browsing).

### <mark style="color:blue;">**3. Types of Routers**</mark>

Routers can be classified based on their usage:

#### <mark style="color:green;">**3.1 Wired Routers**</mark>

* Connect to a network via Ethernet cables.
* Example: Cisco enterprise routers.

#### <mark style="color:green;">**3.2 Wireless Routers**</mark>

* Provide **Wi-Fi** connectivity.
* Common in homes and offices (e.g., TP-Link, Netgear).

#### <mark style="color:green;">**3.3 Core Routers**</mark>

* High-performance routers used in <mark style="color:red;">**large networks**</mark> (e.g., ISPs).

#### <mark style="color:green;">**3.4 Edge Routers**</mark>

* Connect internal networks to external networks (like ISPs).

#### <mark style="color:green;">**3.5 Virtual Routers**</mark>

* Software-based routers (e.g., used in cloud networking).

### <mark style="color:blue;">**4. Routing Tables and Protocols**</mark>

A router makes forwarding decisions based on the <mark style="color:red;">**routing table**</mark> and <mark style="color:red;">**routing protocols**</mark>.

<figure><img src="https://2804731566-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLOszSitBb46QATDLUtW4%2Fuploads%2F8DgREFkBxdjGw6w1Cqeb%2F0505-topology.png?alt=media&amp;token=ff6e652e-fc0c-427b-850e-842857810bbd" alt=""><figcaption><p>Topology</p></figcaption></figure>

#### <mark style="color:green;">**4.1 Routing Table**</mark>

A routing table contains:

* **Destination Network:** The target network.
* **Next Hop:** The next router to forward the packet.
* **Metric:** The cost of the path.

**Example of a Routing Table (Cisco CLI Output)**

```
R1#show ip route 
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0/0
C    192.168.1.0/24 is directly connected, FastEthernet0/0
S    192.168.2.0/24 is directly connected, Serial0/0/0
R1#
```

#### <mark style="color:green;">**4.2 Routing Protocols**</mark>

Routing protocols help routers exchange information and update their tables.

#### **Types of Routing:**

1. **Static Routing:** Manually configured routes.
2. **Dynamic Routing:** Uses protocols to update routes automatically.

#### **Common Routing Protocols:**

* **RIP (Routing Information Protocol)** – Uses hop count.
* **OSPF (Open Shortest Path First)** – Uses link state.
* **BGP (Border Gateway Protocol)** – Used on the internet.

### <mark style="color:blue;">**5. Configuring a Router (Practical)**</mark>

#### <mark style="color:green;">**5.1 Setting Up a Cisco Router (Basic Configuration)**</mark>

We will configure a **Cisco router** using **Packet Tracer** or a real router.

#### **Step 1: Connect to the Router**

* Use a **console cable** and connect it to a PC.
* Open **PuTTY** or **Tera Term** to access the router’s **CLI**.

#### **Step 2: Enter Privileged Mode**

```bash
Router> enable
Router# configure terminal
```

#### Step 3: Set a Hostname

```bash
Router(config)# hostname R1
R1(config)# h
```

#### Step 4: Configure an Interface (Assign IP Address)

```bash
R1(config)# interface FastEthernet0/0
R1(config-if)# ip address 192.168.1.1 255.255.255.0
R1(config-if)# no shutdown
```

#### Step 5: Configure Routing (Static Route Example)

```bash
R1(config)# ip route 192.168.1.0 255.255.255.0 10.0.0.2
```

#### Step 6: Save Configuration

```bash
R1# write memory
```

### <mark style="color:blue;">**6. Troubleshooting Routers**</mark>

#### <mark style="color:green;">**6.1 Checking Connectivity**</mark>

Use **ping** to test connectivity.

```bash
R1#ping 192.168.1.100

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.100, timeout is 2 seconds:
!!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 0/0/1 ms

R1#ping 192.168.2.100

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.100, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 6/11/18 ms

R1#
```

#### <mark style="color:green;">6.2 Viewing the Routing Table</mark>

```bash
R1#show ip route 
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

     10.0.0.0/30 is subnetted, 1 subnets
C       10.0.0.0 is directly connected, Serial0/0/0
C    192.168.1.0/24 is directly connected, FastEthernet0/0
S    192.168.2.0/24 is directly connected, Serial0/0/0
R1#
```

#### <mark style="color:green;">6.3 Checking Interface Status</mark>

```
R1#show ip interface brief 
Interface              IP-Address      OK? Method Status                Protocol
 
FastEthernet0/0        192.168.1.1     YES manual up                    up
 
FastEthernet0/1        unassigned      YES unset  administratively down down
 
Serial0/0/0            10.0.0.1        YES manual up                    up
 
Vlan1                  unassigned      YES unset  administratively down down
R1#
```

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

* A <mark style="color:red;">**router**</mark> directs network traffic and connects multiple networks.
* Uses <mark style="color:red;">**routing tables**</mark> and <mark style="color:red;">**protocols**</mark> (Static, OSPF, RIP, BGP, etc.).
* Can be configured using <mark style="color:red;">**CLI**</mark> (Cisco routers).
* Troubleshooting involves checking routes, interfaces, and logs.

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

`router`, `network router`, `routing table`, `static routing`, `dynamic routing`, `OSPF`, `RIP`, `BGP`, `NAT`, `DHCP`, `firewall`, `QoS`, `packet forwarding`, `IP address`, `gateway`, `Cisco router`, `WAN`, `LAN`, `subnet mask`, `troubleshooting`, `نتورک پلاس`
