0

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]
  • Given that there are multiple addresses, each with their own gateway, we do not specify gateway4 here, and instead configure individual routes to 0.0.0.0/0 (everywhere) using the address of the gateway for the subnet. The metric value should be adjusted so the routing happens as expected. Refer section: Using multiple addresses with multiple gateways – Marmayogi Apr 6 at 4:31
0

"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.

  • Can you give an example. – aircraft Apr 7 at 0:22
  • Updated the answer with a link to the examples on the website. – slangasek Apr 8 at 3:35

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.