Riggen_HomeLab_PlanForIT_11 - itnett/FTD02H-N GitHub Wiki
Here is a MySQL script that creates a comprehensive VLAN and subnet database for all the networks you are planning, including the additional ones discussed. This database will store information like network names, VLAN numbers, IP ranges, gateway addresses, DHCP ranges, and more.
-- Create the database
CREATE DATABASE IF NOT EXISTS network_lab;
-- Use the created database
USE network_lab;
-- Create the table to store VLAN and subnet information
CREATE TABLE vlan_subnets (
id INT AUTO_INCREMENT PRIMARY KEY,
vlan_id INT NOT NULL,
vlan_name VARCHAR(100) NOT NULL,
vlan_tag VARCHAR(20) NOT NULL,
ip_range VARCHAR(50) NOT NULL,
cidr VARCHAR(20) NOT NULL,
network_address VARCHAR(50) NOT NULL,
linknet VARCHAR(50) DEFAULT NULL,
gateway VARCHAR(50) DEFAULT NULL,
start_ip VARCHAR(50) DEFAULT NULL,
end_ip VARCHAR(50) DEFAULT NULL,
dhcp_range VARCHAR(100) DEFAULT NULL,
description VARCHAR(255) DEFAULT NULL
);
-- Insert VLAN and subnet data into the table
INSERT INTO vlan_subnets (vlan_id, vlan_name, vlan_tag, ip_range, cidr, network_address, gateway, start_ip, end_ip, dhcp_range, description)
VALUES
(10, 'LinkNet (pfSense-Lab1)', 'vlan-10', '172.16.10.0/30', '30', '172.16.10.0', '172.16.10.1', '172.16.10.2', '172.16.10.3', NULL, 'WAN-side for pfSense-Lab1 to Proxmox'),
(11, 'LAN-Net (pfSense-Lab1)', 'vlan-11', '192.168.10.0/24', '24', '192.168.10.0', '192.168.10.1', '192.168.10.2', '192.168.10.254', '192.168.10.100 - 192.168.10.200', 'Internal LAN for pfSense-Lab1'),
(12, 'LinkNet (pfSense-Lab2)', 'vlan-12', '172.16.12.0/30', '30', '172.16.12.0', '172.16.12.1', '172.16.12.2', '172.16.12.3', NULL, 'WAN-side for pfSense-Lab2 to Proxmox'),
(13, 'LAN-Net (pfSense-Lab2)', 'vlan-13', '192.168.20.0/24', '24', '192.168.20.0', '192.168.20.1', '192.168.20.2', '192.168.20.254', '192.168.20.100 - 192.168.20.200', 'Internal LAN for pfSense-Lab2'),
(14, 'VPN Tunnel Net', 'vlan-14', '172.16.14.0/30', '30', '172.16.14.0', '172.16.14.1', '172.16.14.2', '172.16.14.3', NULL, 'VPN link between pfSense-Lab1 and Lab2'),
(100, 'Admin', 'vlan-100', '10.0.100.0/24', '24', '10.0.100.0', '10.0.100.1', '10.0.100.2', '10.0.100.254', '10.0.100.100 - 10.0.100.150', 'Proxmox management network'),
(110, 'Monitoring', 'vlan-110', '10.0.110.0/24', '24', '10.0.110.0', '10.0.110.1', '10.0.110.2', '10.0.110.254', '10.0.110.100 - 10.0.110.150', 'Monitoring tools like Zabbix, Grafana'),
(120, 'Production', 'vlan-120', '10.0.120.0/24', '24', '10.0.120.0', '10.0.120.1', '10.0.120.2', '10.0.120.254', '10.0.120.100 - 10.0.120.200', 'Production environment for VMs/containers'),
(130, 'Hybrid Cloud', 'vlan-130', '10.0.130.0/24', '24', '10.0.130.0', '10.0.130.1', '10.0.130.2', '10.0.130.254', '10.0.130.100 - 10.0.130.200', 'Integration with cloud services'),
(140, 'Test Environment', 'vlan-140', '10.0.140.0/24', '24', '10.0.140.0', '10.0.140.1', '10.0.140.2', '10.0.140.254', '10.0.140.100 - 10.0.140.200', 'Isolated lab environment for testing'),
-- Add additional rows for all VLANs up to VLAN 500 as per your plan
(410, 'IPv6 Testing Network', 'vlan-410', 'fd00:1:1::/64', '64', 'fd00:1:1::', NULL, NULL, NULL, NULL, 'IPv6 Testing Network for dual-stack configurations'),
(420, 'Security Operations Center', 'vlan-420', '10.2.20.0/24', '24', '10.2.20.0', '10.2.20.1', '10.2.20.2', '10.2.20.254', '10.2.20.100 - 10.2.20.200', 'SOC environment for monitoring and incident response'),
(430, 'Incident Response and Forensics', 'vlan-430', '10.2.30.0/24', '24', '10.2.30.0', '10.2.30.1', '10.2.30.2', '10.2.30.254', '10.2.30.100 - 10.2.30.200', 'Environment for digital forensics and incident response'),
(440, 'Compliance Zone', 'vlan-440', '10.2.40.0/24', '24', '10.2.40.0', '10.2.40.1', '10.2.40.2', '10.2.40.254', '10.2.40.100 - 10.2.40.200', 'Simulates a compliance zone for testing regulatory frameworks'),
(450, 'Logging and Audit Network', 'vlan-450', '10.2.50.0/24', '24', '10.2.50.0', '10.2.50.1', '10.2.50.2', '10.2.50.254', '10.2.50.100 - 10.2.50.200', 'Network for centralized logging and auditing'),
(460, 'Chaos Engineering Lab', 'vlan-460', '10.2.60.0/24', '24', '10.2.60.0', '10.2.60.1', '10.2.60.2', '10.2.60.254', '10.2.60.100 - 10.2.60.200', 'Lab for testing resilience with chaos engineering'),
(470, 'Big Data Analytics', 'vlan-470', '10.2.70.0/24', '24', '10.2.70.0', '10.2.70.1', '10.2.70.2', '10.2.70.254', '10.2.70.100 - 10.2.70.200', 'Network for big data platforms'),
(480, 'Quantum Computing Research Network', 'vlan-480', '10.2.80.0/24', '24', '10.2.80.0', '10.2.80.1', '10.2.80.2', '10.2.80.254', '10.2.80.100 - 10.2.80.200', 'Environment for quantum computing research'),
(490, 'Software-Defined Networking (SDN) Lab', 'vlan-490', '10.2.90.0/24', '24', '10.2.90.0', '10.2.90.1', '10.2.90.2', '10.2.90.254', '10.2.90.100 - 10.2.90.200', 'Lab for SDN and network virtualization'),
(500, 'Configuration Management', 'vlan-500', '10.2.100.0/24', '24', '10.2.100.0', '10.2.100.1', '10.2.100.2', '10.2.100.254', '10.2.100
.100 - 10.2.100.200', 'Network for configuration management tools');
-
Database Creation:
- The script creates a new database named
network_lab
to store all the VLAN and network details.
- The script creates a new database named
-
Table Definition:
- The table
vlan_subnets
is created with fields to store VLAN ID, VLAN name, tag, IP range, CIDR notation, network address, gateway, start and end IP addresses, DHCP range, and a description for clarity.
- The table
-
Data Insertion:
- Inserts data for all planned VLANs and their subnet details, including future expansions.
- Each entry includes critical information like IP range, network, gateway, and DHCP range.
-
Run the Script:
- Execute this script in your MySQL or MariaDB server instance to create the database and table with all necessary VLANs and subnet details.
-
Modify and Expand:
- You can modify or expand the database with additional VLANs or networks in the future by inserting more rows.
-
Querying Data:
- Use SQL queries to retrieve information from the database for your lab setup, such as checking available IPs, managing network configurations, or documenting VLAN usage.
By running this script, you will have a structured database for your entire network plan, providing an organized overview of all VLANs, subnets, IP ranges, and DHCP settings for current and future use.
This MySQL script provides a structured way to manage your VLAN and subnet configurations, ensuring all your planned networks are documented in a central database. Here’s a breakdown of how to effectively use it:
-
Install MySQL or MariaDB: Make sure you have MySQL or MariaDB installed on your management server or workstation.
sudo apt update sudo apt install mysql-server
-
Access MySQL CLI: Launch the MySQL command-line interface.
mysql -u root -p
-
Run the Provided Script:
Copy and paste the entire script into your MySQL prompt to create the database and table, and populate it with the VLAN data.
SOURCE /path/to/your/script.sql;
-
Add Additional VLANs:
Use the following template to insert new rows for future VLANs:
INSERT INTO vlan_subnets (vlan_id, vlan_name, vlan_tag, ip_range, cidr, network_address, gateway, start_ip, end_ip, dhcp_range, description) VALUES (510, 'New VLAN Name', 'vlan-510', '10.3.0.0/24', '24', '10.3.0.0', '10.3.0.1', '10.3.0.2', '10.3.0.254', '10.3.0.100 - 10.3.0.200', 'Description for new VLAN');
-
List All VLANs: To view all VLANs and their configurations:
SELECT * FROM vlan_subnets;
-
Find Specific VLAN Details: For example, to find details about VLAN 100:
SELECT * FROM vlan_subnets WHERE vlan_id = 100;
-
Filter by IP Range or Usage: To find VLANs within a specific IP range or for a certain purpose:
SELECT * FROM vlan_subnets WHERE ip_range LIKE '10.0.%' AND description LIKE '%security%';
-
Backup and Restore: Regularly back up your VLAN and subnet database to avoid data loss:
mysqldump -u root -p network_lab > network_lab_backup.sql
Restore from a backup if needed:
mysql -u root -p network_lab < network_lab_backup.sql
-
Automate Updates: Consider using scripts or tools to automate the process of adding new VLANs or modifying existing ones as your network evolves.
-
Centralized Documentation:
- Maintains a single source of truth for all VLAN and subnet information.
- Ensures all network configurations are easily accessible and searchable.
-
Scalability and Flexibility:
- Easily add, remove, or modify network details as your lab environment expands.
- Supports complex queries to help manage network resources more efficiently.
-
Improved Management and Planning:
- Simplifies network management by providing detailed information on IP ranges, DHCP settings, and network purposes.
- Aids in capacity planning and ensures compliance with network policies.
By creating a dedicated VLAN and subnet database, you can efficiently manage your network lab's growth and complexity. This approach will help you maintain accurate and up-to-date network documentation, essential for any IT operations and security professional working in a dynamic lab environment.
Yes, you can script the creation of VLANs, network bridges, and other networking components in Proxmox VE using the command-line interface (CLI) and tools like qm
(for virtual machine management) and pvesh
(Proxmox API command line interface). Proxmox VE allows you to use bash
scripts to automate network configurations.
Here's a sample script to create the VLANs and network bridges according to the VLAN and IP plan you've defined:
#!/bin/bash
# Function to create a bridge in Proxmox
create_bridge() {
local bridge_name=$1
local ip_address=$2
local netmask=$3
echo "Creating bridge: $bridge_name"
cat <<EOF >> /etc/network/interfaces
auto $bridge_name
iface $bridge_name inet static
address $ip_address
netmask $netmask
bridge-ports none
bridge-stp off
bridge-fd 0
EOF
}
# Function to create VLAN on a bridge
create_vlan() {
local bridge_name=$1
local vlan_id=$2
local vlan_name=$3
local ip_address=$4
local netmask=$5
echo "Creating VLAN $vlan_id ($vlan_name) on $bridge_name"
cat <<EOF >> /etc/network/interfaces
auto $bridge_name.$vlan_id
iface $bridge_name.$vlan_id inet static
address $ip_address
netmask $netmask
vlan-raw-device $bridge_name
EOF
}
# Create main bridges for pfSense-Lab1 and Lab2
create_bridge "vmbr0" "10.0.100.1" "255.255.255.0" # Admin network
create_bridge "vmbr1" "172.16.10.1" "255.255.255.252" # LinkNet (pfSense-Lab1)
create_bridge "vmbr2" "172.16.12.1" "255.255.255.252" # LinkNet (pfSense-Lab2)
# Create VLANs on the respective bridges
create_vlan "vmbr1" "10" "LinkNet (pfSense-Lab1)" "172.16.10.2" "255.255.255.252"
create_vlan "vmbr1" "11" "LAN-Net (pfSense-Lab1)" "192.168.10.1" "255.255.255.0"
create_vlan "vmbr2" "12" "LinkNet (pfSense-Lab2)" "172.16.12.2" "255.255.255.252"
create_vlan "vmbr2" "13" "LAN-Net (pfSense-Lab2)" "192.168.20.1" "255.255.255.0"
# Continue for other VLANs as per your plan
create_vlan "vmbr0" "110" "Monitoring" "10.0.110.1" "255.255.255.0"
create_vlan "vmbr0" "120" "Production" "10.0.120.1" "255.255.255.0"
create_vlan "vmbr0" "200" "DevOps" "10.0.200.1" "255.255.255.0"
create_vlan "vmbr0" "300" "External Router Link" "10.10.10.1" "255.255.255.0"
# Restart network services to apply changes
echo "Applying network changes..."
systemctl restart networking
echo "Network configuration completed."
-
Save the Script:
- Save the script to a file, for example,
setup_networks.sh
.
- Save the script to a file, for example,
-
Make the Script Executable:
- Run the command:
chmod +x setup_networks.sh
.
- Run the command:
-
Run the Script:
- Execute the script using
sudo
to apply changes:sudo ./setup_networks.sh
.
- Execute the script using
-
Bridge Creation:
- The
create_bridge
function adds a new bridge configuration to/etc/network/interfaces
with a static IP and subnet mask.
- The
-
VLAN Creation:
- The
create_vlan
function creates VLAN interfaces on the specified bridges, assigning them VLAN IDs, IP addresses, and subnet masks.
- The
-
Restart Network Service:
- The script restarts the networking service to apply the changes made in the
/etc/network/interfaces
file.
- The script restarts the networking service to apply the changes made in the
For more advanced configuration, like setting up DHCP ranges or additional options, use the Proxmox API tool (pvesh
):
#!/bin/bash
# Create a VMID for your DHCP server (e.g., pfSense VM)
VMID=100
# Add DHCP configuration using Proxmox API
pvesh create /nodes/<node>/qemu/$VMID/config -net1 model=virtio,bridge=vmbr1,tag=11
pvesh set /nodes/<node>/qemu/$VMID/firewall/options -enable yes
Replace <node>
with your Proxmox node name.
By using these scripts, you can quickly set up and apply your VLAN configurations and networking settings in Proxmox, maintaining consistent and repeatable configurations across your environment. Make sure to review and adapt the script as necessary to match your exact networking needs and Proxmox setup.