LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1169|回复: 10

多线路服务器如何让访问数据包从哪条线路进就从哪条出

[复制链接]
发表于 2006-10-26 09:39:26 | 显示全部楼层 |阅读模式
一台服务器,开了web服务,有两条线路,电信和教育网, 同时也就有了两个ip地址,现在希望教育网和电信网都可以访问其中任意一个ip,以前的做法是找出教育网的ip地址分配,加成静态路由,然后把电信网线路设置成默认路由,然后再配置针对源地址解析的dns.最近这样出现了一些问题,并且要不停的更新路由表,很麻烦。

现在希望能找一种用户访问的时候从哪条线路进来就从哪条线路出去的方式,这样就要方便很多,不知有没有哪位兄弟知道的,多谢先。
发表于 2006-10-26 13:51:11 | 显示全部楼层
类似的帖子仿佛出现过不只N次.
LZ去找找前面的帖子吧,关键字策略路由,双链路,
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-26 17:32:33 | 显示全部楼层
搜索了一下,似乎没有能满足需要的帖子。


我现在用的就是策略路由,但这样有缺陷。 如果来自电信网络的用户访问的是教育网接口的网卡ip,就访问不了,同样来自教育网的用户访问电信网接口的网卡ip也访问不了。

基于目标地址的策略路由只能简单的根据目标地址来路由,而理想的方式就是用户访问哪个网卡就从哪个网卡返回.
回复 支持 反对

使用道具 举报

发表于 2006-10-26 17:35:55 | 显示全部楼层
麻烦事,我们就是策略路由,结果不能架设服务器了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-27 09:38:08 | 显示全部楼层
网络中的双线服务器已经不少吧, 不知道它们是怎么解决的...
回复 支持 反对

使用道具 举报

发表于 2006-10-27 09:44:11 | 显示全部楼层
什么意思?没明白你的意思?
你是想做非对称路由咯?
就是从电信进来从教育网可以出去?
回复 支持 反对

使用道具 举报

发表于 2006-10-27 10:02:17 | 显示全部楼层
不对,你不是要做非对称路由.
你的意思是说电信用户会访问到教育网的地址.
这就不对了.
你不应该让它出现这种情况.
这种情况会出现用户收到的回包的源地址跟用户发包时的目的地址不一致.其实你已经弄巧成拙做了一个非对称路由,用户收到的包源地址不一致的话大部分情况会扔掉.
解决方法:
1:用DNS做view,让电信用户解析的是电信的IP,教育网解析的是教育网的IP
2:用IPTABLES做地址改写,把来自教育网的客户的包的目的地址改成教育网的IP,电信也是如此.


最好用第一个,第二个是在你没有域名的情况下用的.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-27 12:30:52 | 显示全部楼层
Post by Yuri

1:用DNS做view,让电信用户解析的是电信的IP,教育网解析的是教育网的IP
2:用IPTABLES做地址改写,把来自教育网的客户的包的目的地址改成教育网的IP,电信也是如此.

我现在就是这样作的。
Post by Yuri
不对,你不是要做非对称路由.
你的意思是说电信用户会访问到教育网的地址.
这就不对了.
你不应该让它出现这种情况.
这种情况会出现用户收到的回包的源地址跟用户发包时的目的地址不一致.其实你已经弄巧成拙做了一个非对称路由,用户收到的包源地址不一致的话大部分情况会扔掉.

debian内核会扔掉,但RH内核不会扔,但这种方式只有访问线路中所有的路由器都不仍的情况下才可以,现在我这里电信+教育网的双ip主机很正常,网通+教育网双ip的机器以前可以,但最近网通又申请了一段ip地址,换了pppoe拨号的服务器,现在网通线路会扔掉这种包。


关于这个问题我也没搞的很清楚, 现在我的系统是debian sarge,给它换了一个centos4.0内核,然后把/etc/network/options中的spoolprotect改成no就可以了。

现在只有一台比较老的服务器跑不了centos的内核,没法这么作。

这样的做法需要维护一个ip分配列表, 很麻烦, 并且ip分配经常变,如果ip分配变了之后没来得及改路由和dns view就会造成用户访问不了。 最完善的做法是配置dns match-client,然后再在服务器设置路由让数据从哪个接口进来就从哪个接口出去。 这样最方便。
回复 支持 反对

使用道具 举报

