Linux Vlan: Difference between revisions

From Leo's Notes
This page was last edited on 29 March 2015, at 06:11.
mNo edit summary
mNo edit summary
Line 3: Line 3:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
#!/bin/bash
#!/bin/bash
echo 0 >  /proc/sys/net/ipv4/ip_forward
echo 0 >  /proc/sys/net/ipv4/ip_forward


Line 62: Line 60:
route add default gw 172.17.10.1
route add default gw 172.17.10.1


</syntaxhighlight>




</syntaxhighlight>


[[Category:Linux]]
[[Category:Linux]]
[[Category:Networking]]
[[Category:Todo]]
{{Navbox Linux}}

Revision as of 06:11, 29 March 2015

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