diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2018-12-22 00:10:15 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2018-12-22 00:10:15 -0500 |
| commit | 4854c0a648114b4d2421b3fa05a29345cb65e97d (patch) | |
| tree | b22ee573fac811129ec95da466304e1c5a678b77 | |
| parent | ec9d797d5f7ac83324cf50d05c3d368b8ef43669 (diff) | |
| download | dotfiles-4854c0a648114b4d2421b3fa05a29345cb65e97d.tar.gz dotfiles-4854c0a648114b4d2421b3fa05a29345cb65e97d.tar.xz | |
Add a small script for setting up the network on a Linux server
| -rw-r--r-- | net.sh | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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 + |
