I’ve a community system with each:
- Mobile Web through modem (I would like this to work 100% of the time for Web entry)
- Ethernet interface for Modbus TCP connection
The mobile connection is created with this command:
$ sudo nmcli c add sort gsm con-name telus
ipv4.dns '8.8.8.8 8.8.4.4' autoconnect sure
ifname 'cdc-wdm0' apn 'isp.telus.com'
ipv4.route-metric 1
$ sudo nmcli con up telus
The Modbus ethernet connection is created like this:
$ sudo nmcli con add sort ethernet con-name modbus
ifname enp1s0 connection.autoconnect sure
ipv4.never-default sure
ip4.addresses '10.1.9.7/16, 10.1.9.7/8'
ipv4.routes '10.1.0.0/16 10.1.10.1, 10.0.0.0/8 10.1.10.1'
ipv4.route-metric 800
$ sudo nmcli con up modbus
At this level, the ping check fails:
$ ping -c 1 10.65.3.5
PING 10.65.3.5 (10.65.3.5) 56(84) bytes of information.
^C
--- 10.65.3.5 ping statistics ---
1 packets transmitted, 0 obtained, 100% packet loss, time 0ms
The Hacky Resolution:
I’ve to manually delete one of many routes Community Supervisor creates with ip route
:
$ sudo ip route delete 10.0.0.0/8 dev enp1s0 proto kernel scope hyperlink src 10.1.9.7 metric 800
Nice success!
$ ping -c 1 10.65.3.5
PING 10.65.3.5 (10.65.3.5) 56(84) bytes of information.
64 bytes from 10.65.3.5: icmp_seq=1 ttl=126 time=117 ms
--- 10.65.3.5 ping statistics ---
1 packets transmitted, 1 obtained, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 117.203/117.203/117.203/0.000 ms
However I am anxious…
I believe this answer is just momentary, till Community Supervisor places the route again once more…
How one can persist the working configuration so I haven’t got to manually delete the route? It retains popping up once more, as a result of Community Supervisor retains placing it again.
Working routes, after deleting the unhealthy route that makes the ping check fail:
$ sudo ip route delete 10.0.0.0/8 dev enp1s0 proto kernel scope hyperlink src 10.1.9.7 metric 800
$ ip route
default through 10.96.241.146 dev wwan proto static metric 1
10.0.0.0/8 through 10.1.10.1 dev enp1s0 proto static metric 800
10.1.0.0/16 through 10.1.10.1 dev enp1s0 proto static metric 800
10.1.0.0/16 dev enp1s0 proto kernel scope hyperlink src 10.1.9.7 metric 800
10.96.241.144/30 dev wwan proto kernel scope hyperlink src 10.96.241.145 metric 1
Notice the next route isn’t there anymore, but it surely retains getting put again…
10.0.0.0/8 dev enp1s0 proto kernel scope hyperlink src 10.1.9.7 metric 800
Because of this reply, I’ve since added the next script to “/and so forth/NetworkManager/dispatcher.d/99-kill-bad-route.sh”, which can also be sort of hacky…
#!/bin/bash
if [ "$1" == "enp1s0" ] && [ "$2" == "up" ]; then
ip route del 10.0.0.0/8 dev enp1s0 proto kernel scope hyperlink src 10.1.9.7 metric 800
fi
Can the above answer be achieved with a Community Supervisor nmcli
command as a substitute?
This is how I automated the answer with Python:
from pathlib import Path
import subprocess
def add_script_to_auto_delete_problem_route(
counter: int,
bad_network: str,
ip_address: str,
interface: str = "enp1s0",
) -> None:
"""
sudo nano /and so forth/NetworkManager/dispatcher.d/9x-delete-problem-route.sh
#!/bin/bash
if [ "$1" == "enp1s0" ] && [ "$2" == "up" ]; then
ip route del 10.0.0.0/8 dev enp1s0 proto kernel scope hyperlink src 10.1.9.7
fi
"""
file_path: Path = Path(
f"/and so forth/NetworkManager/dispatcher.d/9{counter}-delete-problem-route-modbus.sh"
)
script: str = f"""#!/bin/bash
if [ "$1" == "{interface}" ] && [ "$2" == "up" ]; then
ip route del {bad_network} dev {interface} proto kernel scope hyperlink src {ip_address}
fi
"""
print(
"Including script to '%s' to delete drawback route '%s'...",
file_path,
bad_network,
)
if not file_path.mother or father.exists():
file_path.mother or father.mkdir(dad and mom=True, exist_ok=True)
if not file_path.exists():
file_path.contact()
with open(file_path, "w", encoding="utf-8") as file:
file.write(script)
# Make the file executable
command_list: checklist = ["sudo", "chmod", "+x", str(file_path)]
print("Operating command '%s' to make the script executable...", command_list)
subprocess.run(command_list, shell=False)
return None