2

I'm trying to add two static routes to my NIC. I can add one OK, but if I try to add a second, the entire network connection stops working until I bring down the 2nd card.

This is my current config which works:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
    eno2:
        dhcp4: no
        dhcp6: no
        addresses: [10.10.0.11/24]
        gateway4: 10.10.0.4
        routes:
        - to: 192.168.1.0/24
          via: 10.10.0.4        

But I need to add another route to 192.168.10.0/24 by the same gateway 10.10.0.4

I have tried to add multiple IPs to the same route such as:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
    eno2:
        dhcp4: no
        dhcp6: no
        addresses: [10.10.0.11/24]
        gateway4: 10.10.0.4
        routes:
        - to: [192.168.1.0/24, 192.168.10.0/24]
          via: 10.10.0.4        

and

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
    eno2:
        dhcp4: no
        dhcp6: no
        addresses: [10.10.0.11/24]
        gateway4: 10.10.0.4
        routes:
        - to: 192.168.1.0/24
          via: 10.10.0.4        
        - to: 192.168.10.0/24
          via: 10.10.0.4   

But both the above causes the network to fail. How do I have to format this so that I can have two static routes?

2

So it turns out the second option IS actually correct. I just had to restart a couple of times before it started working. Strange. Use this syntax:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: yes
    eno2:
        dhcp4: no
        dhcp6: no
        addresses: [10.10.0.11/24]
        gateway4: 10.10.0.4
        routes:
        - to: 192.168.1.0/24
          via: 10.10.0.4        
        - to: 192.168.10.0/24
          via: 10.10.0.4 
1

After making changes, do the following to get it to take immediately:

sudo netplan apply

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.