9

I appear to have some fundamental misunderstanding of how VLANs work on Linux, and I'm hoping the good people here can educate me.

Cast: One Cisco 3560, one VLAN, and one Linux box [1].

Cisco  ---------------  Linux
    ge0/1           eth0

The Cisco has a Vlan 37 interface, with IP address 10.40.37.252/24. I want to place 10.40.37.1/24 on the Linux box.

When the Cisco de-encapsulates vlan 37, everything works fine [2]:

# Cisco 
interface Vlan37
    ip address 10.40.37.252/24

interface GigabitEthernet 0/1
    switchport mode access
    switchport access vlan 37

# Linux
ip link set eth0 up
ip addr add 10.40.37.1/24 dev eth0

$ ping 10.40.37.252 && echo It works

However, when I set the port to trunking and assign vlan 37 on the Linux side, it stops working:

# Cisco
interface GigabitEthernet 0/1
    switchport trunk encapsulation dot1q
    switchport mode trunk
    ! [3] [4] [7]

# Linux
vconfig add eth0 37
ip link set eth0.37 up
ifconfig eth0 0.0.0.0 up # ensure no address
ip addr add 10.40.37.1/24 dev eth0.37

$ ping 10.40.37.252 || echo Why does this not work

What am I missing here?

Edit: Solutions:

Shane's question about the mac address table led me to a solution: Use "ip addr" to set different unique L2 (MAC) addresses on each of the VLAN sub-interfaces, and it suddenly works.

Another possible solution that I didn't try (because my hardware is too old) is using "ethtool" to disable VLAN offloading by the NIC itself, and forcing the kernel to deal with the tags.

Thank you Shane!

Edit: More info as per comments:

The overall goal is to have three vlans (public, private, oam&p) terminating on three individual IP addresses on the linux box, with different applications binding to the local addresses. I can expand further if necessary, but I'm trying to keep the problem description and discussion simple, since before I can have three vlans working, I kind of need one to be working. :)

Antoine --> ifup versus ifconfig makes no difference.

Pepoluan --> I'm assuming this is what you were looking for. Note the lack of references by phy drivers is apparently normal. [5]

$ lsmod | grep 802
    8021q   25545 1 cxgb3

Handyman -->

$ ifconfig eth0
    eth0  Link encap: Ethernet HWaddr 00:17:08:92:87:22
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:0 [...]
    TX packets:31932 errors:0 dropped:0 overruns:0 carrier:0 

$ ifconfig eth0.37
    eth0.37 Link encap: Ethernet HWaddr 00:17:08:92:87:22
    UP BROADCAST RUNNING MULTICAST MUT:1500 Metric:1
    RX packets: 0 [...]
    TX packets:32024 errors:90 dropped:0 overruns:0 carrier:0

$ cat /proc/net/vlan/config
    VLAN Dev Name | VLAN ID
    Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
    eth0.37 | 37 | eth0

Chuck --> wireshark and/or tcpdump do not show the tags, but this is apparently a normal limitation on Linux, due to the processing order of vlan handling and pcap in the kernel [6]. Also, the untagged VLAN is set to 1 [7].

[1] I've tried this with both CentOS 5.5 and Ubuntu 11.04, and both have the same issue.

[2] Note the configs are not a cut&paste, so any typos here are simply my bad memory.

[3] "nonegotiate" on or off has no effect on the problem.

[4] Vlan 37 is shown as active & non-pruned on the link, so "allowed" is not the problem.

[5] serverfault: Enabling 8021q on a nic

[6] http://wiki.wireshark.org/CaptureSetup/VLAN#Linux

[7] The native (untagged) VLAN is 1. Manually setting it with "switchport trunk native vlan 1" has no effect.

Darren H
  • 91
  • 1
  • 4

3 Answers3

2

Do you want the host to have access to just vlan 37 or do you want the host to have access to multiple vlans?

