This is a script for a MikroTik CRS 'Router on a Stick' setup

This is part 2 of 2 for setting up a MikroTik Routerboard with Fibre, with a MikroTik CRS Switch off that with multiple VLANS



There is a trunk port coming into port ether1 with vlans 10, 20 & 30
Ports 2-8 are outputting vlan 10
Ports 9-16 are outputting vlan 20
Ports 17-24 are outputting vlan 30
Management IP is set to 192.168.10.2 which is coming on vlan 10

# set the ethernet interfaces to point to the master interface (in the same switch group)

/interface ethernet
set [ find default-name=ether1 ] name=ether1-master-local
set [ find default-name=ether2 ] master-port=ether1-master-local name=ether2-slave-local
set [ find default-name=ether3 ] master-port=ether1-master-local name=ether3-slave-local
set [ find default-name=ether4 ] master-port=ether1-master-local name=ether4-slave-local
set [ find default-name=ether5 ] master-port=ether1-master-local name=ether5-slave-local
set [ find default-name=ether6 ] master-port=ether1-master-local name=ether6-slave-local
set [ find default-name=ether7 ] master-port=ether1-master-local name=ether7-slave-local
set [ find default-name=ether8 ] master-port=ether1-master-local name=ether8-slave-local
set [ find default-name=ether9 ] master-port=ether1-master-local name=ether9-slave-local
set [ find default-name=ether10 ] master-port=ether1-master-local name=ether10-slave-local
set [ find default-name=ether11 ] master-port=ether1-master-local name=ether11-slave-local
set [ find default-name=ether12 ] master-port=ether1-master-local name=ether12-slave-local
set [ find default-name=ether13 ] master-port=ether1-master-local name=ether13-slave-local
set [ find default-name=ether14 ] master-port=ether1-master-local name=ether14-slave-local
set [ find default-name=ether15 ] master-port=ether1-master-local name=ether15-slave-local
set [ find default-name=ether16 ] master-port=ether1-master-local name=ether16-slave-local
set [ find default-name=ether17 ] master-port=ether1-master-local name=ether17-slave-local
set [ find default-name=ether18 ] master-port=ether1-master-local name=ether18-slave-local
set [ find default-name=ether19 ] master-port=ether1-master-local name=ether19-slave-local
set [ find default-name=ether20 ] master-port=ether1-master-local name=ether20-slave-local
set [ find default-name=ether21 ] master-port=ether1-master-local name=ether21-slave-local
set [ find default-name=ether22 ] master-port=ether1-master-local name=ether22-slave-local
set [ find default-name=ether23 ] master-port=ether1-master-local name=ether23-slave-local
set [ find default-name=ether24 ] master-port=ether1-master-local name=ether24-slave-local
set [ find default-name=sfp1 ] master-port=ether1-master-local name=sfp1-slave-local

# add vlans to the access ports
/interface ethernet switch ingress-vlan-translation
# set ports 2-8 for vlan 10
add customer-vid=0 new-customer-vid=10 ports=ether2-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=10 ports=ether3-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=10 ports=ether4-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=10 ports=ether5-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=10 ports=ether6-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=10 ports=ether7-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=10 ports=ether8-slave-local sa-learning=yes
# set ports 9-16 for vlan 20
add customer-vid=0 new-customer-vid=20 ports=ether9-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether10-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether11-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether12-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether13-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether14-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether15-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether16-slave-local sa-learning=yes
# set ports 17-24 for vlan 30
add customer-vid=0 new-customer-vid=30 ports=ether17-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=30 ports=ether18-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=20 ports=ether19-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=30 ports=ether20-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=30 ports=ether21-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=30 ports=ether22-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=30 ports=ether23-slave-local sa-learning=yes
add customer-vid=0 new-customer-vid=30 ports=ether24-slave-local sa-learning=yes

# setup our trunk port (ether1) with the vlan tags on it (10,20,30)
/interface ethernet switch egress-vlan-tag
add tagged-ports=ether1-master-local,switch1-cpu vlan-id=10
add tagged-ports=ether1-master-local,switch1-cpu vlan-id=20
add tagged-ports=ether1-master-local,switch1-cpu vlan-id=30

# vlans are required to be defined in the vlan table. we're adding the switch1-cpu to vlan 10 so we can have a management ip address on it
/interface ethernet switch vlan
add ports=ether1-master-local,ether10-slave-local,switch1-cpu vlan-id=10
add ports=ether1-master-local,ether12-slave-local vlan-id=20
add ports=ether1-master-local,ether13-slave-local vlan-id=30


# we're going to add the vlan tag on this interface for a management ip
/interface vlan
add interface=ether1-master-local l2mtu=1584 name=ether1.master-local.10 vlan-id=10

/ip address
add address=192.168.10.2/24 interface=ether1.master-local.10 network=192.168.10.0

/ip route
add gateway=192.168.10.1