Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
155 lines
4.9 KiB
PowerShell
155 lines
4.9 KiB
PowerShell
# Configure OpenWrt Network Stack
|
|
# This script provides instructions and automation for OpenWrt VM network configuration
|
|
|
|
param(
|
|
[string]$OpenWrtIP = "10.10.60.100",
|
|
[string]$OpenWrtUser = "root",
|
|
[string]$ConfigFile = "openwrt-config.tar.gz"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
Write-Host "=========================================" -ForegroundColor Cyan
|
|
Write-Host "OpenWrt Network Configuration" -ForegroundColor Cyan
|
|
Write-Host "=========================================" -ForegroundColor Cyan
|
|
|
|
Write-Host "`nThis script helps configure OpenWrt VM for network routing and VLAN management." -ForegroundColor Yellow
|
|
Write-Host "OpenWrt should be deployed as a VM on the Router server." -ForegroundColor Yellow
|
|
|
|
# Check if OpenWrt is accessible
|
|
Write-Host "`nChecking OpenWrt connectivity..." -ForegroundColor Yellow
|
|
try {
|
|
$ping = Test-Connection -ComputerName $OpenWrtIP -Count 1 -Quiet
|
|
if ($ping) {
|
|
Write-Host "OpenWrt is reachable at $OpenWrtIP" -ForegroundColor Green
|
|
}
|
|
else {
|
|
Write-Host "OpenWrt is not reachable at $OpenWrtIP" -ForegroundColor Red
|
|
Write-Host "Please ensure OpenWrt VM is running and accessible." -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
}
|
|
catch {
|
|
Write-Host "Cannot reach OpenWrt. Please verify:" -ForegroundColor Red
|
|
Write-Host " 1. OpenWrt VM is running" -ForegroundColor White
|
|
Write-Host " 2. IP address is correct: $OpenWrtIP" -ForegroundColor White
|
|
Write-Host " 3. Network connectivity exists" -ForegroundColor White
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "`nOpenWrt Configuration Steps:" -ForegroundColor Cyan
|
|
Write-Host "1. SSH to OpenWrt: ssh $OpenWrtUser@$OpenWrtIP" -ForegroundColor White
|
|
Write-Host "2. Configure network interfaces" -ForegroundColor White
|
|
Write-Host "3. Configure VLANs" -ForegroundColor White
|
|
Write-Host "4. Configure firewall zones" -ForegroundColor White
|
|
Write-Host "5. Configure mwan3 for multi-WAN" -ForegroundColor White
|
|
|
|
Write-Host "`nExample OpenWrt network configuration:" -ForegroundColor Yellow
|
|
$openWrtConfig = @"
|
|
# /etc/config/network
|
|
|
|
config interface 'loopback'
|
|
option ifname 'lo'
|
|
option proto 'static'
|
|
option ipaddr '127.0.0.1'
|
|
option netmask '255.0.0.0'
|
|
|
|
# WAN interfaces (i350-T4)
|
|
config interface 'wan1'
|
|
option ifname 'eth1'
|
|
option proto 'dhcp'
|
|
option metric '10'
|
|
|
|
config interface 'wan2'
|
|
option ifname 'eth2'
|
|
option proto 'dhcp'
|
|
option metric '20'
|
|
|
|
config interface 'wan3'
|
|
option ifname 'eth3'
|
|
option proto 'dhcp'
|
|
option metric '30'
|
|
|
|
config interface 'wan4'
|
|
option ifname 'eth4'
|
|
option proto 'dhcp'
|
|
option metric '40'
|
|
|
|
# LAN interfaces with VLANs
|
|
config interface 'lan'
|
|
option type 'bridge'
|
|
option ifname 'eth0'
|
|
option proto 'static'
|
|
option ipaddr '10.10.60.1'
|
|
option netmask '255.255.255.0'
|
|
|
|
# VLAN 10 - Storage
|
|
config interface 'vlan10'
|
|
option ifname 'eth0.10'
|
|
option proto 'static'
|
|
option ipaddr '10.10.10.1'
|
|
option netmask '255.255.255.0'
|
|
|
|
# VLAN 20 - Compute
|
|
config interface 'vlan20'
|
|
option ifname 'eth0.20'
|
|
option proto 'static'
|
|
option ipaddr '10.10.20.1'
|
|
option netmask '255.255.255.0'
|
|
|
|
# VLAN 30 - App Tier
|
|
config interface 'vlan30'
|
|
option ifname 'eth0.30'
|
|
option proto 'static'
|
|
option ipaddr '10.10.30.1'
|
|
option netmask '255.255.255.0'
|
|
|
|
# VLAN 40 - Observability
|
|
config interface 'vlan40'
|
|
option ifname 'eth0.40'
|
|
option proto 'static'
|
|
option ipaddr '10.10.40.1'
|
|
option netmask '255.255.255.0'
|
|
|
|
# VLAN 50 - Dev/Test
|
|
config interface 'vlan50'
|
|
option ifname 'eth0.50'
|
|
option proto 'static'
|
|
option ipaddr '10.10.50.1'
|
|
option netmask '255.255.255.0'
|
|
|
|
# VLAN 60 - Management
|
|
config interface 'vlan60'
|
|
option ifname 'eth0.60'
|
|
option proto 'static'
|
|
option ipaddr '10.10.60.1'
|
|
option netmask '255.255.255.0'
|
|
|
|
# VLAN 99 - DMZ
|
|
config interface 'vlan99'
|
|
option ifname 'eth0.99'
|
|
option proto 'static'
|
|
option ipaddr '10.10.99.1'
|
|
option netmask '255.255.255.0'
|
|
"@
|
|
|
|
Write-Host $openWrtConfig -ForegroundColor Gray
|
|
|
|
Write-Host "`nTo apply configuration:" -ForegroundColor Yellow
|
|
Write-Host "1. Copy configuration to OpenWrt" -ForegroundColor White
|
|
Write-Host "2. Edit /etc/config/network on OpenWrt" -ForegroundColor White
|
|
Write-Host "3. Run: /etc/init.d/network reload" -ForegroundColor White
|
|
|
|
Write-Host "`nFor automated configuration, use SSH to push config:" -ForegroundColor Yellow
|
|
Write-Host " ssh $OpenWrtUser@$OpenWrtIP 'cat > /etc/config/network' < network-config.txt" -ForegroundColor White
|
|
|
|
Write-Host "`nNext Steps:" -ForegroundColor Cyan
|
|
Write-Host "1. Run setup-mwan3.ps1 for multi-WAN configuration" -ForegroundColor White
|
|
Write-Host "2. Run configure-vlans.ps1 for VLAN setup" -ForegroundColor White
|
|
Write-Host "3. Run setup-firewall-zones.ps1 for firewall rules" -ForegroundColor White
|
|
|
|
Write-Host "`n=========================================" -ForegroundColor Cyan
|
|
Write-Host "OpenWrt Network Configuration Complete" -ForegroundColor Cyan
|
|
Write-Host "=========================================" -ForegroundColor Cyan
|
|
|