VLAN and Virtual Interfaces on Ubuntu

5,300

Let me fill in some detail to make sure I'm answering the question you've asked. You have a robot with multiple Ethernet ports in different locations, and this robot contains a configurable Ethernet switch. It has one port, "port 1", that is connected to a host you've labeled "main computer" which is the one running Ubuntu. You want to be able to determine, from the Ubuntu host, which port on the robot a particular host is plugged into, and you'd like to do so with VLANs and VLAN trunking.

You can think of a VLAN as a virtual switch, and a VLAN trunk as multiple virtual Ethernet connections made over a single physical Ethernet connection. So the solution you're looking at entails assigning each port (other than port 1) to its own VLAN, then trunking all of those VLANs over port 1 to the Ubuntu host. For simplicity, I'd recommend assigning port 2 to VLAN 2, port 3 to VLAN 3, and so on. Since you haven't specified what kind of switch this robot contains, that's all the detail I can supply on the switch configuration.

The idea is to assign each VLAN to its own IP subnet and run DHCP on that subnet, so that a device plugged into the port on the robot gets an IP in the subnet assigned to that VLAN (and thus port). Again, for simplicity I'd recommend keeping the numbering the same, so VLAN 2 has 192.168.2.0/24, VLAN 3 has 192.168.3.0/24, and so on. Your Ubuntu host will need an IP in each VLAN, ending by convention in .1. And you'll need to set up a DHCP server on each VLAN (via dnsmasq.conf).

Based on the Ubuntu wiki's 'vlan' page, the main computer's /etc/network/interfaces would contain something like this in addition to the basic host configuration (assuming eth1 is your "noral" network connection and eth2 is plugged into the robot's port 1)

auto eth2.2
iface eth1.2 inet static
  address 192.168.2.1
  netmask 255.255.255.0
  vlan-raw-device eth2
auto eth2.3
iface eth2.3 inet static
  address 192.168.3.1
  netmask 255.255.255.0
  vlan-raw-device eth2

and so on. The auto eth2.N sets up trunking of VLAN N on eth2, and the indented lines assign an IP address and netmask on that VLAN to the main computer.

Your dnsmasq.conf would contain

dhcp-range=eth2.2,192.168.2.100,192.168.2.199,4h
dhcp-range=eth2.3,192.168.3.100,192.168.3.199,4h

to assign fresh IP addresses to anything that appears on VLAN 2 (port 2) and VLAN 3 (port 3), respectively.

You should set up the software on the computers plugged into the robot to talk to the main computer's main (eth1) IP address. Then any traffic from an IP matching 192.168.2.x is from a computer plugged into port 2, any traffic from an IP matching 192.168.3.x is from a computer plugged into port 3, and so on.

To answer your second question, I haven't found any tutorials on this, and it seems like a very unusual configuration so that's not especially surprising!

Share:
5,300

Related videos on Youtube

Eric D
Author by

Eric D

Updated on September 18, 2022

Comments

  • Eric D
    Eric D almost 2 years

    I am using a switch in a device that has physical dimensions; these dimensions exist outside the network, just to make clear I'm not trying to use some kind of network terminology.

    The ports of the switch correspond to different physical parts of the device, so when a “computer” gets plugged into a different port it is in a different physical location.

    The exception is port 1, which will always be plugged into the main “computer”. Note that I keep using quotes because these are not laptops or servers, etc… This is a robot and these are different parts of said robot. Hence the need to know where it is plugged in physically.

    I was told that I can use VLANs to do this segregation. I just have to trunk port 1 and separate the VLANs back out and map them to different virtual Ethernet interfaces on the main “computer.”

    All well and good. I sort of understand the concepts. But I have two main questions:

    1. Is there an easier way to know which physical port a computer is plugged into? If I have a device plugged into port 2 and I move it to port 3, I should be able to tell that this device is now on port 3 either because the IP address changed to a different range, (subnet?) or some other cool way that I just don't know about.

    2. Are there clear tutorials on this? I have been digging around and am now trying to set dnsmasq.conf and my interfaces file (I just included lines below my main ethernet interface p2p1 that look like iface p2p1:0 inet dhcp) to set up the VLANs, but I haven't been able to find something that clearly walks me through the steps. A lot of stuff seems to be related to specific setups like OpenStack.

  • Eric D
    Eric D over 9 years
    We are using a D-Link 1100 5 port switch. Here is the manual. I am making port 1 a trunk by tagging it on all the VLANs (VLANs 2-5). Does that sound right?
  • djmitche
    djmitche over 9 years
    It does. Tagging and trunking both refer to the same thing.
  • Eric D
    Eric D over 9 years
    So I've gotten a bit farther - port 1 is tagged on all VLANs, and untagged on the specific port (so VLAN2 is untagged on port 2 and tagged on port 1). I can now switch ports and see a different gateway, corresponding to a different virtual interface on the central computer (set up using the vlan thing, p2p1.2, p2p1.3 etc). I can't ping the central computer, though. Not even the gateways. Also the IP address doesn't change to a new subnet.
  • Eric D
    Eric D over 9 years
    So I had the subnet masks on the central computer set to weird things, I set them all to 255.255.255.0 in /etc/network/interfaces. Now I can ping the central computer from my computer (I'm at 10.0.3.11, on port 3, and the central computer is at 10.0.0.91. I ran ping 10.0.0.91 and it worked). I can't ping my computer from the central computer though. Not even using ping -I p2p1.3 10.0.3.11
  • djmitche
    djmitche over 9 years
    Have a look at the routing table on the central computer (netstat -nr) and possibly its ARP table (arp -an). Also verify you don't have any iptables rules in place. I don't think you'll need to enable forwarding, but it's something to try if nothing else helps.