LinuxSir.cn,穿越时空的Linuxsir!

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

请教SLACKWARE 10 怎么配置双网卡!!!!

[复制链接]
发表于 2005-8-22 17:52:48 | 显示全部楼层 |阅读模式
本人要做一个双网平衡但配置第一个网卡。IP和网关之后第二个网卡没有办法配置网关了。不知道要怎么弄,请高手指教!!!!
发表于 2005-8-22 18:01:35 | 显示全部楼层
我想所谓的网关实现的功能只是当网络信息传递找不到路径的时候要查询的地址吧,其实应该还是
路由功能的一个简单部分。默认的网关只能有一个,就算你使用route命令添加了第二个网关,也
是没有任何作用的。同时在/etc/rc.d/rc.inet1.conf中也不允许定义2个网关。要想2个静态IP地址
直接使用不同的网关,应该没有直接的配置文件。

要想使不同网段的访问正常有几个方案:

1、使用网络地址翻译。
2、使用路由器或路由服务。
3、使用DHCP服务器来获得动态IP和网关。
4、网络地址重定向。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-23 08:10:00 | 显示全部楼层
能不能再细说一下。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-24 12:35:34 | 显示全部楼层
我想了一个方法不知道行不行得通。就是在etc/rc.d/rc.inet1.conf默认电信的网关。在路由里默认是网通的网关,这样可不可以。。
回复 支持 反对

使用道具 举报

发表于 2005-8-25 18:14:45 | 显示全部楼层
Post by jonybay
我想了一个方法不知道行不行得通。就是在etc/rc.d/rc.inet1.conf默认电信的网关。在路由里默认是网通的网关,这样可不可以。。

我觉着不可行,两个默认网关是没有意义的设置,默认网关只能有一个。
要作双网平衡论坛里有这样的主题,也有很多实现的方案,但绝不是强行添加网关能够解决的。
这里有个网址应该有帮助:
http://www.lartc.org/
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-26 11:26:31 | 显示全部楼层
英文的。看不太懂~~~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-27 11:01:50 | 显示全部楼层
可不可以用一个路由器代替一个电信的。然后再用LINUX做一个策略路由。这样就不用设两个网关了吧?我照论坛里的策略路由做了一下,没有成功不知道出错在哪里,电信和网通只能一个能上网。
回复 支持 反对

使用道具 举报

发表于 2005-8-27 13:06:51 | 显示全部楼层
关于双网平衡的问题,我这里实在是没有那个实践条件,所以具体问题没办法帮兄弟了。
不过这个问题网络上应该能找到很多解决的方案,不行的话找你们当地的电信和网通的技术人员咨询一下啊。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-8-28 08:53:25 | 显示全部楼层
局域网及服务器状况:

服务器两块网卡,其实三块也一样。

ADSL:服务器eth0,网址为192.168.2.***,网关为192.168.2.1,网关是一台小路由器,几百块钱的那种,8口的,支持一些比较简单的路由功能,例如NAT,DHCP,ADSL自动拨号等,这样服务器就不用管ADSL拨号了,只要走192.168.2.1就可以了。

教育网:服务器eth1网址为166.111.***.***,网关为166.111.***.***,直接连接到教育网





解决方案:ROUTE+NAT





1、 添加路由表

在添加之前先用route –n查看一下你的路由表,看0.0.0.0,且掩码也为0.0.0.0的路由是不是从ADSL网卡走的,那表示默认路由,如果从教育网走是不行的,我们将FreeIP单独处理,剩下的都从ADSL走。如果那条记录不是从ADSL走的,就把那一条删除,重新添加一条从ADSL走的。

上面OK了后,接着的任务就是搞一份FreeIP表,这个到处都有。我们下面将路由配置写到一个文件中,例如我们给这个文件起名为route。对一个地址为:60.0.0.0,掩码:255.224.0.0的网段,我们可以写成这个样子:

route add –net 60.0.0.0 netmask 255.224.0.0 gw 166.111.***.***。

其中166.111.***.***为你接教育网的那块网卡上用的网关。添加路由表有个简便的方法,这是覃健祥教我的,用将网页上的FreeIP表导到Excel中,然后添加几列:route add-net 和netmask和gw几个列字段都是一样的,组合一下,输出成文本文件,这样就方便多了,不用一行一行的敲了。

生成好了这个文件后将文件权限改为可执行,然后在/etc/rc.d/rc.local中添加一行执行这个文件的命令,保证每次开机都会自动添加路由表。然后手动执行一下,不需要重新启动,用route –n命令就可以看到路由表了,是不是很有成就感,胜利就在眼前。

2、 添加NAT

下面为NAT写一个文件,假设文件名为nat。

#-----------------------------------------------------------------------------------

#!/bin/sh

Echo 1 > /proc/sys/net/ipv4/ip_forward

/sbin/iptables –F –t nat

/sbin/iptables –t nat –A POSTROUTING –s 192.168.2.0/24 –o eth0 –j SNAT –to 192.168.2.***

/sbin/iptables –t nat –A POSTROUTING –s 192.168.2.0/24 –o eth1 –j SNAT –to 166.111.***.***

#-----------------------------------------------------------------------------------





下面解释一下这几行命令:

Echo 1 > /proc/sys/net/ipv4/ip_forward 允许包转发

/sbin/iptables –F –t nat 清空iptables表

/sbin/iptables –t nat –A POSTROUTING –s 192.168.2.0/24 –o eth0 –j SNAT –to 192.168.2.*** 如果从eth0走则将源ip改为192.168.2.***

/sbin/iptables –t nat –A POSTROUTING –s 192.168.2.0/24 –o eth1 –j SNAT –to 166.111.***.*** 如果从eth1走则将源ip改为166.111.***.***





最后一步,把这个文件执行一下,然后将每台客户机设一下ip、掩码,网关设成服务器ip,dns设成192.168.2.1就行。恭喜你,大功告成了,现在客户机可以自动的选择教育网和ADSL,可以享受教育网的丰富资源了。


我看过这个才想到这个方法,我也没有试不知道能不能成功。
回复 支持 反对

使用道具 举报

发表于 2005-8-29 00:41:36 | 显示全部楼层
routing policy database Next

----------------------------------------------------------------------

4.2. 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.

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


http://slackware.zzmobile.com/bl ... d=a_20050807_202220
回复 支持 反对

使用道具 举报

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

本版积分规则

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