How-to-Create VLAN on Linux (with Cisco Catalyst Switch)

Source: Internet
Author: User

The article I want to share and configure VLAN on Linux through Cisco Catalyst Switch.

Requirements:

1. Linux installed on a PC with one or more NICs (Network Interface Card). I Use the Centos 5.4 using 2.6.18-164.11.1.EL5PAE kernel. It should is applicable on other Linux distros such as Slackware, Ubuntu, Fedora, Debian, etc.
2. Cisco Catalyst Switch 2950
3.2 Pc/laptop running WINDOWS/LINUX/BSD/MACOSX
4.3 Straight Cables

This tutorial is based-on Network Diagram below:


Here is the full steps.

1. Load 802.1q module into the system

By default, the 802.1q module is not loaded so we firstly has to load it. You can check the whether it is already loaded or not by using the ' lsmod ' command.

Lsmod |grep 802

If There is nothing shown by lsmod command, it means the module have not been loaded yet. Run ' modprobe ' to load it.

Modprobe 8021q

Make sure the module is successfully loaded by running the ' lsmod ' again

Lsmod |grep 8028021q                  24649  0

If you see something similar like above, the 8021q have been successfully loaded.

2. Create VLAN Interface

We'll use Eth1 interface in the Linux box. We have to bring the interface up without IP address assigned to it before we can use it.

Ifconfig eth1 0.0.0.0 up

We'll create Interface VLAN one-on-A and VLAN-on-this eth1 interface. To create a VLAN interface, use ' vconfig add ' command as below:

Vconfig add eth1 11Added vlan with vid = = one-to-if-:eth1:-vconfig add eth1 12Added VLAN with vid = = to If-:eth1:-

these commands above would create devices eth1.11 and eth1.12 to your system. Linux would consider these as another network devices so can configure and assign IP address like other.
you also see the VLAN interfaces by typing ' ifconfig-a ' command.

ifconfig-aeth1.11   Link encap:ethernet  HWaddr 00:30:48:bf:4e:bd          Broadcast multicast  mtu:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b) eth1.12   Link encap:ethernet  HWaddr 00:30:48:bf:4e:bd          Broadcast multicast  mtu:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 Carrier : 0          collisions:0 txqueuelen:0          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

3. Assign IP address to the VLAN interfaces

The VLAN interfaces were successfully created on the previous step. Now we assign IP address on those interfaces using Ifconfig command as below:

Ifconfig eth1.11 192.168.11.254 netmask 255.255.255.0 upifconfig eth1.12 192.168.12.254 netmask 255.255.255.0 up

Make sure, the IP addresses were assigned successfully on the interfaces.

 ifconfig eth1.11eth1.11 Link encap:ethernet HWaddr 00:30:48:bf:4e:bd inet          addr:192.168.11.254 bcast:192.168.11.255 mask:255.255.255.0 up broadcast multicast MTU:1500 Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0  (0.0 b) TX bytes:0 (0.0 b) ifconfig eth1.12eth1.12 Link encap:ethernet HWaddr 00:30:48:bf:4e:bd inet addr:192.168.12.254 bcast:19 2.168.12.255 mask:255.255.255.0 up broadcast multicast mtu:1500 metric:1 RX packets:0 errors:0 Droppe          d:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0  (0.0 b) TX bytes:0 (0.0 b)  

Until This step, creating and configuring VLANs has been done on the Linux box. Now we is going to configure VLAN and trunk on the Cisco Catalyst switch.

4. Configure Cisco Catalyst Switch, add VLAN database, Configure interface access VLAN and trunk

As said before, we use VLAN one-by-one and VLAN-on-this tutorial. So those VLAN must is added into the VLAN database of the switch.

switch#conf terminalenter configuration commands, one per line.  End with Cntl/z.switch (config) #vlan 11switch (Config-vlan) #name test-vlan11switch (config-vlan) #exitswitch (config) # VLAN 12switch (Config-vlan) #name test-vlan12switch (config-vlan) #exitswitch (config) #exitswitch #wr membuilding Configuration ... [Ok]switch#show VLAN | Include Test-vlan11   test-vlan11                      active12   test-vlan12                      Active

Vlan one and each has been successfully added to the database and active.

now we have to configure 3 ports in the Cisco Catalyst Switch. 1 port was for trunk Betwe En the switch and Linux box and 2 ports is for Pc-a and Pc-b.
we'll use port fa0/16 as trunk port and FA0/14 and FA0/15 as VLAN access Port Connect Ed to pc-a and Pc-b respectively. Below is the commands:

switch#conf terminalenter configuration commands, one per line. End with Cntl/z.switch (config) #int f0/14switch (config-if) #description to_pc-aswitch (config-if) #swi acc VLAN 11switch ( CONFIG-IF) #no Shutdownswitch (config-if) #exitswitch (config) #int f0/15switch (config-if) #description To_pc-bswitch ( CONFIG-IF) #swi ACC vlan 12switch (config-if) #no Shutdownswitch (config-if) #exitswitch (config) #int F0/16switch ( CONFIG-IF) #description Trunk_to_linux_routerswitch (config-if) #switchport Trunk allowed VLAN 11,12switch (config-if) # Switchport mode Trunkswitch (config-if) #no Shutdownswitch (config-if) #exitswitch (config) #exitswitch #wr membuilding Configuration ... [Ok]switch#switch#show Running-config interface f0/14building configuration ... Current configuration:82 bytes!interface FASTETHERNET0/14 description to_pc-a switchport access VLAN 11endswitch#show RU Nning-config Interface f0/15building configuration ... Current configuration:82 bytes!interface FASTETHERNET0/15 description to_pc-b switchport access VLAn 12endswitch#show running-config interface f0/16building configuration ... Current configuration:129 bytes!interface fastethernet0/16 description trunk_to_linux_router switchport Trunk allowed V LAN 11,12 switchport mode trunkendswitch#

The configurations on both Linux box and Switch has completed.
Now it's the time to test whether pc-a and Pc-b can ping to the same network on the Linux box. Make sure the cables is connected properly to all ports on the devices.

5. Test Ping to Linux box using VLAN IP address

Test from Pc-a:

C:\Users\Fuad nahdi>ping 192.168.11.254Pinging 192.168.11.254 with + bytes of data:reply from 192.168.11.254:bytes=3 2 time=1ms ttl=64reply from 192.168.11.254:bytes=32 time

Test from Pc-b:

C:\Users\Fuad nahdi>ping 192.168.12.254Pinging 192.168.12.254 with + bytes of data:reply from 192.168.12.254:bytes=3 2 time=2ms ttl=64reply from 192.168.12.254:bytes=32 time

6. Make everything active at boot

Everything we have the done above are temporary configuration, meaning that it'll be a cleared from the configuration when we Reboo T or shutdown the Linux box.
To make it permanent or active at boot, simply add the following lines into the rc.local file (e.g Centos:/etc/rc.local; Slackware:/etc/rc.d/rc.local):

Modprobe 8021qifconfig eth1 0.0.0.0 upvconfig add eth1 11vconfig add eth1 12ifconfig eth1.11 192.168.11.254 netmask 255.25 5.255.0 upifconfig eth1.12 192.168.12.254 netmask 255.255.255.0 up

How-to-Create VLAN on Linux (with Cisco Catalyst Switch)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.