#!/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