LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-19-2009, 08:40 AM   #1
alexovi4
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Thumbs up 2 providers, iptables, iproute


Hello. Sorry my ENGLISH.
I have a connection to 2 (two) ISP on SLES 11.The routing is working.
Script of my gateway below.
NET_LOCAL1 goes via first ISP, LOCAL_NET2 goes via second ISP. For example, NET_LOCAL1 has address from network 192.168.1.0/24.
But how can i do connnection to Internet from address 192.168.1.5 via second ISP (GW_PROV2)???
--------------------------------------------------------------------
I find 2 ways:
1) use fwmark:
iptables -t mangle -A PREROUTING -s 192.168.1.5 -j MARK --set-mark 10
iptables -t mangle -A PREROUTING -s 192.168.1.0/24 -j MARK --set-mark 20
iptables -t nat -A POSTROUTING -m mark --mark 10 -j SNAT --to-source $IP_PROV2
iptables -t nat -A POSTROUTING -m mark --mark 20 -j SNAT --to-source $IP_PROV1
ip rule add fwmark 10 lookup T_PROV2
ip rule add fwmark 20 lookup T_PROV1
2) use this command:
iptables -t nat -A POSTROUTING -s 192.168.1.5 -o $IF_PROV2 -j SNAT --to-source $IP_PROV2
ip rule add from 192.168.10.2 lookup T_PROV2 pref 2001
---------------------------------------------------------------------
#!/bin/bash
echo "1">/proc/sys/net/ipv4/ip_forward
iptables -t nat -F
iptables -t mangle -F
ip route flush table T_PROV1
ip route flush table T_PROV2
iptables -t nat -A POSTROUTING -s $NET_LOCAL1 -o $IF_PROV1 -j SNAT --to-source $IP_PROV1
#T_PROV1
ip route add $NET_LOCAL1 dev $IF_LOCAL1 src $IP_LOCAL1 table T_PROV1
ip route add $NET_PROV1 dev $IF_PROV1 src $IP_PROV1 table T_PROV1
ip route add $NET_LOCAL2 dev $IF_LOCAL2 src $IP_LOCAL2 table T_PROV1
ip route add $NET_PROV2 dev $IF_PROV2 src $IP_PROV2 table T_PROV1
ip route add default via $GW_PROV1 table T_PROV1
ip route add 127.0.0.0/8 dev lo table T_PROV1
#T_PROV2
ip route add $NET_PROV2 dev $IF_PROV2 src $IP_PROV2 table T_PROV2
ip route add $NET_PROV1 dev $IF_PROV1 src $IP_PROV1 table T_PROV2
ip route add $NET_LOCAL2 dev $IF_LOCAL2 src $IP_LOCAL2 table
ip route add $NET_LOCAL1 dev $IF_LOCAL1 src $IP_LOCAL1 table T_PROV2
ip route add default via $GW_PROV2 table T_PROV2
ip route add 127.0.0.0/8 dev lo table T_PROV2
#main
ip route add $NET_LOCAL1 dev $IF_LOCAL1 src $IP_LOCAL1
ip route add $NET_PROV1 dev $IF_PROV1 src $IP_PROV1
ip route add $NET_PROV2 dev $IF_PROV2 src $IP_PROV2
ip route add $NET_LOCAL2 dev $IF_LOCAL2 src $IP_LOCAL1
ip route add default via $GW_PROV2

ip rule delete table T_PROV1
ip rule delete table T_PROV1
ip rule delete table T_PROV2
ip rule delete table T_PROV2
ip rule delete table T_PROV1
ip rule delete table T_PROV1
ip rule delete table T_PROV2
ip rule delete table T_PROV2

ip rule add from $IP_PROV1 lookup T_PROV1 pref 2010
ip rule add from $IP_PROV2 lookup T_PROV2 pref 2020
ip rule add from $NET_LOCAL1 lookup T_PROV1 pref 2030
ip rule add from $NET_LOCAL2 lookup T_PROV2 pref 2040
ip route flush cache
exit 0.
----------------------------------------------------------
What way will be better for perfomance of Linux server?
Or there are some different type of solve task of regulate diff address go via diff ISP?
Please help.....
 
Old 08-19-2009, 08:47 AM   #2
evilted
Member
 
Registered: Aug 2009
Location: Ouagadougou, Burkina Faso
Distribution: centos
Posts: 92

Rep: Reputation: 18
your missing a default gateway to route to both networks..

heres an example:

Code:
ip route default nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2
to make it a bit easier, relax your firewall until you get the load balancing working correctly then start messing with your rules.


this has been documented many times:

http://lartc.org/howto/lartc.rpdb.multiple-links.html

Last edited by evilted; 08-19-2009 at 08:47 AM. Reason: forgot damn code tags.
 
Old 08-19-2009, 09:10 AM   #3
alexovi4
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by evilted View Post
your missing a default gateway to route to both networks..
Why???
Code:
#T_PROV1
ip route add default via $GW_PROV1 table T_PROV1
#T_PROV2
ip route add default via $GW_PROV2 table T_PROV2
#main
ip route add default via $GW_PROV2
Quote:
Originally Posted by evilted View Post
heres an example:
Code:
ip route default nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2
to make it a bit easier, relax your firewall until you get the load balancing working correctly then start messing with your rules.
I don't need load balancing, i want to change access to the Internet for PC from local network via different ISP.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iproute vishamr2000 Linux - Networking 4 08-04-2005 01:40 AM
iptables/iproute vs ipcop gsgleason Linux - Networking 3 02-10-2005 07:48 PM
new to iproute. please help ? mrpc_cambodia Red Hat 0 07-05-2004 11:20 PM
how to install iproute KoKi Linux - Networking 5 02-03-2004 03:47 PM
2 versions of iproute ? lozz1978 Linux - Newbie 2 01-07-2004 10:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration