0

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
1
  • 1
    Can you please edit the question and add output of ip route? What exactly is it you want to achieve? You can only have one default route at a time, so as this now is, the only way this makes sense to me is thinking you want to set up a primary / secondary default route, or you want to have a separate internet connection for Virtual Machines. Please don't answer in comments, but edit the question instead so relevant info is readily available. Commented Mar 8, 2023 at 15:55

1 Answer 1

0

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
4
  • Since this is nontrivial, an explanation of what this does would be in order.
    – Kusalananda
    Commented Mar 8, 2023 at 16:55
  • What's the difference? Adding sudo? How exactly are you using the commands? In /etc/iproute2/rt_tables? Run manually?
    – Bodo
    Commented Mar 8, 2023 at 17:03
  • With this I can upload through specific network interface Commented Mar 8, 2023 at 18:16
  • 1
    You should edit the question and add the explanation there, friend :-) You'll find guidelines on formulating the answer from the Help center. Commented Mar 8, 2023 at 18:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .