Score:0

How to set iproute2 routing table for 2 network interfaces on Ubuntu 22.04

so flag

I want to use 2 network interfaces (enp7s0 and enp8s0) simultaneously on Ubuntu 22.04. Both has its own separate internet connection. My default is enp8s0 which I plugged the LAN cable in first. I think I need to set a routing table for that.

So I edited

/etc/iproute2/rt_tables

as follow

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

here is my ifconfig

enp7s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.101  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::9c8b:3fe5:795e:bd32  prefixlen 64  scopeid 0x20<link>
        ether d8:5e:d3:01:84:ed  txqueuelen 1000  (Ethernet)
        RX packets 19214  bytes 18384493 (18.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11885  bytes 1705118 (1.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xfc700000-fc71ffff  

enp8s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.16  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2403:6200:89a6:96ee:7aba:94ac:f7e5:421c  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::a09b:20eb:6e61:72b8  prefixlen 64  scopeid 0x20<link>
        inet6 2403:6200:89a6:96ee:33b5:37f2:4af1:bcbb  prefixlen 64  scopeid 0x0<global>
        ether d8:5e:d3:01:84:ee  txqueuelen 1000  (Ethernet)
        RX packets 4578155424  bytes 397941134593 (397.9 GB)
        RX errors 0  dropped 25613  overruns 0  frame 0
        TX packets 9865356056  bytes 14456549029829 (14.4 TB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

but when I do

ip rule show

I got this error

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

How do I fix this?

Could be that I haven't set the

/etc/network/interfaces

From what I found on google I must add these lines

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

But it doesnt exist anymore on Ubuntu 22.04 I heard they changed to

/etc/netplan

but the only file I found there is

01-network-manager-all.yaml

which inside only has

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
Score:0
so flag

Solved by 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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.