Is it possible to connect a single NIC to two different VLANs?

Solution 1:

Sure, you simply have to enable vlan tagging on the switch and the network adapter and setup both sides with all the vlans you want the computer to see.

The details about how to configure vlan trunking vary depending on what OS, and what you have to do for a specific nic or switch.

Keep in mind that this may be a bit of a security issue. Suppose this is connected to two networks which have some firewalling between them. The computer that spans these two networks becomes an alternate pathway. If an attacker can compromise the system, then they can use the system jumping point to get to the inside hosts.

Solution 2:

I am not sure if you are doing this, but don't confuse subnets with VLANs. They are different OSI Layers, Network (IP) and Data Link (Ethernet) respectively. If you are at all unclear about this, I recommend reading the answers to this question and this question.

Having two different subnets on the same NIC doesn't have to correlate with having two VLANs on the same NIC. Adding a second subnet to a NIC in Linux is fine, you just do something like:

ifconfig eth0:1 192.168.7.1 netmask 255.255.255.0

This will add a secondary IP to eth0.

For the VLANs with Linux, Linux Journal has nice a article on it.