Adding vlan to Ubuntu for ABillS

Let me give you an example of massively adding VLANs to Ubuntu Server.

Switch to the root user:

sudo -i

First of all, install the vlan package and load the 8021q module:

apt-get install vlan
modprobe 8021q

To autorun it after restarting the system, open the file /etc/modules, for example, in the text editor nano (Ctrl+X to exit, y/n to save or cancel changes):

nano /etc/modules

And add if it’s not there:


Create a script:

nano /etc/network/

Add content to it (in IFACE we specify the network interface for vlan, in VLANS – the VLAN list):

  /sbin/vconfig set_name_type VLAN_PLUS_VID_NO_PAD
  VLANS=`echo ${VLANS} | sed 'N;s/\n/ /' |sed 's/,/ /g'`
  for i in $VLANS; do
    if [[ $i =~ - ]]; then
      IFS='-' read -a start_stop <<< "$i"
      for cur_iface in `seq ${start_stop[0]} ${start_stop[1]}`;
        echo "${cur_iface}";
        /sbin/vconfig add ${IFACE} ${cur_iface}
        /sbin/ifconfig vlan${cur_iface} up
    echo "$i";
      /sbin/vconfig add ${IFACE} ${i}
      /sbin/ifconfig vlan${i} up

We make the script executable:

chmod +x /etc/network/

Run the script:


To autorun the script, open the configuration of the network interfaces:

nano /etc/network/interfaces

And add a line at the end of the file or in the network interface settings section:

post-up /etc/network/

See also my articles:
Configuring VLANs in Ubuntu
Install and configure accel-ppp (IPoE) for ABillS

Leave a comment

Leave a Reply