[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Разделение трафика



В Пнд, 12/11/2007 в 19:47 +0300, Tiurin Alexandr пишет:
> Покотиленко Костик пишет:
> > В Суб, 10/11/2007 в 10:47 +0300, Tiurin Alexandr пишет:
> >> Доброго времени суток.
> >> Комп подключен к провайдеру по 2м тарифам. Т.е. имеется 2 из из одной 
> >> сети, каждый ип для одного тарифного плана соответственно. Оба ипа висят 
> >> на одной сетевой карте.
> >> Необходимо, что бы конкретные программы выходили в сеть с определенных 
> >> ипов.
> > 
> > Если не секрет - зачем? Какого эффекта ожидаете?
> > 
> > У меня в одной конторе 4 ppp по разным тарифам. Одна группа клиентов
> > ходит по 1-му ppp. Остальные днём по 2-му, вечером и в выходные по 3-му,
> > а городской трафик у всех только по 4-му.
> > 
> > Могу вспомнить как сделал.
> > 
> 
> Провайдер на безлимитных тарифах режет tcp сессии до 20 (т.е 
> входящие+исходящие = не более 20). Т.к. обильно пользуюсь p2p, то часто 
> сеть тормозит (во время веб-серфинга), даже если по скорости обмен 
> трафиком далек до максимума. Да и в целом, используя p2p + зарезаный 
> анлим, получается, что я не реализую весь потенциал этого тарифа по 
> скорости.
> Поэтому хочу, что б p2p ходил по одному тарифу, а все остальное по другому.

Два пути:

1. Используя только iptables.
# man iptables
...
   ROUTE
       This is used to explicitly override the core  network  stack's
routing
       decision.

       (Please  note:  This  target  requires kernel support that might
not be
       available in official Linux kernel sources or Debian's  packaged
Linux
       kernel  sources.   And  if support for this target is available
for the
       specific Linux kernel source version, that support might not be
enabled
       in the current Linux kernel binary.)

       mangle table.

       --oif ifname
              Route the packet through `ifname' network interface

       --iif ifname
              Change the packet's incoming interface to `ifname'

       --gw IP_address
              Route the packet via this gateway

       --continue
              Behave like a non-terminating target and continue
traversing the
              rules.  Not valid in combination with `--iif' or `--tee'

       --tee  Make a copy of the packet, and route that copy to the
given des-
              tination.  For the original, uncopied packet, behave like
a non-
              terminating target and continue traversing the rules.  Not
valid
              in combination with `--iif' or `--continue'
...

2. iptables + iproute2

С помощью iptables ставишь марки, с помощью iproute2 создаёшь
альтернативные таблицы маршрутизации и раскидываешь по маркам трафик в
разные таблицы. Примерно так:

iptables -t mangle -A FORWARD -p tcp --dport 80 -j MARK --set-mark 0x45
iptables -t mangle -A FORWARD -p tcp --dport 80 -j RETURN
iptables -t mangle -A FORWARD -j MARK --set-mark 0x46
iptables -t mangle -A FORWARD -j RETURN

echo 200 P2P >> /etc/iproute2/rt_tables
echo 201 Other >> /etc/iproute2/rt_tables

ip route add default dev eth0 table P2P
ip route add default dev eth0:0 table Other

ip rule add fwmark 0x45 table P2P
ip rule add fwmark 0x46 table Other

-- 
Покотиленко Костик <casper@meteor.dp.ua>



Reply to: