Score:0

Routing not working the same on two internal NIC

ru flag

on mu Ubuntu 22.04 server I have two internal NIC and one external connected to the Internet. I have defined the interfaces with Netplan as follows :

network:
  ethernets:
    eno1:
      dhcp4: true
      dhcp4-overrides:
        route-metric: 100
    enp2s0:
      addresses:
        - 172.16.1.1/24
      nameservers:
        addresses:
        - 127.0.0.53
        - 8.8.8.8
        search:
        - wombats.org
      routes:
        - to: default
          via: 192.168.0.254
        - to: 172.16.1.0/24
          via: 172.16.1.1
          metric: 200
          table: 101
      routing-policy:
        - from: 172.16.1.0/24
          table: 101
    wlp8s0:
      dhcp4: no
      addresses:
        - 172.16.2.1/24
      routes:
        - to: 172.16.2.0/24
          via: 172.16.2.1
          metric: 20
          table: 102
      routing-policy:
        - from: 172.16.2.0/24
          table: 102
  version: 2

A computer connected to enp2s0 is routed perfectly to the internet and internally. When the same computer is connected through wlp8s0 it cannot even reach the network managed by enp2s0 (172.16.1.1/24). Here are the two routing tables : connected through enp2s0 :

ip r
default via 172.16.1.1 dev enxf8e43b9d4867 proto dhcp metric 100 
169.254.0.0/16 dev enxf8e43b9d4867 scope link metric 1000 
172.16.1.0/24 dev enxf8e43b9d4867 proto kernel scope link src 172.16.1.3 metric 100 
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown

connected through wlp8s0:

ip r
default via 172.16.2.1 dev wlp0s20f3 proto dhcp metric 20600 
169.254.0.0/16 dev wlp0s20f3 scope link metric 1000 
172.16.2.0/24 dev wlp0s20f3 proto kernel scope link src 172.16.2.4 metric 600 
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown

The notable difference is the metric of the default route in both configurations. This does not come from the DHCP server as both subnets are configured identically. I have tried to disable ufw and tried to add iptables. But all that has not changed the result.

I do not understand why I cannot route the traffic of the wlp8s0 ! Does the fact that one NIC is a cable and the other a wifi explain the difference ? It should not as they get served IPs in the same way.

Thanks for your help. Jan

JanP avatar
ru flag
I have found out that adding the following rule to /etc/ufw/before.rules : "-A POSTROUTING -s 172.16.2.0/24 -o eno1 -j MASQUERADE" at least allows me to reach the Internet from NIC wlp8s0. But I still cannot connect to the other network (172.16.1.0/24).
JanP avatar
ru flag
What I also noted is that for each interface defined in netland the option "ignore-carrier: true" is essential. It ensures that the NIC is defined even if no carrier is connected.
Score:0
ru flag

The solution to this problem was twofold : First the masquerading needs to be done on both interfaces (subnets) :

-A POSTROUTING -s 172.16.1.0/24 -o eno1 -j MASQUERADE
-A POSTROUTING -s 172.16.2.0/24 -o eno1 -j MASQUERADE

Then what is not less important is that the interfaces are brought-up with or without carrier. This done in /etc/netplan/00-installer-config.yaml with the line:

    enp2s0:
      ignore-carrier: true

same for the wlp8s0. If you do not

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.