About route add,I had some trouble

When I execute the command shown in the figure, an error occurs, but I am specifying a route for another network card

I found that when my network card is configured with the same routing address, the metric value will affect the result of my ping. But the configuration I checked on Centso is that the metric values of different network cards are the same, and after modifying the metric 'values of different network cards, the ping results are also different. The network card with the lowest ping value can successfully ping.

This thread looks like continuation of https://forums.rockylinux.org/t/i-seem-to-have-some-issues-with-my-network-when-using-the-ping-command/

Note: copy-paste is way more convenient than posting bitmap images.


We see two link-local subnets: 10.1.36.0/24 and 172.168.0.0/24.
We see that interface enp25s0f0 has address 10.1.36.59 in subnet 10.1.36.0/24
We see that interface enp202s0f1np1 has address 172.168.0.159 in subnet 172.168.0.0/24

We do not see interface ens3f1np1. Does it have no configuration? Can one see it with nmcli d s ?
If the interface ens3f1np1 were configured with address 172.168.0.59/24, then it should automatically have route to link-local subnet 172.168.0.0/24

However, as I wrote in the previous thread, then you will have two addresses (172.168.0.59 and 172.168.0.159) in same subnet 172.168.0.0/24. That requires at least policy based routing to be configured and still only one of the addresses/interfaces will be the default for all outgoing connections.


Network configuration is managed by NetworkManager.service in Rocky. (It was the default already in CentOS 7.)
You can use ip to look at current config, but changes you should do via NM. For example, with nmcli.

Yes, he does have a route that automatically links to the local network, but what I am curious about is why the metric values of the same route are different for different network ports. For example, one of my computers has values of 102 and 103, and I expect them to both be 104, and the same is true for the other computer. Regarding the issue in my previous post, I found that this metric value will affect my ping results.

Lets assume that routing decision is done for each and every packet.
Lets now have two routes to same destination that are equally good. The route to use is picked randomly.

You send first packet to destination D via first route. SRC=A.
The D sends a reply to A. You send next packet to D.
This time, RNG decides to use the other route. D receives packet from B.
Surely a packet from B is not part of any valid connection and must be discarded.
The D still waits for the next packet from A …


With different metric of routes we have that all packets to D leave through A. No confusion, except:
D initiates connection to B. For some reason it receives unexpected packets from A.

That last issue is resolved with the policy routing. When we have crafted reply to D, we do remember that connection came via B. Rule points to different routing table, which judges that reply will be sent via B, rather than the system default A. D is happy.

I understand the functions of this different routing metric, so if I need to implement the ping mentioned earlier, do I need to configure a reasonable routing strategy? I don’t know if my understanding is correct

Before that, why do you want two IP addresses on the same subnet?

I think you may have wanted those IPs to be 172.16.X.X or 192.168.X.X, not 172.168.X.X? The former are Class B/C private subnets, and the latter is apparently owned by the company that used to be Yahoo. If you’re trying to route that subnet on your private network, you may find queries that should go over your internet connection are not reaching their destination.

2 Likes

Because I want to handle visitors’ different businesses through different IPs

I understand what you mean, but this is only configured within my local area network, and my other Centos system machines do not have this problem at all, they only appear on my Rocky.

First a note: one does not need multiple physical interfaces in order to have multiple IP addresses; one connection can have more than one IPv4 address (IPv6 by nature has multiple addresses per connection).


Policy based routing: Chapter 21. Configuring policy-based routing to define alternative routes Red Hat Enterprise Linux 9 | Red Hat Customer Portal

What you said is right, perhaps I didn’t express my intention clearly. In fact, I have configured multiple network cards for myself and configured different IPs for each card. At the same time, I need to use different network cards to handle different business requests. However, the actual situation now is that after I specify the network card when I use the ping command, I cannot ping. The only network card that can ping is the one with a low metric value in the Routing table information. This type will not appear in my Centos now because their metric values are the same.