3

How to configure two segment's IP addresses' gateway use netplan ?

#!/bin/bash
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0f1:
      addresses:
        - 22.95.140.1/24      
        ...
        - 22.95.141.1/24    
        - 22.95.141.2/24 
        ....
      gateway4: 22.95.140.254
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      dhcp4: no
      optional: no

You see I configured two IP segment 22.95.140.0/24 and 22.95.141.0/24.

but there I only configured one gateway, gateway4: 22.95.140.254, is there I need two IP segments' gateway?

if I need two, how can I configured it?

should I configured like this?

gateway4: [22.95.140.254, 22.95.140.254]
aircraft
  • 183

1 Answers1

3

"gateway" is shorthand for "default router". You only need to specify one default route to the Internet. If you have multiple routes to the Internet via different routers and you want to use all of them, you will need to configure this using the more detailed routes section.

See https://netplan.io/examples#using-multiple-addresses-with-multiple-gateways for example of how to do this.

slangasek
  • 5,562