Skip to content

Commit

Permalink
Merge pull request dentproject#26 from KorelU/Bridges-VLANs-and-Trunking
Browse files Browse the repository at this point in the history
Bridging-VLANs-and-Trunking
  • Loading branch information
taskin0003 authored Feb 28, 2024
2 parents 3bddcee + c0ae6b5 commit 7e926fa
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 120 additions & 0 deletions NetworkConfigurations/VLANConfigurationSubCategories/BridgingL2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
title: Bridging Layer 2
grand_parent: Network Configuration
parent: VLAN Configuration
nav_order: 1
layout: default
---

# Bridging Layer 2

## Introduction

In this guide, we will explain what bridging is
and give a quick example of how to use bridges.

In Linux systems, a bridge is a virtual switch-like device used to
connect different network interfaces and virtual network devices.

## Bridges

To create a bridge, use the following command:

```
$ ip link add name ${Bridge Name} type bridge
```

NOTE: Bridges may be configured with VLAN support.
For more information, visit VLANs (Configuring 802.1q Interfaces)

### Connecting Interfaces to a Bridge

Once you have created a new bridge, connect interfaces to it
with the following command:

```
$ ip link set dev ${Interface Name} master ${Bridge Name}
```

Connecting multiple different interfaces to the same bridge will allow devices on the
same subnet to ping each other.

![Network Configuration](../../Images/ImagesForNetworkConfiguration/SameSubnet.png)

With the configuration above, open the console on the switch and log in.

Run the following:

```
$ ip link add name br0 type bridge
$ ip link set dev enp0s4 master br0
$ ip link set dev enp0s5 master br0
```

Now ensure all interfaces are up with the `ip link` command.

```
$ ip link set br0 up
$ ip link set enp0s4 up
$ ip link set enp0s5 up
```

In the example above, the devices connected on enp0s4 and enp0s5
will now be able to communicate with one another using this bridge
as they are on the same subnet.

**NOTE: The output below was tested on a Virtual Machine**

PC1 ping on PC2:

```
PC1 : 192.168.0.1 255.255.255.0
PC1> ping 192.168.0.2
84 bytes from 192.168.0.2 icmp_seq=1 ttl=64 time=0.506 ms
84 bytes from 192.168.0.2 icmp_seq=2 ttl=64 time=0.713 ms
84 bytes from 192.168.0.2 icmp_seq=3 ttl=64 time=0.728 ms
84 bytes from 192.168.0.2 icmp_seq=4 ttl=64 time=0.878 ms
^C
PC1>
```

To detach a port from a bridge, use:

```
$ ip link set ${Interface Name} nomaster
```

## Configuration Persistence

The configurations above can be done with ifupdown
by placing the following in the `interfaces` file of the
`root@localhost:/etc/network#` directory.

Access the interfaces file with any file editor of your
choice and include the following:

```
auto br0
iface inet br0 manual
bridge_ports enp0s4 enp0s5
```

The first line creates a new bridge interface named `br0`.
The second line then indicates that interfaces `enp0s4` and `enp0s5`
are under the bridge interface

To apply these changes, restart the networking service by running:

`$ sudo systemctl restart networking`

NOTE: It may take longer than expected.

Creating and linking bridges in this manner is analogous
to using iproute2; however, upon rebooting the device
configurations will persist.
128 changes: 128 additions & 0 deletions NetworkConfigurations/VLANConfigurationSubCategories/Trunks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
title: Trunks
grand_parent: Network Configuration
parent: VLAN Configuration
nav_order: 3
layout: default
---

# Trunks

## Introduction

VLAN trunking is the practice of aggregating multiple network
links into a single link. As each VLAN is relative to a switch Trunks
can make two switches act like a single switch.

Trunking, with VLAN Aware bridging, is relatively simple
as it builds on itself.

## Example Configuration

Consider the topology:

![Network Configuration](../../Images/ImagesForNetworkConfiguration/ImageOneForTrunking.png)

Let's say we wanted to configure PC1 and PC3 to be on VLAN 10
while PC2 and PC4 would be on VLAN 20. By building a trunk, we
can communicate over the two switches with one link.

First, ensure each switch has a bridge for the interfaces in use.
In this example, `enp0s4`, `enp0s5`, and `enp0s6` are in use
on both switches.

On Switch 1 and Switch 2, run the following:

```
$ ip link add name br0 type bridge
$ ip link set dev enp0s4 master br0
$ ip link set dev enp0s5 master br0
$ ip link set dev enp0s6 master br0
```

Now Bring all devices up with

```
$ ip link set br0 up
$ ip link set enp0s4 up
$ ip link set enp0s5 up
$ ip link set enp0s6 up
```

Communication over the switches is now possible between all PCs.

To establish the VLANs toggle VLAN Aware mode on.

On Switch 1 and Switch 2, run the following:

```
$ ip link set dev br0 type bridge vlan_filtering 1
```

Next, add the desired VLAN tags to each PC interface.
Then, add both tags to the two interfaces connecting the switches.
In this example, the link for both switches is on their respective `enp0s6`.

On Switch 1 and Switch 2, run the following:

```
$ bridge vlan add dev enp0s4 vid 10 pvid untagged master
$ bridge vlan add dev enp0s5 vid 20 pvid untagged master
$ bridge vlan add dev enp0s6 vid 10
$ bridge vlan add dev enp0s6 vid 20
```

All four PCS can now only communicate over the trunk
with the respective PCs who share their VLAN.

**NOTE: The outputs below were tested on a Virtual Machine**

```
PC1 : 192.168.0.1 255.255.255.0
PC1> ping 192.168.0.3
84 bytes from 192.168.0.3 icmp_seq=1 ttl=64 time=2.345 ms
84 bytes from 192.168.0.3 icmp_seq=2 ttl=64 time=1.093 ms
84 bytes from 192.168.0.3 icmp_seq=3 ttl=64 time=1.442 ms
^C
PC1> ping 192.168.0.2
host (192.168.0.2) not reachable
PC1> ping 192.168.0.4
host (192.168.0.4) not reachable
PC1>
```

```
PC2 : 192.168.0.2 255.255.255.0
PC2> ping 192.168.0.4
84 bytes from 192.168.0.4 icmp_seq=1 ttl=64 time=2.345 ms
84 bytes from 192.168.0.4 icmp_seq=2 ttl=64 time=1.093 ms
84 bytes from 192.168.0.4 icmp_seq=3 ttl=64 time=1.442 ms
^C
PC2> ping 192.168.0.1
host (192.168.0.1) not reachable
PC2> ping 192.168.0.3
host (192.168.0.3) not reachable
PC2>
```
Loading

0 comments on commit 7e926fa

Please sign in to comment.