Route based on port / protocol

Linux Advanced Routing and Traffic Control

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

 



Title: Mensagem
I have a Linux Box with 3 NIC's connected to 2 different ISP's running a Proxy (Squid) and E-mail server (QMail).
                                  ________
                                  |             |-- x.x.x.1 ---- x.x.x.2 (ISP-1 gateway)
                                  |   Squid  |
LAN ------- 10.85.1.85 --|             |
                                  |  Qmail  |
                                  |             |-- y.y.y.1 ---- y.y.y.2 (ISP-2 gateway)
                                  --------------
 
All is running OK. But now, I want do redirect all traffic from Squid (http) to ISP-1 and all traffic from QMail (smtp) to ISP-2.
Anyone can help me ?
 
 
I've already tried this, but no success:
 
  # Create two tables (21 and 31) to use with each connection 
  # Copy main route to table 31
ip route show table main | grep -Ev ^default | \
   while read ROUTE ; do \
     ip route add table 31 $ROUTE; \
   done
  # use ISP-1 as default gateway for table 31
ip route replace default via x.x.x.2 table 31
  # Copy main route to table 21
ip route show table main | grep -Ev ^default | \
   while read ROUTE ; do \
     ip route add table 21 $ROUTE; \
   done
  # use ISP-2 as default gateway for table 21
ip route replace default via y.y.y.2 table 21
   # Mark packages (1 or ISP-1 e 2 for ISP-2)
   # here, I've tried to change OUTPUT for POSTROUTING and PREROUTING without success
iptables -t mangle -A OUTPUT -p tcp --dport 80 -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -p tcp --dport 25 -j MARK --set-mark 2
 
  # Define rules to use the correct connection
ip rule add from x.x.x.1 table 31
ip rule add fwmark 1 table 31
 
ip rule add from y.y.y.1 table 21
ip rule add fwmark 2 table 21
 
 
             Antonio Luiz
 

[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux