+ mikrotik scripts

This commit is contained in:
Nico Schottelius 2020-08-07 15:03:09 +02:00
parent 5e966b852d
commit 8429201d0d
2 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,59 @@
#!/bin/sh
# Nico Schottelius, 2020-08-03
# Setup a standard crs326
if [ $# -ne 4 ]; then
echo "$0 <current-ip> <new-ipv6-network> <hostname-to-be-setup> <password>"
echo "Example:"
echo "$0 fe80::764d:28ff:fe09:9355%eth1 2a0a:e5c0:2::/64 mikrotik-crs326-8 \$(pass ...)"
exit 1
fi
ip=$1; shift
newip=$1; shift
hostname=$1; shift
password=$1; shift
target=$ip
bridge=bridge
conf() {
echo $@
ssh admin@${target} "$@"
}
commastring() {
echo $@ | sed 's/ /,/g'
}
conf "/system identity set name=$hostname"
conf "/interface bridge add name=$bridge"
################################################################################
# MTU
for i in $(seq 1 24); do
conf "/interface ethernet set ether$i mtu=9200 l2mtu=9204"
conf "/interface bridge port add bridge=$bridge interface=ether$i hw=yes"
done
for i in $(seq 1 2); do
conf "/interface ethernet set sfp-sfpplus$i mtu=9200 l2mtu=9204"
conf "/interface bridge port add bridge=$bridge interface=sfp-sfpplus$i hw=yes"
done
################################################################################
# IPv6 address, password
conf "/ipv6 address add eui-64=yes advertise=no address=$newip interface=$bridge"
conf "/ipv6 address print"
conf "/password old-password=\"\" new-password=$password confirm-new-password=$password"
# Show neigh
conf "/interface bridge host print where !local"
echo "do not forget to set a password"

View File

@ -0,0 +1,103 @@
#!/bin/sh
# Nico Schottelius, 2020-08-03
# Setup a standard crs326
if [ $# -ne 2 ]; then
echo "$0 <ip> <hostname-to-be-setup>"
echo "Example:"
echo "$0 fe80::764d:28ff:fe09:9355%eth1 mikrotik-crs326-8"
exit 1
fi
ip=$1; shift
hostname=$1; shift
password=$1; shift
target=$ip
bridge=bridgevlans
internal=10
coworking=15
server=11
other="8 16 18 33 34"
tagged="ether23 ether24 sfp-sfpplus1"
net_internal=2a0a:e5c0:2::/64
conf() {
echo $@
ssh admin@${target} "$@"
}
commastring() {
echo $@ | sed 's/ /,/g'
}
#set -x
# do this out of band -- see mikrotik-setup.sh
#conf "/password new-password=$password confirm-new-password=$password old-password=\"\""
conf "/system identity set name=$hostname"
conf "/interface bridge add name=$bridge"
################################################################################
# MTU
for i in $(seq 1 24); do
conf "/interface ethernet set ether$i mtu=9200 l2mtu=9204"
done
for i in $(seq 1 2); do
conf "/interface ethernet set sfp-sfpplus$i mtu=9200 l2mtu=9204"
done
################################################################################
# VLANs
# Internal ports 1-16
ifaces=""
for i in $(seq 1 16); do
conf "/interface bridge port add bridge=$bridge interface=ether$i hw=yes pvid=$internal"
ifaces="ether$i ${ifaces}"
done
# also tag the bridge for the vlan interface we need later
conf "/interface bridge vlan add bridge=$bridge tagged=$(commastring $tagged),$bridge untagged=$(commastring $ifaces) vlan-ids=$internal"
# Coworking 17-18
ifaces=""
for i in $(seq 17 18); do
conf "/interface bridge port add bridge=$bridge interface=ether$i hw=yes pvid=$coworking"
ifaces="ether$i ${ifaces}"
done
conf "/interface bridge vlan add bridge=$bridge tagged=$(commastring $tagged) untagged=$(commastring $ifaces) vlan-ids=$coworking"
# Server 19-20
ifaces=""
for i in $(seq 19 20); do
conf "/interface bridge port add bridge=$bridge interface=ether$i hw=yes pvid=$server"
ifaces="ether$i ${ifaces}"
done
conf "/interface bridge vlan add bridge=$bridge tagged=$(commastring $tagged) untagged=$(commastring $ifaces) vlan-ids=$server"
# Not modified 21-22
# Tagged 23-24, sfp-sfpplus1
for iface in $tagged; do
conf "/interface bridge port add bridge=$bridge interface=$iface hw=yes"
done
conf "/interface bridge vlan add bridge=$bridge tagged=$(commastring $tagged) vlan-ids=$(commastring $other)"
conf "/interface vlan add interface=$bridge vlan-id=$internal mtu=9200 name=internal"
conf "/ipv6 address add eui-64=yes advertise=no address=$net_internal interface=internal"
conf "/interface bridge set $bridge vlan-filtering=yes"
# Show neigh
conf "/interface bridge host print where !local"