In which vlan am I in?

I am not sure what you mean by a GENERAL switch, but for most switches it is impossible to see in which VLAN you are when you are connected to an 'access' port.

That said, using the CDP (Cisco) and LLDP (Juniper) protocols you can find out in which VLAN you are. Enabling CDP/LLDP on an access port is arguably a security risk (information exposure) so it might not be enabled on your network. You can use tcpdump to disassemble CDP/LLDP packets to find the VLAN number.

For Cisco CDP:

sudo tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000' 

For Juniper LLDP:

sudo tcpdump -nn -v -i eth0 -s 1500 -c 1 '(ether[12:2]=0x88cc or ether[20:2]=0x2000)'

Traditionally, from a client computer, you cannot tell which vlan you're in. You can look at an IP address and subnet mask and determine which subnet the IP is in, but not the vlan. However, the wireshark wiki has some interesting information about capturing vlan tags off the wire.

When capturing on a VLAN, you won't necessarily see the VLAN tags in packets.

For example, in at least some operating systems, you might have more than one network interface device on which you can capture - a "raw interface" corresponding to the physical network adapter, and a "VLAN interface" the traffic on which has had the VLAN tags removed. The OS's networking stack would be connected to the VLAN interface, and that interface would appear to the networking stack to be an Ethernet interface with a smaller MTU than normal (to leave room for the VLAN tags). On those OSes, in order to see the raw Ethernet packets, rather than "de-VLANized" packets, you would have to capture not on the virtual interface for the VLAN, but on the interface corresponding to the physical network device, if possible.

Here are some details on capturing VLAN tags on various operating systems. If the OS or the network adapter driver won't allow the VLAN tags to be captured, set up port mirroring (or "port spanning", as Cisco calls it) on the VLAN switch and connect an independent system, such as a laptop, to the mirror port, and don't configure the interface attached to that port as a member of a VLAN.. You'll definitely see the VLAN tags, regardless of what OS the independent system is running or what type of network adapter you're using.

Linux

To enable VLAN tagging, you need two things: the vlan rpm (e.g., vlan-1.8-23) and the 8021q kernel module. Once installed, the vconfig command can be used to create VLAN interfaces on an existing physical device. For more info, see the vconfig(8) man page.

After your VLAN interfaces are set up and traffic is flowing, you can run Wireshark and capture on the VLAN interface of your choice (e.g., eth0.100 for VLAN 100) or on the underlying physical interface (e.g., eth0). If you choose the former, you will only see frames destined for that VLAN; if you choose the latter, you may see all frames or you may see only untagged frames (if there are any). It depends on the NIC, the NIC firmware, the driver, and the alignment of the moon and planets. (A table enumerating the behaviors of various adapters, firmware versions, and drivers might be useful. -Guy Harris)

If you are capturing on the host system where the VLANs are configured, you will probably not see the VLAN tags in the captured frames -- even if you capture on the physical device. The driver is stripping the tags before the pcap library sees them. See the tech note from Intel mentioned in the Windows section below. (Do Linux drivers support getting VLAN tags, perhaps with a driver configuration option or other option, in the same way that the Intel Windows driver does? -Guy Harris) (e100 driver works great on 2.4.26 - Jaap Keuter)

Windows

Windows has no built-in support mechanisms for VLANs. There aren't separate physical and VLAN interfaces you can capture from, unless a specialized driver that adds such support is present.

So whether you see VLAN tags in Wireshark or not will depend on the network adapter you have and on what its and its driver do with VLAN tags.

Most "simple" network adapters (e.g. widely used Realtek RTL 8139) and their drivers will simply pass VLAN tags to the upper layer to handle these. In that case, Wireshark will see VLAN tags and can handle and show them.

Some more sophisticated adapters will handle VLAN tags in the adapter and/or the driver. This includes some Intel adapters and, as far as i know, Broadcom gigabit chipsets (NetXtreme / 57XX based chips). Moreover, it is likely that cards that have specialized drivers will follow this path as well, to prevent interference from the "real" driver.

Tags:

Vlan