EanderAlx.org

Linux, Virtualization and whatever I find interesting ...

User Tools


Site Tools


linux:arch_vlan_rcconf

Arch: VLANs in rc.conf

  • the package vconfig is needed in order to use VLANs
Deprecated

 pacman -Sy vconfig
  • There were several approaches in the Forum to configure VLANs in rc.conf. The Problem is: therefor its necessary to do extensive changes in “/etc/rc.d/network”.
  • After a update its possible that all changes are gone.
  • I wasn't interested in doing multiple changes in “/etc/rc.d/network” after updates.
  • That's why I write my own variant. It's only needed to change two lines.
  • With my Script it's only Possible to add VLAN and not to remove.
  • “vconfig” is designed that after a reboot VLAN interface are not configured.
  • If you want to achieve more, further changes have to include into “/etc/rc.d/network” and I wanted to avoid this.

Setup:

  • First the Script, put it into “/etc/conf.d”.
create_vlans
#!/bin/bash
#FILES
#       /proc/net/vlan/config
#       /proc/net/vlan/[vlan-device]
# rc.conf:
# VLANs
#
#VLAN_DEVS=(eth0.6)
######
# /etc/rc.d/network
# vlan settings
#[ -f /etc/conf.d/create_vlans ] && . /etc/conf.d/create_vlans
#
### Variables ###
LSMOD_PATH="/usr/bin/lsmod"
VLAN_PATH="/proc/net/vlan/"
VCONFIG_PATH="/usr/sbin/vconfig"
#
### Functions ###
vlan_add()
{
	if [ -e $VCONFIG_PATH ];then
		/usr/bin/lsmod | grep 8021q > /dev/null 2> /dev/null
		if [ $? == 0 ];then
			if [ ! -e $VLAN_PATH$1 ];then
				VLANS_DEV=$1
				VLAN_IFACE=`echo $VLANS_DEV | cut -d "." -f1`
				VLAN_ID=`echo $VLANS_DEV | cut -d "." -f2`
				$VCONFIG_PATH add $VLAN_IFACE $VLAN_ID > /dev/null 2> /dev/null
			fi
		else
			echo "8021q Module not loaded"
		fi
	else
		echo "please install vconfig: pacman -S vconfig"
	fi
}
vlan_rem()
{
	vconfig rem $1
}
#
### Main ###
if [ ! -e $LSMOD_PATH ];then
	echo "/usr/bin/lsmod not available, unable to check vlan module"
else
	for vlans in ${VLAN_DEVS[@]}; do
		vlan_add $vlans   
	done
fi
  • Adapt “/etc/rc.d/network” Attention: the changed are gone after update initscripts.
  • Add these lines before the other includes.
# vlan settings
[ -f /etc/conf.d/create_vlans ] && . /etc/conf.d/create_vlans

configure VLANs

  • VLAN interfaces now can be entered in the rc.conf.
  • With “VLAN_DEVS=()” the interfaces were created [Interface.VLAN_ID].
  • Then you can assign an IP-Adresse to the interface. The interface name is “vlan6” for example. This name must not contain “.” or “ ”.

Example:

#VLANs
VLAN_DEVS=(eth0.6)

interface=eth0
address=
netmask=
broadcast=
gateway=

interface=eth0.6
address=172.16.10.1
netmask=255.255.0.0
broadcast=172.16.255.255
gateway=

Comments

Hi,

you don't have to change the init script.

IMO it should also work if you add [ -f /etc/conf.d/create_vlans ] && . /etc/conf.d/create_vlans into one of the files which are already sourced by network: /etc/conf.d/{wireless,bonding,bridges,dhcpcd}

Kind regards, Andrwe

1 |
Andrwe
| 08.04.2012 21:46 | reply
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
linux/arch_vlan_rcconf.txt · Last modified: 23.03.2013 17:34 by eanderalx