VLAN configuration for UNIX hosts

From Wiki
Jump to: navigation, search

Mac OS X and FreeBSD

FreeBSD needs

device          vlan
device          miibus

loaded.

OS X just works.

sudo ifconfig vlan3 create
sudo ifconfig vlan3 vlan 3 vlandev en0
sudo ifconfig vlan3 inet 10.0.0.3 netmask 255.255.255.0
sudo ipconfig set vlan3 dhcp

# To revert:
sudo ifconfig vlan3 destroy

To bring up interfaces at boot time in FreeBSD.

# vi /etc/rc.conf

ifconfig_fxp0="up"
ifconfig_vlan0="inet 192.168.200.126 netmask 255.255.255.0 vlan 200 vlandev fxp0"
ifconfig_vlan1="inet 198.168.10.126 netmask 255.255.255.0 vlan 10 vlandev fxp0"

FreeBSD 9 (maybe earlier)

vlans_vr3="vlan5 vlan6 vlan7"
create_args_vlan5="vlan 5 inet 172.16.4.1/24"
create_args_vlan6="vlan 6 inet 172.16.7.1/24"
create_args_vlan7="vlan 7 inet 172.16.8.1/24"

Debian Linux

For Xen

This is more complex, so it has its own page.

Configure Whilst Running

Load the required module and make sure it loads next time.

# modprobe 8021q
# echo 8021q >> /etc/modules

Get vconfig et al.

# apt-get install vlan

Create your VLANs.

# vconfig add eth1 2
# vconfig add eth1 3

Assign IP addresses.

# ifconfig eth1 0.0.0.0
# ifconfig eth1.2 192.168.0.1 broadcast 192.168.0.255 netmask 255.255.255.0 up
# ifconfig eth1.3 10.0.0.1 broadcast 10.0.0.255 netmask 255.255.255.0 up

Configuration at Boot

Bring the interfaces up and assign addresses at boot time.

Lenny onwards:

To bring up a VLAN interface unconfigured (e.g. for a bridge):

auto vlan2
iface vlan2 inet manual
  vlan_raw_device eth1

auto vlan3
iface vlan3 inet manual
  vlan_raw_device eth1

Or, with an IP address (note static vs. manual):

auto vlan2
iface vlan2 inet static
  address 192.168.0.1
  netmask 255.255.255.0
  network 192.168.0.0
  broadcast 192.168.0.255
  vlan_raw_device eth1

auto vlan3
iface vlan3 inet static
  address 10.0.0.1
  netmask 255.255.255.0
  network 10.0.0.0
  broadcast 10.0.0.255
  vlan_raw_device eth1

Older (pre-Lenny) versions:

# Bring up eth1 at boot time, but don't assign any IP address:
iface eth1 inet manual
      pre-up ifconfig $IFACE up
      post-down ifconfig $IFACE down

# IP address for VLAN 2:
auto eth1.2 
iface eth1.2 inet static
        address 192.168.0.1 
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255

# IP address for VLAN 3:
auto eth1.3
iface eth1.3 inet static
        address 10.0.0.1
        netmask 255.255.255.0
        network 10.0.0.0
        broadcast 10.0.0.255

Physical interface needs to be brought up at boot time with no address. This is now only needed in older versions of Debian like Etch.

# vi /etc/network/if-up.d/eth1

 #!/bin/sh
 ifconfig eth1 up

# chmod +x /etc/network/if-up.d/eth1