# How to monitor VLANs on Linux (Ubuntu with Netplan )

## Introduction

Domotz is able to scan and monitor automatically all the networks attached to the operating system it is running on. For this reason to scan and monitor VLANs, you might configure a virtual network interface for each VLAN on your Linux operating system where the Agent runs on.
For more general information about monitoring VLANs in Domotz please see: [https://help.domotz.com/user-guide/vlan-network-interface-configuration/](https://help.domotz.com/user-guide/vlan-network-interface-configuration/)

## Prerequisites

Before proceeding please check:

1 - that the device were the Domotz Agent is installed is plugged in on to a trunk port of your switch which is able to see all your VLANs.

2 - test that you are able to ping hosts on those subnets from the Linux computer which the Domotz Agent is installed on

## Manual Configuration

You can do this on Ubuntu by editing the netplan file which resides in the /etc/netplan/ directory and has the .yaml extension.
For more information about this please see here: [https://vitux.com/how-to-configure-networking-with-netplan-on-ubuntu/](https://vitux.com/how-to-configure-networking-with-netplan-on-ubuntu/)

You can download here some examples of those files that can be modified and applied to your Domotz Agent:

- [VLANs with primary nic ip set to DHCP](https://raw.githubusercontent.com/domotz/support_scripts/main/netplan_examples/01-vlans-dynamic-ip.yaml)
- [VLANs with primary nic set to STATIC ip address](https://raw.githubusercontent.com/domotz/support_scripts/main/netplan_examples/02-vlans-static-ip.yaml)

You can then make a backup of your current netplan file (you can just rename it to *.yaml.backup) and rename the new netplanfile to 00-network-setup.yaml.

Then perform:

```
sudo netplan try
```

Then:

```
sudo netplan apply
```

After that your Domotz Agent will show the new vlans as being scanned which will appear in the format $nicname.2 (for example eth0.2 - which means VLAN2 attached to eth0).

## Assisted Configuration

To configure the network and vlans you might use also the following bash scripts:
1) Network Configurator: [Download Network Configurator Example script](https://raw.githubusercontent.com/domotz/support_scripts/refs/heads/main/linux_agent/network_config.sh)

2) VLAN Configurator: [Download VLAN Setup Configurator Example Script](https://raw.githubusercontent.com/domotz/support_scripts/refs/heads/main/linux_agent/add_vlans.sh)

### Step by Step

Follow the detailed steps below to configure the primary network interface and VLANs on your Ubuntu host:

**1. Access the host**

- Locally (direct console access), or
- Remotely via SSH

**2. Install wget (if not already installed)**

Run the following command to ensure `wget` is available:

```
sudo apt update
sudo apt install wget -y
```

**3. Download the Configuration Scripts**

Use wget to fetch the scripts for configuring the primary network interface and VLANs:

```
cd ~
wget https://raw.githubusercontent.com/domotz/support_scripts/refs/heads/main/linux_agent/network_config.sh
wget https://raw.githubusercontent.com/domotz/support_scripts/refs/heads/main/linux_agent/add_vlans.sh
```

**4. Set Script Permissions**

Make both scripts executable:

```
sudo chmod +x network_config.sh add_vlans.sh
```

**5. Run the Network Configuration Script**

Execute the script for primary interface setup:

```
sudo ~/network_config.sh
```

The script will prompt you to enter the required network information for the primary interface.

**6. Run the VLAN Configuration Script**

Execute the VLAN setup Script:

```
sudo ~/add_vlans.sh
```

You will be asked for:

- The network interface name
- The number of VLANs you would like to configure (excluding the untagged VLAN already set up with the previous script)

**7. Apply the Netplan Configuration**

Apply your updated network configuration:

If you are connected via SSH, your connection will terminate when the network configuration is applied. Whenever possible, perform these steps with local console access to avoid losing connectivity.

```
sudo netplan try
sudo netplan apply
```

Please note that in case of an error, such as:
`awk: cannot open "/etc/netplan/00-installer-config.yaml" (No such file or directory)`
Please edit the script and modify the path of your **.yaml** file according to its name and path on your Linux host.
The Netplan file path value is defined in the NETPLAN_FILE variable:

Modify the Netplan file path in the script.

1. Locate the line that begins with `NETPLAN_FILE=`. This variable sets the netplan file path.
2. Change the file path within the quotation marks to the path of your netplan configuration file. The default path shown is `/etc/netplan/00-installer-config.yaml`.
3. Save the script after making the change to ensure your configuration is correctly targeted.

## Testing VLAN Configuration

To test, please issue:

```
sudo ifconfig
```

you will get something like this:

```
eth0      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX
          inet addr:192.168.1.250  Bcast:192.168.1.255  Mask:255.255.254.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2963441738 errors:0 dropped:1537311 overruns:0 frame:0
          TX packets:2492320545 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1140723218 (1.1 GB)  TX bytes:394942035 (394.9 MB)

eth0.103  Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX
          inet addr:192.168.103.250  Bcast:192.168.103.255 Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:504612755 errors:0 dropped:0 overruns:0 frame:0
          TX packets:422335283 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:25634206918 (25.6 GB)  TX bytes:18165979372 (18.1 GB)

eth0.252  Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX
          inet addr:192.168.252.254  Bcast:192.168.252.255 Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:528968305 errors:0 dropped:0 overruns:0 frame:0
          TX packets:449295251 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:34981287899 (34.9 GB)  TX bytes:19762756952 (19.7 GB)

eth0.253  Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX
          inet addr:192.168.253.254  Bcast:192.168.253.255 Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4965237 errors:0 dropped:0 overruns:0 frame:0
          TX packets:400524664 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:237801810 (237.8 MB)  TX bytes:16902032617 (16.9 GB)
```

In Domotz instead:

Managing Sites in the Inventory.

1. Navigate to the "Inventory" section and select the "Sites" tab at the top to view site-related data.
2. Review the statistics: "1002 Sites" for total sites, "88 Offline" for sites not currently active, "525 With Important Offline Devices" indicating critical offline devices, "159 With Security Issues" highlighting security concerns, and "185 Inactive" with no current activity.
3. In the table, locate the "Site Integrations" column. Click "Add" to set up new integrations for each site listed.

Network Setup Overview

1. At the top, the status of the network is indicated as "Online."
2. Under "Attached Networks," a description explains that the networks listed are identified by the Domotz Agent as connected to the host NIC. Devices on these networks are found by MAC address.
3. Three specific network identifiers are displayed: "eth0.103," "eth0.252," and "eth0.253." These represent different Layer-2 networks.

In the case above, you see VLAN103, VLAN252, VLAN253 attached to the eth0 interface.
