# Networks & Switching

<details id="bkmrk-editable-diagram"><summary>Editable diagram</summary>

<div drawio-diagram="126"><img src="https://wiki.hexadust.net/uploads/images/drawio/2024-11/vGMNOS2JlKaeoPSL-drawing-3-1732908475.png" alt=""/></div>

</details>[![network.png](https://wiki.hexadust.net/uploads/images/gallery/2024-11/scaled-1680-/xOrahgcBwTwT1Yyk-network.png)](https://wiki.hexadust.net/uploads/images/gallery/2024-11/xOrahgcBwTwT1Yyk-network.png)

## VLANs

<table border="1" id="bkmrk-name-tag-network-des" style="border-collapse: collapse; width: 100%; height: 206.267px;"><colgroup><col style="width: 9.76927%;"></col><col style="width: 6.31428%;"></col><col style="width: 16.441%;"></col><col style="width: 32.8819%;"></col><col style="width: 34.669%;"></col></colgroup><tbody><tr style="height: 29.4667px;"><td style="height: 29.4667px;">**Name**  
</td><td style="height: 29.4667px;">**Tag**  
</td><td style="height: 29.4667px;">**Network**  
</td><td style="height: 29.4667px;">**Description**</td><td style="height: 29.4667px;">**Gateways**  
</td></tr><tr style="height: 29.4667px;"><td style="height: 29.4667px;">HOME</td><td style="height: 29.4667px;">1  
</td><td style="height: 29.4667px;">192.168.1.0/24</td><td style="height: 29.4667px;">Internal home network  
</td><td style="height: 29.4667px;">caroline: 192.168.1.1

justine: 192.168.1.2 (DHCP default)

</td></tr><tr style="height: 29.4667px;"><td style="height: 29.4667px;">GUEST</td><td style="height: 29.4667px;">10  
</td><td style="height: 29.4667px;">192.168.10.0/24</td><td style="height: 29.4667px;">Isolated network  
</td><td style="height: 29.4667px;">caroline: 192.168.10.1 (DHCP default)  
</td></tr><tr style="height: 29.4667px;"><td style="height: 29.4667px;">SERVER</td><td style="height: 29.4667px;">50  
</td><td style="height: 29.4667px;">192.168.50.0/24</td><td style="height: 29.4667px;">Internet exposed servers  
</td><td style="height: 29.4667px;">caroline: 192.168.50.1 (DHCP default)  
</td></tr><tr style="height: 29.4667px;"><td>IOT  
</td><td>80  
</td><td>192.168.80.0/24</td><td>IoT devices  
</td><td>carolone: 192.168.100.1 (DHCP default)

</td></tr><tr><td style="height: 29.4667px;">MGMT</td><td style="height: 29.4667px;">100  
</td><td style="height: 29.4667px;">192.168.100.0/24</td><td style="height: 29.4667px;">Management network  
</td><td style="height: 29.4667px;">carolone: 192.168.100.1

justine: 192.168.100.2 (DHCP default)

</td></tr></tbody></table>

### Connectivity

Caroline does VLAN routing.

<table border="1" id="bkmrk-name-internet-access" style="border-collapse: collapse; width: 100%; height: 147.334px; border-width: 1px;"><colgroup><col style="width: 12.2716%;"></col><col style="width: 21.803%;"></col><col style="width: 21.6884%;"></col><col style="width: 25.8493%;"></col><col style="width: 18.3479%;"></col></colgroup><tbody><tr style="height: 29.4667px;"><td style="height: 29.4667px;">**Name**  
</td><td style="height: 29.4667px;">**Internet access G/W** </td><td>**DNS** </td><td style="height: 29.4667px;">**WiFi SSID** </td><td style="height: 29.4667px;">**Access to** </td></tr><tr style="height: 29.4667px;"><td style="height: 29.4667px;">HOME</td><td style="height: 29.4667px;">Justine (VPN), Caroline  
</td><td>Justine (PiHole), Caroline  
</td><td style="height: 29.4667px;">Haru, Haru Legacy (2.4GHz)  
</td><td style="height: 29.4667px;">SERVER, IOT  
</td></tr><tr style="height: 29.4667px;"><td style="height: 29.4667px;">GUEST</td><td style="height: 29.4667px;">Caroline</td><td>Caroline</td><td style="height: 29.4667px;">Toudi, Toudi Legacy (2.4GHz)  
</td><td style="height: 29.4667px;">  
</td></tr><tr style="height: 29.4667px;"><td style="height: 29.4667px;">SERVER</td><td style="height: 29.4667px;">Caroline</td><td>Caroline</td><td style="height: 29.4667px;"> </td><td style="height: 29.4667px;">  
</td></tr><tr style="height: 29.4667px;"><td>IOT  
</td><td>Caroline</td><td>Caroline</td><td>IoT (2.4GHz)  
</td><td style="height: 29.4667px;"> </td></tr><tr><td style="height: 29.4667px;">MGMT</td><td style="height: 29.4667px;">Justine (VPN), Caroline</td><td>Justine (PiHole), Caroline</td><td style="height: 29.4667px;">Haru MGMT (2.4GHz)  
</td><td style="height: 29.4667px;">SERVER</td></tr></tbody></table>

## Subnets

<table border="1" id="bkmrk-base-range-subnet-1-" style="border-collapse: collapse; width: 100%; height: 447px;"><colgroup><col style="width: 25.0199%;"></col><col style="width: 25.0199%;"></col><col style="width: 20.8532%;"></col><col style="width: 29.1865%;"></col></colgroup><tbody><tr style="height: 29.8px;"><td style="height: 29.8px;">**Base range**  
</td><td style="height: 29.8px;">**Subnet 1 / Usage**  
</td><td style="height: 29.8px;">**Subnet 2 / Usage**</td><td style="height: 29.8px;">**IPv6 ULA `fd42:dead:beef/48`**</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">`10.0.0.0/8`</td><td style="height: 29.8px;">*reserved for work VPNs*  
</td><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">`172.16.0.0/12` (to 172.31.)  
</td><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">  
</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`172.17.1.1/24. `</td><td style="height: 29.8px;">Justine VPN: `vpn`  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:1701/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`172.17.2.1/24`</td><td style="height: 29.8px;">Justine VPN: `outpust`</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:1721/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`172.17.100.1/24`</td><td style="height: 29.8px;">VPS VPN: `vps`  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:1700/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`172.18.0.0/16`</td><td style="height: 29.8px;">Justine Docker  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:1800/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`172.19.0.0/16`</td><td style="height: 29.8px;">Igor Kubenretes  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:1900/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`172.20.0.0/24`</td><td style="height: 29.8px;">Igor Sandbox VMs  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:2000/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">`192.168.0.0/16`</td><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`fd42:dead:beef:68/56`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`192.168.1.0/24`</td><td style="height: 29.8px;">HOME VLAN  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:6801/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`192.168.10.0/24`</td><td style="height: 29.8px;">GUEST VLAN  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:6810/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`192.168.50.0/24`</td><td style="height: 29.8px;">SERVER VLAN  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:6850/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`192.168.80.0/24`</td><td style="height: 29.8px;">IOT VLAN  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:6880/64</span>`</td></tr><tr style="height: 29.8px;"><td style="height: 29.8px;">  
</td><td style="height: 29.8px;">`192.168.100.0/24`</td><td style="height: 29.8px;">MGMT VLAN  
</td><td style="height: 29.8px;">`<span class="info-value svelte-13utf9w">fd42:dead:beef:6800/64</span>`</td></tr></tbody></table>

## Adding networks

### Caroline

- *Network* -&gt; *Interfaces* -&gt; *Devices*
    - Add `VLAN (802.1q)` on `eth1` for new VLAN tag
- *Network* -&gt; *Interfaces*
    - Add interface for the new device
    - Configure DHPC server on the new interface with options for default G/W and DNS server 
        - `3,192.168.80.1`
        - <div class="item" tabindex="0">`6,192.168.80.1`</div>
- *Network* -&gt; *Firewall* -&gt; *Zones*
    - Add zone for the new interface
- *Network* -&gt; *Firewall* -&gt; *Traffic rules*
    - Add rule for DHCP (`UDP 67`)
    - Add rule for DNS (`UDP+TCP 53`)
    - Add rule for ICMP
- *Network* -&gt; *DHCP and DNS* -&gt; *Devices &amp; Ports*
    - Add new interface to DHCP server *Listen interfaces*

## Switch configuration

<p class="callout info">**OpenWRT edit VLAN tag assignment** Network -&gt; Interfaces -&gt; Devices -&gt; `switch` (Bridge device) -&gt; Configure... -&gt; Bridge VLAN filtering</p>

## IPv6

### ULA

- [Unique local address](https://en.wikipedia.org/wiki/Unique_local_address)
- Use for private or local addressing.
- Prefix `<span class="ipaddr"><span style="padding-right: 1px;">fc00::</span><span style="padding-right: 1px;">/</span><span style="padding-right: 1px;">7</span></span>`
    - Prefix `<span class="ipaddr"><span style="padding-right: 1px;">fd00::</span><span style="padding-right: 1px;">/</span><span style="padding-right: 1px;">8</span></span>` format: 
        - Global ID: `<span class="ipaddr"><span style="padding-right: 1px;">fdxx:xxxx:xxxx::</span><span style="padding-right: 1px;">/</span><span style="padding-right: 1px;">48</span></span>` - `x`-es should be chosen random
        - Subnets (64k): `<span class="ipaddr"><span style="padding-right: 1px;">fdxx:xxxx:xxxx:ssss::</span><span style="padding-right: 1px;">/64</span></span>`
        - Expanded: `<span class="ipaddr"><span style="padding-right: 1px;">fdxx:xxxx:xxxx:ssss:0000:0000:0000:0000</span><span style="padding-right: 1px;">/128</span></span>`
    - <span class="ipaddr"><span style="padding-right: 1px;">Prefix `fc00::/8`</span><span style="padding-right: 1px;"> is not defined.</span></span>

<span class="ipaddr"><span style="padding-right: 1px;">For WireGuard the Global ID can be generated with `base64 -d | hexdump` from server's public key.</span></span>

Random ID can be made with `cat /dev/random | head -c5 | ruby -e 'puts STDIN.read.unpack("H*")'`.

Encode v4 in v6 example: `fd00:192:168::1/64`.

ULA: `fd42:dead:beef/48`

### IPv4 in IPv6

Example: `::ffff:192.0.2.1` -&gt; hex encoded `::ffff:c000:201`