Skip to content

Instantly share code, notes, and snippets.

@ToasterDEV
Created January 12, 2024 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToasterDEV/ac3ad3ef037092b7a61c265023c631a6 to your computer and use it in GitHub Desktop.
Save ToasterDEV/ac3ad3ef037092b7a61c265023c631a6 to your computer and use it in GitHub Desktop.
#!/bin/sh
#### VLAN Mapper Script for AsusWRT Merlin HND Platform #########################################
#v2023-01-12
#By ToasterDEV, spliced together mostly from: https://gist.github.com/Jimmy-Z/6120988090b9696c420385e7e42c64c4?permalink_comment_id=4475965#gistcomment-4475965 by DervilRus
#### Instructions ###############################################################################
#You will need to have installed AsusWRT-Merlin as the firmware
#And configure at least one USB drive using amtm
#When that's done, save this script as "/jffs/scripts/services-start"
#Add the execution permission to the script by running "chmod a+x /jffs/scripts/services-start"
#And then reboot the unit by running "reboot"
#### Port Mapping (Test and modify as needed per model) #########################################
# GT-AX11000
#
# eth0 Physical port WAN
# eth1 Physical port 1
# eth2 Physical port 2
# eth3 Physical port 3
# eth4 Physical port 4
# eth5 Physical port 2.5GbE
#
# eth6 WiFi 2.4GHz
# eth7 WiFi 5.0GHz
#
# wl0.1 WiFi 2.4GHz guest1
# wl1.1 WiFi 5.0GHz-1 guest1
# wl2.1 WiFi 5.0GHz-2 guest1
#
# wl0.2 WiFi 2.4GHz guest2
# wl1.2 WiFi 5.0GHz-1 guest2
# wl2.2 WiFi 5.0GHz-2 guest2
#
# wl0.3 WiFi 2.4GHz guest3
# wl1.3 WiFi 5.0GHz-1 guest3
# wl2.3 WiFi 5.0GHz-2 guest3
#################################################################################################
ip="192.168.3.2" # Default network static IP
#Remember to set up the unit to ONLY use this address before running anything!
taggedPort="eth5" # Tagged "WAN/Uplink" port
nonTaggedPorts="eth0 eth1 eth2 eth3 eth4 eth6 eth7" # Other ports (Tagged with the LAN VLAN ID)
vlanId0=10 # Default network VLAN ID
vlanId1=40 # Guest network 1 VLAN ID (Guests)
vlanId2=20 # Guest network 2 VLAN ID (IoT)
vlanId3=30 # Guest network 3 VLAN ID (Security)
guest1_1="wl0.1" # Guest network 1 interface 2.4GHz
guest1_2="wl1.1" # Guest network 1 interface 5GHz-1
guest1_3="wl2.1" # Guest network 1 interface 5GHz-2
#VLAN_1_port_0="" # VLAN ID #1 Ethernet interface
#VLAN_1_port_1="" # VLAN ID #1 Ethernet interface
#VLAN_1_port_2="" # VLAN ID #1 Ethernet interface
#VLAN_1_port_3="" # VLAN ID #1 Ethernet interface
#VLAN_1_port_4="" # VLAN ID #1 Ethernet interface
guest2_1="wl0.2" # Guest network 2 interface 2.4GHz
guest2_2="wl1.2" # Guest network 2 interface 5GHz-1
guest2_3="wl2.2" # Guest network 2 interface 5GHz-2
#VLAN_2_port_0="" # VLAN ID #2 Ethernet interface
#VLAN_2_port_1="" # VLAN ID #2 Ethernet interface
#VLAN_2_port_2="" # VLAN ID #2 Ethernet interface
#VLAN_2_port_3="" # VLAN ID #2 Ethernet interface
#VLAN_2_port_4="" # VLAN ID #2 Ethernet interface
guest3_1="wl0.3" # Guest network 3 interface 2.4GHz
guest3_2="wl1.3" # Guest network 3 interface 5GHz-1
guest3_3="wl2.3" # Guest network 3 interface 5GHz-2
#VLAN_3_port_0="" # VLAN ID #3 Ethernet interface
#VLAN_3_port_1="" # VLAN ID #3 Ethernet interface
#VLAN_3_port_2="" # VLAN ID #3 Ethernet interface
#VLAN_3_port_3="" # VLAN ID #3 Ethernet interface
#VLAN_3_port_4="" # VLAN ID #3 Ethernet interface
# Fix physical ports not working
ethswctl -c hw-switching -o disable
# Remove separate networks from default bridge
brctl delif br0 ${taggedPort}
brctl delif br0 ${guest1_1}
brctl delif br0 ${guest1_2}
brctl delif br0 ${guest1_3}
brctl delif br0 ${guest2_1}
brctl delif br0 ${guest2_2}
brctl delif br0 ${guest2_3}
brctl delif br0 ${guest3_1}
brctl delif br0 ${guest3_2}
brctl delif br0 ${guest3_3}
#brctl delif br0 ${VLAN_1_port_0}
#brctl delif br0 ${VLAN_1_port_1}
#brctl delif br0 ${VLAN_1_port_2}
#brctl delif br0 ${VLAN_1_port_3}
#brctl delif br0 ${VLAN_1_port_4}
#brctl delif br0 ${VLAN_2_port_0}
#brctl delif br0 ${VLAN_2_port_1}
#brctl delif br0 ${VLAN_2_port_2}
#brctl delif br0 ${VLAN_2_port_3}
#brctl delif br0 ${VLAN_2_port_4}
#brctl delif br0 ${VLAN_3_port_0}
#brctl delif br0 ${VLAN_3_port_1}
#brctl delif br0 ${VLAN_3_port_2}
#brctl delif br0 ${VLAN_3_port_3}
#brctl delif br0 ${VLAN_3_port_4}
# Add VLANs
ip link add link ${taggedPort} name ${taggedPort}.${vlanId0} type vlan id ${vlanId0}
ip link add link ${taggedPort} name ${taggedPort}.${vlanId1} type vlan id ${vlanId1}
ip link add link ${taggedPort} name ${taggedPort}.${vlanId2} type vlan id ${vlanId2}
ip link add link ${taggedPort} name ${taggedPort}.${vlanId3} type vlan id ${vlanId3}
ip link set ${taggedPort}.${vlanId0} up
ip link set ${taggedPort}.${vlanId1} up
ip link set ${taggedPort}.${vlanId2} up
ip link set ${taggedPort}.${vlanId3} up
ip link add link ${VLAN_1_port_0} name ${VLAN_1_port_0}.${vlanId1} type vlan id ${vlanId1}
#ip link add link ${VLAN_1_port_1} name ${VLAN_1_port_1}.${vlanId1} type vlan id ${vlanId1}
#ip link add link ${VLAN_1_port_2} name ${VLAN_1_port_2}.${vlanId1} type vlan id ${vlanId1}
#ip link add link ${VLAN_1_port_3} name ${VLAN_1_port_3}.${vlanId1} type vlan id ${vlanId1}
#ip link add link ${VLAN_1_port_4} name ${VLAN_1_port_4}.${vlanId1} type vlan id ${vlanId1}
#ip link add link ${VLAN_2_port_0} name ${VLAN_2_port_0}.${vlanId1} type vlan id ${vlanId2}
ip link add link ${VLAN_2_port_1} name ${VLAN_2_port_1}.${vlanId2} type vlan id ${vlanId2}
ip link add link ${VLAN_2_port_2} name ${VLAN_2_port_2}.${vlanId2} type vlan id ${vlanId2}
ip link add link ${VLAN_2_port_3} name ${VLAN_2_port_3}.${vlanId2} type vlan id ${vlanId2}
ip link add link ${VLAN_2_port_4} name ${VLAN_2_port_4}.${vlanId2} type vlan id ${vlanId2}
#ip link add link ${VLAN_3_port_0} name ${VLAN_3_port_0}.${vlanId3} type vlan id ${vlanId3}
#ip link add link ${VLAN_3_port_1} name ${VLAN_3_port_1}.${vlanId3} type vlan id ${vlanId3}
#ip link add link ${VLAN_3_port_2} name ${VLAN_3_port_2}.${vlanId3} type vlan id ${vlanId3}
#ip link add link ${VLAN_3_port_3} name ${VLAN_3_port_3}.${vlanId3} type vlan id ${vlanId3}
#ip link add link ${VLAN_3_port_4} name ${VLAN_3_port_4}.${vlanId3} type vlan id ${vlanId3}
ip link set ${VLAN_1_port_0}.${vlanId1} up
#ip link set ${VLAN_1_port_1}.${vlanId1} up
#ip link set ${VLAN_1_port_2}.${vlanId1} up
#ip link set ${VLAN_1_port_3}.${vlanId1} up
#ip link set ${VLAN_1_port_4}.${vlanId1} up
#ip link set ${VLAN_2_port_0}.${vlanId2} up
ip link set ${VLAN_2_port_1}.${vlanId2} up
ip link set ${VLAN_2_port_2}.${vlanId2} up
ip link set ${VLAN_2_port_3}.${vlanId2} up
ip link set ${VLAN_2_port_4}.${vlanId2} up
#ip link set ${VLAN_3_port_0}.${vlanId3} up
#ip link set ${VLAN_3_port_1}.${vlanId3} up
#ip link set ${VLAN_3_port_2}.${vlanId3} up
#ip link set ${VLAN_3_port_3}.${vlanId3} up
#ip link set ${VLAN_3_port_4}.${vlanId3} up
# Default network
ifconfig br0 "${ip}" netmask 255.255.255.0
brctl addif br0 ${taggedPort}.${vlanId0}
nvram set lan_ifnames="${nonTaggedPorts} ${taggedPort}.${vlanId0}"
nvram set br0_ifnames="${nonTaggedPorts} ${taggedPort}.${vlanId0}"
brctl stp br0 on
# Guest network 1
brctl addbr br1
brctl addif br1 ${taggedPort}.${vlanId1}
brctl addif br1 ${guest1_1}
brctl addif br1 ${guest1_2}
brctl addif br1 ${guest1_3}
brctl stp br1 on
ip link set br1 up
nvram set lan1_ifnames="${guest1_1} ${guest1_2} ${guest1_3} ${taggedPort}.${vlanId1}"
nvram set br1_ifnames="${guest1_1} ${guest1_2} ${guest1_3} ${taggedPort}.${vlanId1}"
nvram set ${guest1_1}_ap_isolate=0
wl -i ${guest1_1} ap_isolate 0
nvram set ${guest1_2}_ap_isolate=0
wl -i ${guest1_2} ap_isolate 0
nvram set ${guest1_3}_ap_isolate=0
wl -i ${guest1_3} ap_isolate 0
# Guest network 2
brctl addbr br2
brctl addif br2 ${taggedPort}.${vlanId2}
brctl addif br2 ${guest2_1}
brctl addif br2 ${guest2_2}
brctl addif br2 ${guest2_3}
brctl stp br2 on
ip link set br2 up
nvram set lan2_ifnames="${guest2_1} ${guest2_2} ${guest2_3}${taggedPort}.${vlanId2}"
nvram set br2_ifnames="${guest2_1} ${guest2_2} ${guest2_3}${taggedPort}.${vlanId2}"
nvram set ${guest2_1}_ap_isolate=0
wl -i ${guest2_1} ap_isolate 0
nvram set ${guest2_2}_ap_isolate=0
wl -i ${guest2_2} ap_isolate 0
nvram set ${guest2_3}_ap_isolate=0
wl -i ${guest2_3} ap_isolate 0
# Guest network 3
brctl addbr br3
brctl addif br3 ${taggedPort}.${vlanId3}
brctl addif br3 ${guest3_1}
brctl addif br3 ${guest3_2}
brctl addif br3 ${guest3_3}
brctl stp br3 on
ip link set br3 up
nvram set lan3_ifnames="${guest3_1} ${guest3_2} ${guest3_3} ${taggedPort}.${vlanId3}"
nvram set br3_ifnames="${guest3_1} ${guest3_2} ${guest3_3} ${taggedPort}.${vlanId3}"
nvram set lan3_ifname="br3"
nvram set br3_ifname="br3"
nvram set ${guest3_1}_ap_isolate=0
wl -i ${guest3_1} ap_isolate 0
nvram set ${guest2_2}_ap_isolate=0
wl -i ${guest2_2} ap_isolate 0
nvram set ${guest2_3}_ap_isolate=0
wl -i ${guest2_3} ap_isolate 0
#Bridges for Ethernet ports
#Bridge #0
brctl addbr br4
brctl addif br4 ${taggedPort}.${vlanId1}
#brctl addif br4 ${taggedPort}.${vlanId2}
#brctl addif br4 ${taggedPort}.${vlanId3}
brctl addif br4 ${VLAN_1_port_0}.${vlanId1}
#brctl addif br4 ${VLAN_2_port_0}.${vlanId2}
#brctl addif br4 ${VLAN_3_port_0}.${vlanId3}
brctl stp br4 on
ip link set br4 up
nvram set lan4_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_0}.${vlanId1}"
#nvram set lan4_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_0}.${vlanId2}"
#nvram set lan4_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_0}.${vlanId3}"
nvram set br4_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_0}.${vlanId1}"
#nvram set br4_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_0}.${vlanId2}"
#nvram set br4_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_0}.${vlanId3}"
nvram set lan4_ifname="br4"
nvram set br4_ifname="br4"
#Bridge #1
brctl addbr br5
#brctl addif br5 ${taggedPort}.${vlanId1}
brctl addif br5 ${taggedPort}.${vlanId2}
#brctl addif br5 ${taggedPort}.${vlanId3}
#brctl addif br5 ${VLAN_1_port_1}.${vlanId1}
brctl addif br5 ${VLAN_2_port_1}.${vlanId2}
#brctl addif br5 ${VLAN_3_port_1}.${vlanId3}
brctl stp br5 on
ip link set br5 up
#nvram set lan5_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_1}.${vlanId1}"
nvram set lan5_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_1}.${vlanId2}"
#nvram set lan5_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_1}.${vlanId3}"
#nvram set br5_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_1}.${vlanId1}"
nvram set br5_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_1}.${vlanId2}"
#nvram set br5_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_1}.${vlanId3}"
nvram set lan5_ifname="br5"
nvram set br5_ifname="br5"
#Bridge #2
brctl addbr br6
#brctl addif br6 ${taggedPort}.${vlanId1}
brctl addif br6 ${taggedPort}.${vlanId2}
#brctl addif br6 ${taggedPort}.${vlanId3}
#brctl addif br6 ${VLAN_1_port_2}.${vlanId1}
brctl addif br6 ${VLAN_2_port_2}.${vlanId2}
#brctl addif br6 ${VLAN_3_port_2}.${vlanId3}
brctl stp br6 on
ip link set br6 up
#nvram set lan6_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_2}.${vlanId1}"
nvram set lan6_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_2}.${vlanId2}"
#nvram set lan6_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_2}.${vlanId3}"
#nvram set br6_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_2}.${vlanId1}"
nvram set br6_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_2}.${vlanId2}"
#nvram set br6_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_2}.${vlanId3}"
nvram set lan6_ifname="br6"
nvram set br6_ifname="br6"
#Bridge #3
brctl addbr br7
#brctl addif br7 ${taggedPort}.${vlanId1}
brctl addif br7 ${taggedPort}.${vlanId2}
#brctl addif br7 ${taggedPort}.${vlanId3}
#brctl addif br7 ${VLAN_1_port_3}.${vlanId1}
brctl addif br7 ${VLAN_2_port_3}.${vlanId2}
#brctl addif br7 ${VLAN_3_port_3}.${vlanId3}
brctl stp br7 on
ip link set br7 up
#nvram set lan7_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_3}.${vlanId1}"
nvram set lan7_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_3}.${vlanId2}"
#nvram set lan7_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_3}.${vlanId3}"
#nvram set br7_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_3}.${vlanId1}"
nvram set br7_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_3}.${vlanId2}"
#nvram set br7_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_3}.${vlanId3}"
nvram set lan7_ifname="br7"
nvram set br7_ifname="br7"
#Bridge #4
brctl addbr br8
#brctl addif br8 ${taggedPort}.${vlanId1}
brctl addif br8 ${taggedPort}.${vlanId2}
#brctl addif br8 ${taggedPort}.${vlanId3}
#brctl addif br8 ${VLAN_1_port_4}.${vlanId1}
brctl addif br8 ${VLAN_2_port_4}.${vlanId2}
#brctl addif br8 ${VLAN_3_port_4}.${vlanId3}
brctl stp br8 on
ip link set br8 up
#nvram set lan8_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_4}.${vlanId1}"
nvram set lan8_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_4}.${vlanId2}"
#nvram set lan8_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_4}.${vlanId3}"
#nvram set br8_ifnames="${taggedPort}.${vlanId1} ${VLAN_1_port_4}.${vlanId1}"
nvram set br8_ifnames="${taggedPort}.${vlanId2} ${VLAN_2_port_4}.${vlanId2}"
#nvram set br8_ifnames="${taggedPort}.${vlanId3} ${VLAN_3_port_4}.${vlanId3}"
nvram set lan8_ifname="br8"
nvram set br8_ifname="br8"
# Restart eapd
killall eapd
eapd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment