Score:0

Netplan: Two primary IPs on a VLAN subinterface

de flag

The following Netplan config results in only one of those IPs becoming primary (the other one becomes secondary):

vlans:
    vlan10:
        addresses:
        - 1.1.1.1/24
        - 1.1.1.2/24
        dhcp4: false
        dhcp6: false
        id: 10
        link: eth1

How do I have 2 primary IPs in that subnet/VLAN? (obviously not on a single interface, which is impossible) E.g. with pre-Netplan networking config I was able to create what looked like 2 subinterfaces on the same VLAN, each with its own (primary) IP in the same subnet showing up in ifconfig output:

eth1      Link encap:Ethernet  HWaddr 00:0C:29:DB:27:4F
          inet6 addr: fe80::20c:29ff:fedb:274f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1.10   Link encap:Ethernet  HWaddr 00:0C:29:DB:27:4F
          inet addr:50.0.10.254  Bcast:50.0.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fedb:274f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth1.10:0 Link encap:Ethernet  HWaddr 00:0C:29:DB:27:4F
          inet addr:50.0.10.253  Bcast:50.0.10.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

But a similar config with Netplan adds only one of those subinterfaces/IPs, ignoring/rejecting the other for some reason. Defining those 2 IPs as VRRP VIPs could be done but perhaps there's a more natural way?

Thanks in advance!

Update: looks like virtual interface like eth1.10:0 above is a feature supported through labels starting with Netplan v0.100 / Ubuntu 20.04 (mine's v0.99 with Ubuntu 18 and I'm not allowed to upgrade it to give it a try): https://bugs.launchpad.net/ubuntu/+source/nplan/+bug/1743200 That partially answers my question, so other ideas on how to have 2 primary IPs in a subnet/VLAN on a single server are welcome.

Score:1
uy flag

There is only one primary IP per interface. This IP is (in contrast to secondary IPs) used as source IP for locally generated outgoing traffic. This is valid if all IPs are out of the same subnet. If the configuration contains multiple IPs out of multiple subnets the selection of the source IP for local generated traffic is done based on the routing table.

If you want to configure VRRP you need (at least) 2 hosts, each with 1 (primary IP) in the same subnet. A third IP is configured inside the VRRP Daemon (on ubuntu e.g. keepalived or haproxy) and not on OS level.

Depending on the exact version of ubuntu some additional parameter on OS level (e.g. net.ipv4.ip_nonlocal_bind in sysctl) may be needed.

Keepalived takes care about routing only, while haproxy terminates the tcpsession.

dandreye avatar
de flag
"There is only one primary IP per interface" - correct, so how do have 2 subinterfaces (each with its own IP) bound to the same VLAN? As for at least 2 hosts for VRRP, well that's what VRRP is primarily designed for (redundancy), but I only have a single host here and just need its ability to make its VIP look like a primary IP (my application is just having problems using secondary ones).
dandreye avatar
de flag
I've just updated my question with what it used to look like with Ubuntu 16 (no Netplan): 2 subinterfaces bound to the same VLAN, each with its own (primary) IP in the same subnet. Can't believe it's impossible with Netplan...
dummyuser avatar
uy flag
Trying to set up VRRP on a single host is useless and a waste of time.
dandreye avatar
de flag
Well, hence the question how to do it w/o VRRP.
dummyuser avatar
uy flag
Well, the question you asked is clearly answered. The Answer does not fit to your problem. Sounds like an XY -Problem. Maybe you should describe the issue in your application in a new question instead of trying to solve it on other layers you are not familiar with.
dandreye avatar
de flag
Sorry but I don't think your answer "There is only one primary IP per interface" answers my question, which says nothing about having those primary IPs necessarily on a *single* interface. For instance having those primary IPs on *different* subinterfaces (bound to the same VLAN) would be perfectly fine. Exactly that was possible with pre-Netplan Ubuntu versions as illustrated in my old example, so I'm now looking for a similar Netplan config. My application can only use *primary* IPs (it cannot use secondary ones) and they must belong to the same subnet/VLAN, so I doubt it's an XY-problem.
dandreye avatar
de flag
Having 2 primary IPs in a subnet/VLAN doesn't necessarily imply having them on a single interface. Perhaps the vlans section of my Netplan config is somewhat misleading as it shows a single interface with 2 IPs. Still the question below is consise: "How do I have 2 primary IPs *in that subnet*?". I've just amended its wording accordingly to rule out any confusion.
I sit in a Tesla and translated this thread with Ai:

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.