هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
ip route get 10.20.0.5
ip route add 10.20.0.0/16 via 10.0.1.254 dev ens224
nmcli connection modify ens224 +ipv4.routes "10.20.0.0/16 10.0.1.254"
nmcli connection up ens224
ip routeip route add is for a quick test (lost at reboot); nmcli … +ipv4.routes makes it permanent.
Step by step
- Which way does a packet go now?
ip route get 10.20.0.5
10.20.0.5 via 192.0.2.1 dev ens192 src 192.0.2.10 uid 1000
ip route
default via 192.0.2.1 dev ens192 proto static metric 100
10.0.1.0/24 dev ens224 proto kernel scope link src 10.0.1.11 metric 101
192.0.2.0/24 dev ens192 proto kernel scope link src 192.0.2.10 metric 100Here 10.20.0.5 goes out of the public interface — wrong.
- Test with a temporary route (gone after reboot or network restart):
ip route add 10.20.0.0/16 via 10.0.1.254 dev ens224
ip route get 10.20.0.5
10.20.0.5 via 10.0.1.254 dev ens224 src 10.0.1.11
ping -c 3 10.20.0.5
ip route del 10.20.0.0/16The gateway (via) must be in a network the server is directly connected to (here 10.0.1.0/24).
- Make it permanent — RHEL / NetworkManager:
nmcli connection modify ens224 +ipv4.routes "10.20.0.0/16 10.0.1.254"
nmcli connection up ens224
nmcli -g ipv4.routes connection show ens224
10.20.0.0/16 10.0.1.254Remove it again with -ipv4.routes "10.20.0.0/16 10.0.1.254". A metric: "10.20.0.0/16 10.0.1.254 50".
- Make it permanent — Ubuntu / netplan:
ens224:
addresses: [10.0.1.11/24]
routes:
- to: 10.20.0.0/16
via: 10.0.1.254netplan try- Change the default gateway (careful on a remote server — use the console or
netplan try):
- In the cloud (AWS, Azure, GCP) routes between subnets are set in the VPC/VNet route tables, not on the server — a route on the server alone is often not enough.
Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
RTNETLINK answers: Network is unreachable | The gateway is not in a directly connected network. | Use a gateway in one of the server's own subnets. |
RTNETLINK answers: File exists | The route (or one with the same target) exists. | ip route — delete or replace it (ip route replace …). |
| The route is gone after reboot | It was added with ip route add only. | Add it with nmcli or netplan. |
| Ping goes out, answers never come back | The other side has no route back (asymmetric routing), or rp_filter drops it. | Add the return route on the other side/gateway. |
| Two default routes | Both interfaces got a gateway (DHCP). | ipv4.never-default yes on the private connection. |
| Works on the server, not for other subnets in the cloud | Cloud route tables / security rules. | Add the route in the VPC/VNet route table too. |
Go further
- Command pages: ip, nmcli, tracepath.
- Next how-tos: Set a static IP address, Trace the network path to a host, Test if a remote port is open, Connect two servers with WireGuard.
- Learn it: RHCSA — Check routes, RH124 — Routes, AZ-104 — Routes in a VNet.
- VPNs that need routes: WireGuard, OpenVPN.
1How do you see which gateway and interface a packet to 10.20.0.5 will use?
2Why is a route added with ip route add lost after a reboot, and how do you keep it?
It lives only in the running kernel; add it to the connection with nmcli … +ipv4.routes (or netplan).