0

I want to use 2 network interfaces, each one has its own default gateway, at the same time. I found on google that iproute2 program could solve my problem but I also have to config netplan in order to accomplish that. The only info I found is about /etc/network/interfaces

auto lo
iface lo inet loopback

allow-hotplug enp7s0
iface enp7s0 inet static
    address 192.168.0.101
    netmask 255.255.255.0
    gateway 192.168.0.1

allow-hotplug enp8s0
iface enp8s0 inet static
    address 192.168.1.16
    netmask 255.255.255.0

which is not on Ubuntu 22.04 anymore. How do I have this config applied to netplan?

Also, when I edited /etc/iproute2/rt_tables to add these lines

1 rt2

ip route add 192.168.0.0/24 dev enp7s0 src 192.168.0.101 table rt2
ip route add default via 192.168.0.1 dev enp7s0 table rt2
ip rule add from 192.168.0.101/32 table rt2
ip rule add to 192.168.0.101/32 table rt2

it came up with this error when I

ip rule show

Database /etc/iproute2/rt_tables is corrupted at ip route add 192.168.0.0/24 dev enp7s0 src 192.168.0.101 table rt2

0:  from all lookup local
32766:  from all lookup main
32767:  from all lookup default

Not sure where did it go wrong. Any help is appreciated

guntbert
  • 631
  • 9
  • 21

1 Answers1

0

solved using

sudo ip route add 192.168.0.0/24 dev enp7s0 src 192.168.0.101 table rt2
sudo ip route add default via 192.168.0.1 dev enp7s0 table rt2
sudo ip rule add from 192.168.0.101/32 table rt2
sudo ip rule add to 192.168.0.101/32 table rt2
guntbert
  • 631
  • 9
  • 21