发表于 2006-10-27 15:52:01 | 显示全部楼层
这里有你要的答案,翻译就不帮你翻了
http://lartc.org/howto/lartc.rpdb.multiple-links.html
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-29 23:00:00 | 显示全部楼层
很不错。


多谢!










Routing for multiple uplinks/providers

A common configuration is the following, in which there are two providers that connect a local network (or even a single machine) to the big Internet.

                                                                 ________
                                          +------------+        /
                                          |            |       |
                            +-------------+ Provider 1 +-------
        __                  |             |            |     /
    ___/  \_         +------+-------+     +------------+    |
  _/        \__      |     if1      |                      /
/             \     |              |                      |
| Local network -----+ Linux router |                      |     Internet
\_           __/    |              |                      |
   \__     __/       |     if2      |                      \
      \___/          +------+-------+     +------------+    |
                            |             |            |     \
                            +-------------+ Provider 2 +-------
                                          |            |       |
                                          +------------+        \________

There are usually two questions given this setup.
4.2.1. Split access

The first is how to route answers to packets coming in over a particular provider, say Provider 1, back out again over that same provider.

Let us first set some symbolical names. Let $IF1 be the name of the first interface (if1 in the picture above) and $IF2 the name of the second interface. Then let $IP1 be the IP address associated with $IF1 and $IP2 the IP address associated with $IF2. Next, let $P1 be the IP address of the gateway at Provider 1, and $P2 the IP address of the gateway at provider 2. Finally, let $P1_NET be the IP network $P1 is in, and $P2_NET the IP network $P2 is in.

One creates two additional routing tables, say T1 and T2. These are added in /etc/iproute2/rt_tables. Then you set up routing in these tables as follows:

          ip route add $P1_NET dev $IF1 src $IP1 table T1
          ip route add default via $P1 table T1
          ip route add $P2_NET dev $IF2 src $IP2 table T2
          ip route add default via $P2 table T2
       

Nothing spectacular, just build a route to the gateway and build a default route via that gateway, as you would do in the case of a single upstream provider, but put the routes in a separate table per provider. Note that the network route suffices, as it tells you how to find any host in that network, which includes the gateway, as specified above.

Next you set up the main routing table. It is a good idea to route things to the direct neighbour through the interface connected to that neighbour. Note the `src' arguments, they make sure the right outgoing IP address is chosen.

            ip route add $P1_NET dev $IF1 src $IP1
            ip route add $P2_NET dev $IF2 src $IP2
          

Then, your preference for default route:

            ip route add default via $P1
          

Next, you set up the routing rules. These actually choose what routing table to route with. You want to make sure that you route out a given interface if you already have the corresponding source address:

            ip rule add from $IP1 table T1
            ip rule add from $IP2 table T2
          

This set of commands makes sure all answers to traffic coming in on a particular interface get answered from that interface.

Warning       

Reader Rod Roark notes: 'If $P0_NET is the local network and $IF0 is its interface, the following additional entries are desirable:

ip route add $P0_NET     dev $IF0 table T1
ip route add $P2_NET     dev $IF2 table T1
ip route add 127.0.0.0/8 dev lo   table T1
ip route add $P0_NET     dev $IF0 table T2
ip route add $P1_NET     dev $IF1 table T2
ip route add 127.0.0.0/8 dev lo   table T2                                      

'

Now, this is just the very basic setup. It will work for all processes running on the router itself, and for the local network, if it is masqueraded. If it is not, then you either have IP space from both providers or you are going to want to masquerade to one of the two providers. In both cases you will want to add rules selecting which provider to route out from based on the IP address of the machine in the local network.
4.2.2. Load balancing

The second question is how to balance traffic going out over the two providers. This is actually not hard if you already have set up split access as above.

Instead of choosing one of the two providers as your default route, you now set up the default route to be a multipath route. In the default kernel this will balance routes over the two providers. It is done as follows (once more building on the example in the section on split-access):

            ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \
            nexthop via $P2 dev $IF2 weight 1
          

This will balance the routes over both providers. The weight parameters can be tweaked to favor one provider over the other.

Note that balancing will not be perfect, as it is route based, and routes are cached. This means that routes to often-used sites will always be over the same provider.

Furthermore, if you really want to do this, you probably also want to look at Julian Anastasov's patches at http://www.ssi.bg/~ja/#routes , Julian's route patch page. They will make things nicer to work with.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表