This IOS configuration means set the native (that's untagged) vlan to 37.

interface GigabitEthernet 0/1
    switchport mode access
    switchport access vlan 37

On the linux side, the vconfig command creates an interface alias for traffic tagged as vlan 37.

vconfig add eth0 37

Do you see the problem? The switch is sending your host untagged traffic and the host is looking for/generating tagged traffic.

You either need just use eth0 in the native vlan 37 or change the switch conf so that it's passing tagged traffic, eg.

interface GigabitEthernet 0/1
    switchport trunk allowed vlan 37
    switchport mode trunk

On fairly old IOS devices you man need to set the truck encapsulation to 8021q as they will default to ISL.

Joshua Hoblitt
  • 665
  • 4
  • 11
  • Access worked fine, trunking did not. The goal was to have three or more VLANs, each with their own subnet, terminating on the Linux box. The solution/workaround was to ensure each VLAN on the Linux side had a distinct MAC address. – Darren H Aug 22 '11 at 04:22
  • Well that depends on what you mean by "work". When an IOS device has a port in access mode it means "all packets *input* into this port will be tagged [internal to the switch] as vlan X". That means what ever 802.1q headers you've added from the Linux host are being stripped. You can easily prove this by running tcpdump on different port also set to access mode on vlan 37; you should be able to see broadcast traffic from all three of your "vlan" interfaces on the linux box. – Joshua Hoblitt Aug 22 '11 at 08:27
  • I should have mentioned two things. 1) That I do use vlan tags on centos 5 with Cisco & Blade Networks switches in my production virtualization environment. 2) `switch port mode access` will also strip all 802.1q tags on egress traffic. That's why you've had to resort to fiddling with the mac addresses to get communication working at all. Without the destinations having different mac addresses they were all ending up on the native vlan interface as the packets are coming to the Linux host with *no vlan tags*. – Joshua Hoblitt Aug 22 '11 at 08:40
  • Just for clarity, on IOS "trunk" means use 802.1q vlan tags. – Joshua Hoblitt Aug 22 '11 at 18:14
0

Now I am not an expert with the Linux side of this, by going by my Switching knowledge, do you have the eth0 interface on the Linux machine configured for dot1q trunking? I dont know if there is a provision for multiple vlans to operate within a Linux machine, but I assume that you have a single interface which is configured to work as part of Vlan37, thus essentially making your Linux machine's NIC to be an access port. An access port cannot communicate directly with a trunk port, it wont be able to create or understand the trunking encapsulation.

From what I understand you want the Linux machine to work within Vlan 37. Just revert the ge0/1 port to be an access port under Vlan37 and routinely assign the linux machine any IP under the subnet of Vlan37. You really do not need trunking which is used only to convey multiple Vlan information over a single link.

gokul varma nk
  • 67
  • 2
  • 15
0

I think the issue is with your switch config. After setting the port to trunk mode with 802.1q tags you need to configure the switch to send vlan 37 as tagged traffic and you may also need to set the port to use another vlan for non-tagged traffic. When I set this up I also had to set which vlan were allowed/denied on that port. My IOS is a bit rusty but I think this is what you are looking for.

You should also be able to confirm your switch config using wireshark on eth0 since it will show you the VLAN tags on the packets. The Cisco LLDP packets may also give you a clue to what port ge0/1 is doing.

chuck
  • 232
  • 1
  • 5
  • I didn't notice bullet points 3 and 4 when posting. I would still try wireshark since it would allow you to verify that the traffic meant for the switch is being sent on vlan 37. – chuck Aug 18 '11 at 17:18
  • Wireshark on linux often can not show the VLAN tags, and unfortunately, such is the case here. See new footnote [6] in edited question above. – Darren H Aug 18 '11 at 18:51
  • Defaults as per the asker's setup will have vlan 1 as native vlan and all others as tagged vlans. – MikeyB Aug 20 '11 at 01:45