How to Set Up DHCP for Multiple VLANs on Linux

Save

A virtual local area network, OR VLAN, provides the ability to create multiple LANs within a single physical network. To set up DHCP for the VLANs, first set up the network interfaces for each VLAN and then establish the DHCP settings for each VLAN. When you configure DHCP, treat each VLAN as though it were a separate physical interface on the machine, just as a DHCP client does when requesting a new address.

  • Install the VLAN support package. For example, type:

    apt-get install vlan

  • Edit the network interfaces file. Assign a static configuration to the physical network adapter if it doesn't already exist. Establish the IP address and subnet mask, the network address and the broadcast address. For example:

    auto eth0
    iface eth0 inet static
    address 192.168.100.1
    netmask 255.255.255.0
    network 192.168.100.0
    broadcast 192.168.100.255

  • Create a virtual network adapter for each VLAN. Establish its network addresses with a static assignment. Attach the virtual adapter to the physical adapter with "vlan_raw_device." For example:

    iface eth0.101 inet static
    address 10.16.2.1
    netmask 255.255.255.0
    network 10.16.2.0
    broadcast 10.16.2.255
    vlan_raw_device eth0

    iface eth0.102 inet static
    address 172.16.0.1
    netmask 255.255.0.0
    network 172.16.0.0
    broadcast 172.16.255.255

  • Edit the DHCP configuration file and define the DHCP configuration for each virtual network adapter. Establish the DHCP range and set the DHCP lease time. Set DHCP options such as the router address, network subnet mask and broadcast address, domain name server addresses and forwarding policy. For example:

    subnet 10.16.2.0 netmask 255.255.255.0 {
    range 10.16.2.100 10.16.2.249;
    default-lease-time 86400;
    max-lease-time 86400;
    option routers 10.16.2.1;
    option subnet-mask 255.255.255.0;
    option broadcast-address 10.16.2.255;
    option dns-servers 192.168.1.1;
    option ip-forwarding off;
    }

    subnet 172.16.0.0 netmask 255.255.255.0 {
    range 172.16.99.1 172.16.99.249;
    default-lease-time 86400;
    max-lease time 86400;
    option routers 172.16.0.1;
    option subnet-mask 255.255.0.0;
    option broadcast-address 172.16.255.255;
    option dns-servers 192.168.1.1;
    option ip-forwarding off;
    }

  • Restart the network services and test the VLAN configuration to ensure the network packets are tagged correctly and that each client receives an IP address through DHCP.

References

  • Photo Credit Hemera Technologies/AbleStock.com/Getty Images
Promoted By Zergnet

Comments

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!