D
D
Dmitry Alexandrov2020-02-05 21:33:56
linux
Dmitry Alexandrov, 2020-02-05 21:33:56

How to split traffic on linux?

There are two providers on the device, one is cheap and slow and the other is expensive but fast. As an example: I want only mail to work through a cheap one, and YouTube and other traffic go through the road.

How to configure routing and firewall (iptables)?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Dimonchik, 2020-02-05
@dimonchik2013

adjust handles
look for "two channels", microtic and all that

K
Karpion, 2020-02-06
@Karpion

It is necessary to configure complex routing.
Let the "cheap and slow provider" give you the IP address "IP1"
and the "expensive but fast provider" give you the IP address "IP2"
. Those. "mail" (SendMail or whoever you have) should open a connection from IP1, and users' browsers worked from IP2. Depends on it - through what provider you will be sent the answer.
The mail program must have an option in the config - from which address to open the connection.
Or you can drive TCP:25 traffic into NAT in iptables to convert the IP address.
And user programs are probably already configured to work through NAT (more precisely, the server intercepts their traffic and NATit. It is enough to correctly register the IP address IP2. Moreover, it is possible that SMTP and POP3 work for users - then you need to change the NAT rules by entering ports 25 there, 110 and what else is used there - on IP1
.

G
Germanjon, 2020-02-06
@Germanjon

1. Option 1:
route add default gw expensive_provider_gateway (or via connection_interface)
route add ip_mail_address gw cheap provider_gateway (or via connection_interface).
2. Option 2:
Torment with BGP

A
Alexey Dmitriev, 2020-02-06
@SignFinder

Use iproute2. It allows you to route marked traffic, for example, in iptables.
Mark the traffic you need and tell ip route where to route it.
A simpler option is if you use NAT, then you can use -j SNAT --to-source your output ip
instead of -j MASQUERADE
Accordingly, it will be different for different types of traffic.

K
kiper-prog, 2020-02-07
@kiper-prog

One friend did something similar on FreeBSD, ipfw, he also made it so that when one provider is turned off, all traffic turns to another, you can dig in this direction.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question