1

I have a Netgear switch and a Unifi Seurity gateway, which together allow me to seperate my network into different vlans. For the case in point I have servers on VLAN 10.

With other hardware I have i.e. my NAS, I simply tell the network configuration to use VLan 10 and as long as the port in the netgear switch is marked as Tagged on Vlan 10 everything works.

I am really struggling with Ubuntu 18.04 and Vlans. I don't want to do anything fancy other than have my Ubuntu 18 servers on vlan10

By the way I'm am using a Raspberry Pi 4 Model B

Here is my current configuration in /etc/netplan/50-cloud-init-.yaml

network:
  version: 2
  renderer: networked
  ethernets:
    eth0:
      addresses:
        - 192.168.10.20/24
      gateway4: 192.168.10.1
      nameservers:
        addresses: [192.168.10.3, 8.8.8.8]
  vlans:
    vlan10:
      id: 10
      link: eth0
      addresses: [192.168.10.21/24]

With the above configuration netplan apply does not give me any errors and everything is shown as correct when I run ip addr.

The problem however is that I can access any devices outside of vlan 10 from the Ubuntu box. I can however ssh into my NAS which is on Vlan 10 and from there SSH into the Ubuntu server.

It almost makes me think the problem is in my netgear switch configuration, but the ports the ubuntu server are plugged into are configured just the same as the NAS, which as I say works just fine.

3 Answers3

3

There are two ways to use VLANs, either with tagged ports on the switch, or with untagged ports. It is more common to use untagged ports on a switch, such that the host does not have to be configured to know about the vlan at all, but simply sees plain ethernet packets that are segmented onto a particular vlan by the switch.

Based on your configuration, it's evident that you are using tagged ports instead, requiring the host to be vlan-aware.

The problem with your original configuration was that you had the default route (gateway) configured on the ethernet interface, when it needed to be on the VLAN interface. The following configuration should be sufficient:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0: {}
  vlans:
    vlan10:
      id: 10
      link: eth0
      addresses: [192.168.10.20/24]
      gateway4: 192.168.10.1
      nameservers:
        addresses: [192.168.10.3, 8.8.8.8]
slangasek
  • 5,828
2

The sample code I included in my question had become a bit messy from following other tutorials.

The answer provided by @Frobozz was accurate based on the question I asked, but the actual code I needed, in the end, was this. It was because of @Frobozz response that I started to understand what I needed to google for.

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
  bridges:
    br10:
      dhcp4: no
      dhcp6: no
      interfaces: [ vlan10 ]
      addresses: [ 192.168.10.20/24 ]
      gateway4: 192.168.10.1
      nameservers:
        addresses:
          - "192.168.10.3"
          - "8.8.8.8"
  vlans:
    vlan10:
      id: 10
      link: eth0
      dhcp4: no
      dhcp6: no
1

Netplan takes some getting use to. The missing piece here is bridging: Here is an example:

network:
    version: 2
    renderer: networked
    ethernets:
        eth0:
            optional: true
    bridges:
        br0:
            interfaces: [eth0]
            addresses:
            - 192.168.10.20/24
            gateway4: 192.168.10.1
            nameservers:
                addresses: [192.168.10.3, 8.8.8.8]
        br10:
            interfaces: [vlan10]
            addresses: [192.168.10.21/24]
        br25:
            interfaces: [vlan25]
    vlans:
        vlan10:
            id: 10
            link: eth0
        vlan25:
            id: 25
            link: eth0

Be sure that bridge-utils is installed:

apt install bridge-utils

Frobozz
  • 719