VLAN-EN

Da PoliArch.

Altre Pagine: · Home Page · Documentazione · Downloads · Screenshots · Contatti

Introduction

VLANs allows to split a LAN. Linux accepts tagged traffic and shows every virtual interface as a different network interface (for example eth0_10 for the VLAN 10)

Configuration

Add a VLAN

# ip link add link INTERFACE name INTERFACE_VID type vlan id VID

Example:

# ip link add link eth0 name eth0_10 type vlan id 10

Type:

# ip link

to ensure that the eth0_10 interface has been correctly created.

Configure the VLAN

To add an IPv4 address to the just created interface and activate it:

# ip addr add IP/NETMASK brd BROADCAST-ADDR dev INTERFACE_VID
# ip link set dev INTERFACE_VID up

Example:

# ip addr add 192.168.100.1/24 brd 192.168.100.255 dev eth0_10
# ip link set dev eth0_10 up

Deconfigure a VLAN

To correctly deactivate a VLAN before remove it

# ip link set dev INTERFACE_VID down

Example:

# ip link set dev eth0_10 down

Remove a VLAN

To remove a VLAN

# ip link delete INTERFACE_VID

Example:

# ip link delete eth0_10

Script

VLAN Creation/Activation

Below there is a short script (integrated starting from the version 12.12) that allows the creation/activation of a VLAN

File: add_vlan.sh
#!/bin/sh
echo "== Welcome in the VLAN creation procedure =="
echo "VLAN Configuration"

# Interface to configure (for example eth0)
echo -n "Interface to configure (for example eth0): "
read nic_to_cfg

# VLAN ID to configure (for example 10)
echo -n "VLAN ID (for example 10): "
read vlan_id

# VLAN adding
ip link add link $nic_to_cfg name "$nic_to_cfg"_$vlan_id type vlan id $vlan_id

# Configuration
echo -n "IP to assign to the interface (for example 192.168.1.10): "
read ip_addr

echo -n "Netmask to assign to the interface (for example 255.255.255.0): "
read ip_netmask

echo -n "Broadcast address (for example 192.168.1.255): "
read ip_brd

ip addr add $ip_addr/$ip_netmask brd $ip_brd dev "$nic_to_cfg"_$vlan_id
ip link set dev "$nic_to_cfg"_$vlan_id up

if [ $? -eq 0 ] ; then
	echo "VLAN successfully created and activated!"
else
	echo "Error during VLAN activation!!"
fi

VLAN Deactivation/Removal

Below there is a short script (integrated starting from the version 12.12) that allows the VLAN deactivation/removal

File: del_vlan.sh
#!/bin/sh
echo "== Welcome in the VLAN removal procedure =="

# Interface to deconfigure (for example eth0)
echo -n "Interface to deconfigure (for example eth0): "
read nic_to_cfg

# ID of the VLAN to remove (for example 10)
echo -n "ID of the VLAN to remove (for example 10): "
read vlan_id

# Disable VLAN
ip link set dev "$nic_to_cfg"_$vlan_id down

# VLAN removal
ip link delete "$nic_to_cfg"_$vlan_id

if [ $? -eq 0 ] ; then
	echo "VLAN" $vlan_id "removed!"
else
	echo "Error during VLAN removal!"
fi

Useful links

  • Information VLAN (wikipedia)

Altre Pagine: · Home Page · Documentazione · Downloads · Screenshots · Contatti