howto use netplan in ubuntu 20.04 with 2 lan interfaces + policy based routing

5
(2)

Q: Hello everyone. Ubuntu 20.04 Server I’m asking for help setting up Netplan.

You need to configure the Netplan settings so that all responses go through the network connection through which the requests came.

2 Internet providers.

2nd network cards.

Each one accesses the Internet through its own router (its own provider).

Cards with static IP:

eth1 – 192.168.1.11 gate1 – 192.168.1.1

eth2 – 192.168.100.12 gate2 – 192.168.100.1

Did you ask? We answer!

You need to make sure that the package iproute2 is installed on your system.

apt install iproute2

Edit /etc/iproute2/rt_tables, add these lines

101 101
102 102

Then edit /etc/netplan/ in my case it’s a file 99-netplan.yaml

network:
    version: 2
    renderer: networkd
    ethernets:
        eth1:
            addresses:
             - 192.168.1.11/24
            dhcp4: no
            nameservers:
              addresses:
                - 192.168.1.1
                - 8.8.8.8
            routes:
             - to: default
               via: 192.168.1.1
             - to: 192.168.1.11/24
               via: 192.168.1.1
               table: 101
            routing-policy:
             - from: 192.168.1.11/24
               table: 101
        eth2:
            addresses:
             - 192.168.100.12/24
            dhcp4: no
            nameservers:
              addresses:
                - 192.168.100.1
                - 8.8.4.4
            routes:
             - to: 192.168.100.0/24
               via: 192.168.100.1
               table: 102
            routing-policy:
             - from: 192.168.100.0/24
               table: 102

Check config of netplan

netplan generate

If there are no errors, then enter the command

netplan apply

That’s all. Policy based routing is configured.

Similar Posts:

301

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top