Задача такая
Есть внешний сервер, к нему подключены 5 внешних (Белых) IP
Нужно поднять на нем 5 соксов, на разных портах, каждый сокс должен смотреть через свой внешний IP. Этакий прокси-роутер :)
Что имеем:
ifconfig:
venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:127.0.0.2 P-t-P:127.0.0.2 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
RX packets:1239 errors:0 dropped:0 overruns:0 frame:0
TX packets:1141 errors:0 dropped:1 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:92654 (90.4 KiB) TX bytes:122191 (119.3 KiB)
venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:93.170.123.191 P-t-P:93.170.123.191 Bcast:93.170.123.191 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
venet0:1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:93.170.123.201 P-t-P:93.170.123.201 Bcast:93.170.123.201 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
venet0:2 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:93.170.123.208 P-t-P:93.170.123.208 Bcast:93.170.123.208 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
venet0:3 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:93.170.123.212 P-t-P:93.170.123.212 Bcast:93.170.123.212 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
venet0:4 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:93.170.123.213 P-t-P:93.170.123.213 Bcast:93.170.123.213 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
Создал 5 юзеров в системе c UID 1000,1001,1002,1003,1004 (1,2,3,4,5)
И пытаюсь назначить для них разные шлюзы
/etc/rc.local
/sbin/iptables -t mangle -A OUTPUT -m owner --uid-owner 1000 -j MARK --set-mark 1
/sbin/iptables -t mangle -A OUTPUT -m owner --uid-owner 1001 -j MARK --set-mark 2
/sbin/iptables -t mangle -A OUTPUT -m owner --uid-owner 1002 -j MARK --set-mark 3
/sbin/iptables -t mangle -A OUTPUT -m owner --uid-owner 1003 -j MARK --set-mark 4
/sbin/iptables -t mangle -A OUTPUT -m owner --uid-owner 1004 -j MARK --set-mark 5
/bin/ip rule add fwmark 1 table P1
/bin/ip rule add fwmark 2 table P2
/bin/ip rule add fwmark 3 table P3
/bin/ip rule add fwmark 4 table P4
/bin/ip rule add fwmark 5 table P5
/bin/ip route add default via 93.170.123.191 dev venet0:0 table P1
/bin/ip route add default via 93.170.123.201 dev venet0:1 table P2
/bin/ip route add default via 93.170.123.208 dev venet0:2 table P3
/bin/ip route add default via 93.170.123.212 dev venet0:3 table P4
/bin/ip route add default via 93.170.123.213 dev venet0:4 table P5
после чего делаю su 4
4@alex:/root$ curl -s http://whatismijnip.nl |cut -d " " -f 5
93.170.123.191
и под каким бы юзером не зашел (через su) 1-5, под всеми этот один IP
что у меня не так?
Диагностика:
root@alex:~# iptables -L -t mangle
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
MARK all -- anywhere anywhere owner UID match 1 MARK set 0x1
MARK all -- anywhere anywhere owner UID match 2 MARK set 0x2
MARK all -- anywhere anywhere owner UID match 3 MARK set 0x3
MARK all -- anywhere anywhere owner UID match 4 MARK set 0x4
MARK all -- anywhere anywhere owner UID match 5 MARK set 0x5
root@alex:~# ip rule list
0: from all lookup local
32761: from all fwmark 0x5 lookup P5
32762: from all fwmark 0x4 lookup P4
32763: from all fwmark 0x3 lookup P3
32764: from all fwmark 0x2 lookup P2
32765: from all fwmark 0x1 lookup P1
32766: from all lookup main
32767: from all lookup default
root@alex:~# ip route list table P1
default via 93.170.123.191 dev venet0
root@alex:~# ip route list table P2
default via 93.170.123.201 dev venet0
root@alex:~# ip route list table P3
default via 93.170.123.208 dev venet0
root@alex:~# ip route list table P4
default via 93.170.123.212 dev venet0
root@alex:~# ip route list table P5
default via 93.170.123.213 dev venet0
root@alex:~# route add whatismijnip.nl gw 93.170.123.212
root@alex:~# curl -s http://whatismijnip.nl |cut -d " " -f 5
93.170.123.212
а так работает!
вообще странно что когда я su делаю на юзера, у меня грузится без обратного nat'a что-то под ним!
такое чувство что не работает iptables mark+iproute