Reputation: 1
How can I use pyroute2 to change the base value of reachable_time_ms?
I couldn't find how to do this in the documentation on pyroute2 library. Which object should be used from the library to set this parameter. As I understand it, you can use IPRoute for this.
Upvotes: 0
Views: 12
Reputation: 1008
You cannot directly modify the reachable_time_ms
parameter using the pyroute2
library, as it is not directly exposed through the library's IPRoute
or other objects. This parameter is part of the ARP (neighbor) cache settings and is typically configured at the system level using the Linux sysctl
interface or by writing to /proc/sys
files.
But here is how you can modify the reachable_time_ms
parameter indirectly:
You can use the subprocess
module to invoke the sysctl
command from Python (recommended):
import subprocess
# Replace 'eth0' with your interface name
interface = "eth0"
new_value = 30000 # Reachable time in milliseconds
# Construct and execute the sysctl command
sysctl_command = f"sysctl -w net.ipv4.neigh.{interface}.reachable_time_ms={new_value}"
subprocess.run(sysctl_command, shell=True, check=True)
Alternatively, you can modify the corresponding file under /proc/sys/net/ipv4/neigh/<interface>/reachable_time_ms
(not recommended):
interface = "eth0"
new_value = "30000" # Reachable time in milliseconds
# Construct the file path
file_path = f"/proc/sys/net/ipv4/neigh/{interface}/reachable_time_ms"
# Write the new value to the file
with open(file_path, "w") as f:
f.write(new_value)
Upvotes: 0