for Linux support we need policy routing (ip rule + ip route) #50
normaluser-nobody
started this conversation in
Ideas
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Unfortunately on linux IP address binding != interface binding. Linux uses the route which has the lowest metric inspite of specifying the source IP address. Therefore, we need custom ip rule and ip route configurations. I wrote a script that does this.
`#!/bin/bash
echo "=== Auto Routing Script ==="
Define interface names and their custom table IDs
declare -A interfaces=(
["wlp0s20f3"]=101
["enp0s20f0u1"]=102
["eth1"]=103
)
Check if interface exists
interface_exists() {
ip link show "$1" &>/dev/null
}
ensure_rt_tables() {
# Ensure directory exists
if [ ! -d /etc/iproute2 ]; then
echo "/etc/iproute2 missing, creating..."
sudo mkdir -p /etc/iproute2
fi
}
Call it for table creation and editing
ensure_rt_tables
Get IPv4 and IPv6 addresses
get_ip_addresses() {
interface=$1
ipv4=$(ip -4 addr show "$interface" | grep -oP 'inet \K[\d.]+' | head -1)
ipv6=$(ip -6 addr show "$interface" | grep -oP 'inet6 \K[0-9a-f:]+' | grep -v '^fe80' | head -1)
echo "$ipv4 $ipv6"
}
Get link-local IPv6 address (optional, for debugging)
get_link_local_ipv6() {
interface=$1
ip -6 addr show "$interface" | grep -oP 'inet6 \K[0-9a-f:]+' | grep '^fe80' | head -1
}
Get IPv4 default gateway for a specific interface
get_gateway_ipv4() {
interface=$1
ip route show default | grep "dev $interface" | awk '{print $3}' | head -1
}
Configure routing for an interface
configure_interface() {
interface=$1
table_id=$2
table_name="${interface}_table"
}
Main
for interface in "${!interfaces[@]}"; do
if interface_exists "$interface"; then
configure_interface "$interface" "${interfaces[$interface]}"
else
echo "Interface $interface does not exist. Skipping."
fi
done
Show results
echo -e "\nCurrent IPv4 routing rules:"
ip rule show
echo -e "\nCurrent IPv6 routing rules:"
ip -6 rule show
`
Beta Was this translation helpful? Give feedback.
All reactions