Score:0

two IPs and two gateways on one interface in bridge configuration with netplan on Ubuntu 20.04

kr flag

I have a Hetzner dedicated server with single network card and two public IP addresses (both IPs have its own gateway). Right know it has only one address configured with neplan. Below is my config

network:
  version: 2
  renderer: networkd
  ethernets:
    enp195s0:
      addresses:
        - x.x.x.x/32        #Main IPv4 address
        - xx.xx.xx.xx::2/64 #IPv6
      routes:
        - on-link: true
          to: 0.0.0.0/0
          via: gx.gx.gx.gx      #Main IPv4 address Gateway IP
      nameservers:
        addresses:
          - 185.12.64.2
          - 185.12.64.1
          - 2a01:4ff:ff00::add:1
          - 2a01:4ff:ff00::add:2

And now I want to configure network to have two public IPs as a bridge because I want to share it with kvm guest machines. Here is one of my tries:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp195s0:
      dhcp4: false
      dhcp6: false

  bridges:
    kvmbr0:
      interfaces:
        - enp195s0
      addresses:
        - x.x.x.x/32          #Main IPv4 address
        - y.y.y.y/32          #Additional IPv4 address
      routes:
        - to: 0.0.0.0/0
          via: gx.gx.gx.gx    #Main IPv4 address Gateway IP
          table: 1
          metric: 100
        - to: 0.0.0.0/0
          via: gy.gy.gy.gy    #Additional IPv4 address Gateway IP
          table: 2
          metric: 200
      mtu: 1500
      dhcp4: no
      dhcp6: no
      nameservers:
        addresses:
          - 185.12.64.2
          - 185.12.64.1
          - 2a01:4ff:ff00::add:1
          - 2a01:4ff:ff00::add:2
      parameters:
        stp: false 
        forward-delay: 4 

The problem is that after netplan apply I always loose the internet connection :/ I have a script which recovers default netplan config after a few minutes if I don't stop it, so it's hard form me to check what happens on server but I suppose that it is something with routing. I'm new in netplan configs, could you please help me to find proper solution?

djdomi avatar
za flag
how to solve? ask hetzner. you pay them to support your server
Score:0
kr flag

I found solution. It's below

network:
  version: 2
  renderer: networkd
  ethernets:
    enp195s0:
      dhcp4: false
      dhcp6: false

  bridges:
    kvmbr0:
      interfaces:
        - enp195s0
      addresses:
        - x.x.x.x/26           # <- netmask here
        - y.y.y.y/29           # <- netmask here
      routes:
        - to: 0.0.0.0/0
          via: gx.gx.gx.gx
          metric: 100
        - to: nx.nx.nx.nx/26   # <- route to main IP network
          via: gx.gx.gx.gx     # <- via main IP gateway
          metric: 100
          table: 1             # <- with routing table assignment 
        - to: 0.0.0.0/0
          via: gy.gy.gy.gy
          metric: 200          
        - to: ny.ny.ny.ny/29   # <- route to additional IP network
          via: gy.gy.gy.gy     # <- via additional IP gateway
          metric: 200
          table: 2             # <- with routing table assignment
      routing-policy:          # <- routing policies for IPs networks 
        - from: nx.nx.nx.nx/26 
          table: 1             # <- appropriate routing table
        - from: ny.ny.ny.ny/29
          table: 2             # <- appropriate routing table
      dhcp4: no
      dhcp6: no
      nameservers:
        addresses:
          - 185.12.64.2
          - 185.12.64.1
          - 2a01:4ff:ff00::add:1
          - 2a01:4ff:ff00::add:2
      parameters:
        stp: true 
        forward-delay: 4

The main problem were netmasks. It shouldn't be 32 bits because they didn't contain the gateways IPs. That was the reason that I was loosing the network connection. So I put there the correct netmasks from the IP addresses networks.

Other changes were needed to allow additional IP to communicate with internet.

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.