Страница 1 из 1

Перенаправление трафика пользователя.

Добавлено: 2019-06-09 15:00:26
novik
Как с помощью PF реализовать такой функционал?
Как в iptables перенаправить трафика нужного пользователя в другой интерфейс?

Код: Выделить всё

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

Перенаправление трафика пользователя.

Добавлено: 2019-06-10 10:50:49
skeletor
в pf'e нет возможности фильтровать по uid.

Перенаправление трафика пользователя.

Добавлено: 2019-06-10 19:22:37
novik
skeletor писал(а):
2019-06-10 10:50:49
нет возможности фильтровать по uid
А что-то другое, не PF, из арсенала FreeBSD может?

Перенаправление трафика пользователя.

Добавлено: 2019-06-10 22:36:43
novik
skeletor писал(а):
2019-06-10 10:50:49
в pf'e нет возможности фильтровать по uid.
После долгих поисков, в man pf.conf я кажется нашёл то, что нужно?
group <group>
Similar to user, this rule only applies to packets of sockets owned
by the specified group.

user <user>
This rule only applies to packets of sockets owned by the specified
user. For outgoing connections initiated from the firewall, this
is the user that opened the connection. For incoming connections
to the firewall itself, this is the user that listens on the
destination port. For forwarded connections, where the firewall is
not a connection endpoint, the user and group are unknown.

All packets, both outgoing and incoming, of one connection are
associated with the same user and group. Only TCP and UDP packets
can be associated with users; for other protocols these parameters
are ignored.

User and group refer to the effective (as opposed to the real) IDs,
in case the socket is created by a setuid/setgid process. User and
group IDs are stored when a socket is created; when a process
creates a listening socket as root (for instance, by binding to a
privileged port) and subsequently changes to another user ID (to
drop privileges), the credentials will remain root.

User and group IDs can be specified as either numbers or names.
The syntax is similar to the one for ports. The value unknown
matches packets of forwarded connections. unknown can only be used
with the operators = and !=. Other constructs like user >= unknown
are invalid. Forwarded packets with unknown user and group ID
match only rules that explicitly compare against unknown with the
operators = or !=. For instance user >= 0 does not match forwarded
packets. The following example allows only selected users to open
outgoing connections:

block out proto { tcp, udp } all
pass out proto { tcp, udp } all user { < 1000, dhartmei }

Перенаправление трафика пользователя.

Добавлено: 2019-06-12 11:48:25
skeletor
Судя по man'y, то да. Попробуйте, расскажите. Возможно я был не прав ))

Перенаправление трафика пользователя.

Добавлено: 2019-10-14 18:24:49
novik
skeletor писал(а):
2019-06-12 11:48:25
Попробуйте, расскажите.
Вроде нормально работает.

Код: Выделить всё

pass out quick on $ext_if route-to ($vpn_if $gw_vpn) from ($vpn_if) to any user novik
pass in quick on $ext_if route-to ($vpn_if $gw_vpn) from ($vpn_if) to any user novik
pftop кажет:

Код: Выделить всё

   7  Pass     Out     Q ng0              K  3365231 1191425K 3253144K       route-to ... inet from (ng1) to any user = 1001  flags S/SA
   8  Pass     In      Q ng0              K        0        0 3253144K       route-to ... inet from (ng1) to any user = 1001  flags S/SA