N
N
Nicholas2015-12-15 11:45:54
VPN
Nicholas, 2015-12-15 11:45:54

How to redirect the traffic of the desired user in iptables to another interface?

There are two interfaces eth0 and eth1 It is
necessary to redirect all user traffic under the id 1001 to the second interface eth1
Possible to implement? if so how?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alegzz, 2015-12-15
@alegzz

iptables -t mangle -N markrt
iptables -t mangle -F markrt

#в локальную сеть не маркируем
iptables -t mangle -A markrt -d 172.16.0.0/24 -j RETURN
iptables -t mangle -A markrt -m connmark ! --mark 0 -j RETURN
iptables -t mangle -A markrt -j MARK --set-mark 10

iptables -t mangle -A OUTPUT -m owner --uid-owner 1001  -j markrt

#если приложение не прибито к интерфейсу eth1, то адрес будет кривым. исправляем
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

#делаем default маршрут, поменять на свое, table 10 - оставить
ip route add default dev eth1 via 172.16.0.1 table 10
#пакеты, промаркированные 0xa должны маршрутизироваться по правилу
ip rule add fwmark 10 lookup 10

P
Puma Thailand, 2015-12-15
@opium

Mark user packets in iptables and make a separate routing table for marked packets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question