Adding vlan to Ubuntu for ABillS

Here is an example of adding a VLAN to Ubuntu Server for ABillS.

Switch to the root user:

sudo su

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:

8021q

Create a script:

nano /etc/network/vlan.sh

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

#!/bin/bash
IFACE="eth1"
VLANS="51,200-350,700-1000"

  /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]}`;
      do
        echo "${cur_iface}";
        /sbin/vconfig add ${IFACE} ${cur_iface}
        /sbin/ifconfig vlan${cur_iface} up
      done
    else
    echo "$i";
      /sbin/vconfig add ${IFACE} ${i}
      /sbin/ifconfig vlan${i} up
    fi;
  done

We make the script executable:

chmod +x /etc/network/vlan.sh

Run the script:

/etc/network/vlan.sh

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

nano /etc/network/interfaces

And add at the end of the line:

post-up /etc/network/vlan.sh

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

Подписаться на IT Blog (RU) по Email
Subscribe to IT Blog (EN) by Email

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a Reply