Score:0

how to mark connections to route multiple gateways?

us flag

hi i am having trouble setting up permanent routes for my network interfaces,

i have :

os : linux (centos 7)

eth0 : IP 172.16.3.6 -- Gateway : 172.16.0.1

eth0:1 : IP 10.1.5.102 -- Gateway : 10.1.5.101

eth0:2 : IP 10.1.5.106 -- Gateway : 10.1.5.105

and i wanna to connect to :

10.10.10.1:5160 via 10.1.5.102 (Sip-Trunk Connection (udp))

10.10.10.1:5161 via 10.1.5.106 (Sip-Trunk Connection (udp))

there is a one dst. IP but different port.

so how can i mark and route connections ? (by default connections going with 172.16.3.6 IP address)

Score:1
cn flag

Routing does not work at the port level, it only looks at the IP address.

What you can do is use iptables to mark packets and then use policy based routing to pick a different routing table.

Something like:

# iptables -A OUTPUT -t udp --dport 5160 -d 10.10.10.1 -t mangle -j MARK --set-mark 1
# echo 201 sip.out >> /etc/iproute2/rt_tables
# ip rule add fwmark 1 table sip.out
# ip route add 10.10.10.1 via 10.1.5.101 dev eth0:1 table sip.out
# ip route add 10.10.10.1 via 10.1.5.105 dev eth0:2

Examples of how can be found here

erfan mehralizadeh avatar
us flag
it's not working
cn flag
[Edit](https://serverfault.com/posts/1084456/edit) the original question to show exactly what you tried. The suggestion above is meant to be a guide, you will need to adjust it to fit your specific situation.
cn flag
I've fixed the `iptables` line in the example and tested it in a virtual network. all works.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.