Linux Vlan

From Leo's Notes
Revision as of 16:57, 21 May 2014 by Leo (talk | contribs)
This page was last edited on 21 May 2014, at 16:57.

You can make your linux box act like a smart switch by using this script:

#!/bin/bash


echo 0 >  /proc/sys/net/ipv4/ip_forward

modprobe 8021q

# Uplink
Uplink="p4p2"

# Ports
Port1="p1p1"
Port2="p1p2"
Port3="p4p1"

# Vlans
Vlans="911 1010 7"

# Make sure everything else is down until we reconfigure
ifconfig $Uplink down

ifconfig $Port1 down
ifconfig $Port2 down
ifconfig $Port3 down


#
# Set up the vlans on the uplink port.
#
for Vlan in $Vlans ; do
	vconfig add $Uplink $Vlan
	brctl addbr br$Vlan
	brctl addif br$Vlan $Uplink.$Vlan
done

#
# Add our interfaces to the bridged VLANs
#
brctl addif br911 $Port1
brctl addif br7 $Port2
brctl addif br1010 $Port3


# Start things up
ifconfig p4p1 up
for Vlan in $Vlans ; do
	ifconfig p4p1.$Vlan up
	ifconfig br$Vlan up
done

ifconfig $Port1 up
ifconfig $Port2 up
ifconfig $Port3 up


# This machine is on deptnfs, so get an IP on this interface
#dhclient br1010
ifconfig br1010 172.17.10.9 netmask 255.255.255.0
route add default gw 172.17.10.1