aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/vlan.sh48
-rw-r--r--net/workstation.sh48
2 files changed, 96 insertions, 0 deletions
diff --git a/net/vlan.sh b/net/vlan.sh
new file mode 100644
index 0000000..2ca1f0c
--- /dev/null
+++ b/net/vlan.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+set -e
+# A short script to setup the network on a server creating bridges for each
+# vlan specified.
+
+# Why? NetworkManager sucks and so do other network utilities. This is simple
+# and fits the need of creating a virtual machine host that can place VMs
+# on any one of the vlans.
+
+defaultrouter="10.9.8.7"
+nameservers="10.11.12.13 10.12.14.16"
+vlan_ifs="eth0 eth1 eth3"
+eth0_vlan_ids="10"
+eth0_vlan_10_inet="10.10.1.2/24"
+eth1_vlan_ids="20 34 38 60 160 240 432"
+eth1_vlan_60_inet="10.60.8.2/24"
+eth3_vlan_ids=50
+eth3_vlan_50_inet="10.50.0.1/24"
+echo="echo"
+
+for if in $vlan_ifs ; do
+ $echo ip link set up $if
+ eval vlan_ids="\$${if}_vlan_ids"
+
+ for id in $vlan_ids; do
+ $echo ip link add link $if name ${if}.${id} type vlan id ${id}
+ $echo brctl addbr vlan${id}
+ $echo brctl addif vlan${id} ${if}.${id}
+ $echo ip link set up ${if}.${id}
+
+ eval inet="\$${if}_vlan_${id}_inet"
+ if ! [ -z "$inet" ] ; then
+ $echo ip -4 addr add "$inet" dev ${if}.${id}.
+ fi
+ done
+done
+
+$echo ip route add default via $defaultrouter
+
+$echo truncate -s 0 /etc/resolv.conf
+for ns in $nameservers ; do
+ if ! [ -z "$echo" ] ; then
+ echo echo nameserver $ns '>>' /etc/resolv.conf
+ else
+ echo nameserver $ns >> /etc/resolv.conf
+ fi
+done
+
diff --git a/net/workstation.sh b/net/workstation.sh
new file mode 100644
index 0000000..7639a6e
--- /dev/null
+++ b/net/workstation.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# net.sh
+# Sets up a bridged network specifically for use on a laptop or workstation.
+# Called by `/etc/rc.local` on my Void Linux machine
+
+bridges="vbr0 br0"
+
+br0_ifs="enp2s0"
+# vbr0_ifs=""
+vbr0_inet="10.33.33.1/24"
+vbr0_inet6="fc00:333::1/64"
+
+assign_inet_for_if() {
+_if="$1" ; shift
+eval _inet="\$${_if}_inet"
+for addr in $_inet ; do
+ ip -4 addr add $addr dev $br
+done
+}
+
+assign_inet6_for_if() {
+_if="$1" ; shift
+eval _inet="\$${_if}_inet6"
+for addr in $_inet ; do
+ ip -6 addr add $addr dev $br
+done
+}
+
+for br in $bridges ; do
+ brctl addbr $br
+ ip link set up "$br"
+
+ eval _ifs="\$${br}_ifs"
+ for _if in $_ifs ; do
+ brctl addif "$br" "$_if"
+ ip link set up "$_if"
+ done
+
+ assign_inet_for_if "${br}"
+ assign_inet6_for_if "${br}"
+done
+
+for _if in $_ifs ; do
+ assign_inet_for_if "$_if"
+ assign_inet6_for_if "$_if"
+
+ ip link set up "$_if"
+done