R
R
Roman Vasilenko2014-06-13 12:36:36
Squid
Roman Vasilenko, 2014-06-13 12:36:36

It is very necessary to configure Squid3 -> 2 parallel providers (USB, USB)

Hello!
I've been fighting for two months now with a problem: I can't set up Internet access from the local network through two providers.
I need the proxy server on squid to send requests to the modem and router in a 1:1 or 1:2 ratio when accessing it. More shortly that if through squid - two channels are involved.
And I do not mean some kind of gluing of channels to increase power - you need to work only at the level of request distribution.
What I have:
- Local network 192.168.2.0/24
- Zyxel Keenetic Giga II router, IP: 192.168.2.1, gateway
- Server with Ubuntu 12.04.4 LTS, on which the services I need are running and Squid3 is installed. IP: 192.168.2.10
- USB modem MegaFon 100-3 (ZTE MF-823), plugged into Zyxel Keenetic Giga II
- Beeline USB modem (ZTE MF-667), plugged into the Server with Ubuntu 12.04.4 LTS
Server configuration:
/etc/network/interfaces:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.2.10
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
gateway 192.168.2.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.4.4 8.8.8.8
# 3G
Modemace ppp0 inet wvdial
provider wvdial
auto ppp0
wvdial.conf:
[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0
Init3 = AT+CGDCONT=1,"IP","home.beeline.ru"
Modem Type = Analog Modem
Phone = *99#
ISDN = 0
Password = beeline
New PPPD = 1 Username
= beeline Modem = /
dev/ttyUSB1
Baud = 9600
Stupid Mode = 1
Auto Reconnect = on
Idle Seconds = 0 IF1=eth0 IP1=192.168.2.1 P1=192.168.2.1 P1_NET=192.168.2.0/24 IF2=ppp0 IP2=`ip address show | grep ppp0 | sed '1d' | awk '{print $2}'`
P2=`ip route show dev ppp0 | awk '/r/ { print $1 }'`
P2_NET=`ip route show dev ppp0 | awk '/r/ { print $1 }'`/32
ip route add $P1_NET dev $IF1 src $IP1 table zyxel
ip route add default via $P1 table zyxel
ip route add $P2_NET dev $IF2 src $IP2 table beeline
ip route add default via $P2 table beeline
ip route add $P1_NET dev $IF1 src $IP1
ip route add $P2_NET dev $IF2 src $IP2
#ip route add default via $P1
ip rule add from $IP1 table zyxel
ip rule add from $ IP2 table beeline
ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \
nexthop via $P2 dev $IF2 weight 1
But when I run it, the Internet disappears, and I'm not smart enough to understand why.
I am not an admin and I am forced to do this, because there is no one else. Help me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cool Admin, 2014-06-13
@ifaustrue

Colleague, welcome! I'll tinker a little, add comments to your script,

so that you understand the logic and we speak the same language:
#!/bin/sh
#Описываем переменные первого интерфейса и его подсеть
IF1=eth0
IP1=192.168.2.1
P1=192.168.2.1
P1_NET=192.168.2.0/24
#Аналогично для второго (но влоб это сделать нельзя, потому достаём всё динамически через grep)
IF2=ppp0
IP2=`ip address show | grep ppp0 | sed '1d' | awk '{print $2}'`
P2=`ip route show dev ppp0 | awk '/r/ { print $1 }'`
P2_NET=`ip route show dev ppp0 | awk '/r/ { print $1 }'`/32
#Создаём первую таблицу маршрутизации
ip route add $P1_NET dev $IF1 src $IP1 table zyxel
#задаём для неё шлюз по умолчанию
ip route add default via $P1 table zyxel
#Аналогично со второй
ip route add $P2_NET dev $IF2 src $IP2 table beeline
ip route add default via $P2 table beeline

#Задаём два правила для ответа на входящий трафик, откуда пришёл, туда и ответить
ip route add $P1_NET dev $IF1 src $IP1
ip route add $P2_NET dev $IF2 src $IP2

#задаём правило трафика по-умолчанию (сами закомментили?)
#ip route add default via $P1
#дополнительно говорим, что при трафик от айпи интерфейса, ответить с использование соотв. таблиц (в первую очередь для для DNAT)
ip rule add from $IP1 table zyxel
ip rule add from $IP2 table beeline

#Определяем веса таблиц, которые мы создали и говорим что их нуджно использовать после основной (в которой у нас по идее пусто)
ip route add default scope global nexthop via $P1 dev $IF1 weight 1 nexthop via $P2 dev $IF2 weight 1

Actually, what seemed strange (and possibly wrong)
1. No masquerading for traffic. In the case of a zixel, you most likely do not need it, but with a modem without it,
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -s $P1_NET -o $IF2 -j MASQUERADE
2. Why commented out the default route in the script?
#ip route add default via $P1
remove, check
3. After running the script - ping the default gateways (ifconfig will show them to you), and also see the route output - there should be visible two routing tables and routes for everything and everything.

S
shaazz, 2014-06-13
@shaazz

Frankly speaking, the essence of the question is not clear. Usually, with two providers, channel reservation is required (a certain number of pings with a certain timeout to an external address is achieved and, if there are no responses, switching to a reserve), or spillover balancing (when a given threshold is reached, the second channel is used simultaneously), round robin (in turn) . It is configured on one device. That is, either on a Zyxel piece of iron if it supports channel redundancy or balancing, where one input is a USB whistle, the second is Ubuntu via ethernet -> WAN. But since you still have services running on Ubuntu, this does not suit you (the server behind the WAN will not be visible). Therefore, you must have an Ubuntu server as a gateway, where one input is a USB whistle, the second is Zyxel via ethernet (and, accordingly, the second network card must be on a server for LAN).Balancing in Ubuntu.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question