Score:0

How to configure vlan of same network with different mac in ubuntu.20.04

jp flag

I've ubuntu.20.04 VM launched on openstack with 1 trunk port having multiple subports from same network, which maps to 1 parent interface with multiple sub interface. For example if the subnet is 192.168.64.0/24, I've parent interface ip(VM IP) as 192.168.64.100 and multiple subports such as 192.168.64.101, 192.168.64.102 with different VLAN IDs. I initially tried to manually set up the sub interfaces using the below command.

ubuntu@kp-proxy:~$ sudo ip link add link ens3 name ens3.101 type vlan id 101
ubuntu@kp-proxy:~$ sudo ip link set dev ens3.101 address fa:16:3e:ac:11:40
ubuntu@kp-proxy:~$ sudo ip link set ens3.101 up
ubuntu@kp-proxy:~$ sudo dhclient ens3.101

However in the above case the dhclient was hanging forever, hence I modified the /etc/netplan/50-cloud-init.yaml manually to use mac address as idfr for dhcp. The updated file looks like below. Now when I apply the netplan, though command doesn't seems stuck in dhclient command but I see sub interface is also having same mac address of the parent, thus no ip address is retrieved from dhcp server of openstack.

50-cloud-init.yaml file

network:
    version: 2
    renderer: networkd
    ethernets:
        ens3:
            dhcp4: true
            macaddress: fa:16:3e:b1:2b:16
            mtu: 1450
    vlans:
       ens3.101:
            link: ens3
            id: 101
            macaddress: fa:16:3e:ac:11:40
            dhcp4: yes
            dhcp-identifier: mac

output of ip addr:

2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:b1:2b:16 brd ff:ff:ff:ff:ff:ff
    inet 192.168.64.100/24 brd 192.168.64.255 scope global dynamic ens3
       valid_lft 85261sec preferred_lft 85261sec
    inet6 fe80::f816:3eff:feb1:2b16/64 scope link
       valid_lft forever preferred_lft forever
3: ens3.101@ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default qlen 1000
    link/ether fa:16:3e:b1:2b:16 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::f816:3eff:feb1:2b16/64 scope link
       valid_lft forever preferred_lft forever

How to configure VLANs correctly for ubuntu-20.04, I've validated on centos-8.4 using the above command and it seems working and I was able to get the sub interface with ip address and was able to ping from other machines to both interfaces.

Score:0
br flag

Please, explain the reason why you need more MAC addresses in one device. If you need multiple dynamically assigned IP addresses to multiple interfaces of one device, use solution #2 below. But the IP address of each interface must be in separated IP network, not in the same network, as you suggested (192.168.64.0/24). Only one DHCP server with more DHCP scopes assigned to more IP networks is enough in solution #2, one scope to one IP network.

Special IP setting for each node in the same IP network can be solved by IP reservations in the DHCP server.

Situation

Maybe I am wrong, please, correct me. But I think it is your misunderstanding concerning VLAN's and IP interfaces.

VLAN is setting concerned to layer 2 (L2) of OSI model. It operates with data frames, 802.1Q tagging and MAC addresses. A VLAN tagging split one flat L2 network into multiple L2 networks which can operate independently on the same physical infrastructure. It is like to divide one network switch to multiple separate switches. The switches can be connected via L3 router. In this case the L2 separation (broadcast domains etc.) remains, but networks can communicate over the router. Router can filter the IP communication, blocks broadcast frames and do other useful things.

You wrote:

For example if the subnet is 192.168.64.0/24, I've parent interface ip(VM IP) as 192.168.64.100 and multiple subports such as 192.168.64.101, 192.168.64.102 with different VLAN IDs.

VLAN's are usually used to separate complete IP networks each from other, but not to separate individual IP addresses in one (the same) IP network!!! It means one VLAN should be connected to one IP network by this way (example):

  • VLAN 10 <--> 192.198.110.0/24
  • VLAN 20 <--> 192.198.120.0/24
  • VLAN 300 <--> 192.198.5.0/24
  • etc.

IP networks and addresses lie in L3 of OSI model. It is higher level and in most concepts the IP network is "inside" L2 network, i.e. inside VLAN.

In that concept usually router for inter-VLAN routing should be created with multiple interfaces, each in one VLAN. Example:

  • eth0.10, VLAN 10, IP 192.168.110.1
  • eth0.20, VLAN 20, IP 192.168.120.1
  • eth0.300, VLAN 300, IP 192.168.5.1

Subports you mentioned (192.168.64.101, 192.168.64.102 ...) cannot be in the separated VLAN's if they are in the same IP network. It is VLAN concept upside down. I have mentioned example about separated switches. If you separate one switch into multiple virtual switches and then you connect all these switches to one IP network, you lose the separation. There is no sense for separation of switches if they are interconnected via the same IP network and same broadcast domain.

Any network node incl. PC, VM or inter-VLAN router cannot have more IP interfaces in the same IP network or subnet, because in this case does not exist rule to tell to the node which of the same-level same-network interfaces must be used to communicate to peer node in the same network.

Possible solution

Possibility #1

Do not use VLAN's at all. Use one IP network with multiple IP nodes. One node is your host, second node is your first virtual machine, third node is your second VM etc. Only one IP interface on your host is needed to be able communicate with all virtual machines.

Possibility #2

  • Create multiple (L2) VLAN's. Create multiple (L3) IP networks and assign one to one: VLAN to IP network.
  • Create inter-VLAN router in your host. Create more IP interfaces and set each one to one VLAN. See above to my list with eth0.10, eth.20... interfaces.
  • Enable IP routing in your host.
  • Assign one IP interface to each of your VM's. Each VM will be in separate IP network and separate VLAN. The VM's can communicate each to other only if router in your host allows it.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.