如何通过iptables等手段合并2个网卡..

83 views
Skip to first unread message

david pu

unread,
May 6, 2014, 2:55:04 AM5/6/14
to sh...@googlegroups.com
假定我有eth0, eth1 2个网卡,希望同一时刻只有1个能work,但是中间会切换而且IP保持一样。
怎么虚拟一个ethX,使得系统其实就看到一个然后通过转发来在不同的eth0/1工作的时候切换?

--
() ASCII Ribbon Campaign
/\ Keep it simple!

liyaoshi

unread,
May 6, 2014, 3:18:47 AM5/6/14
to sh...@googlegroups.com
brctl add br0 eth0 eth1


--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Shanghai Linux User Group”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/d/optout

liyaoshi

unread,
May 6, 2014, 3:20:13 AM5/6/14
to sh...@googlegroups.com
brctl add br0
brctl addif  br0 eth0
brctl addif br0 eth1 

david pu

unread,
May 6, 2014, 3:31:05 AM5/6/14
to sh...@googlegroups.com
大赞!
我来研究下hoho
> 您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。
> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到shlug+un...@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout



Heiher

unread,
May 6, 2014, 3:33:42 AM5/6/14
to shlug
Bridge 的方式好像不是同一时刻只有一个工作吧?
Best regards!
Heiher
http://hev.cc

letaotor

unread,
May 6, 2014, 3:34:15 AM5/6/14
to sh...@googlegroups.com
用bond吧,mode 1 应该能满足需求

Yours sincerely,

letaotor

letaotor

unread,
May 6, 2014, 3:47:06 AM5/6/14
to sh...@googlegroups.com



在 2014年5月6日 下午3:34,letaotor <leta...@gmail.com>写道:
用bond吧,mode 1 应该能满足需求
哦,应该是bonding 



--

Yours sincerely,

letaotor

david pu

unread,
May 6, 2014, 4:52:12 AM5/6/14
to sh...@googlegroups.com
嗯,看来bonding更高级,符合我的需求,多谢~

August

unread,
May 6, 2014, 8:35:45 AM5/6/14
to sh...@googlegroups.com

bond

Chaos Eternal

unread,
May 8, 2014, 2:14:51 AM5/8/14
to sh...@googlegroups.com
涨姿势啊。

是不是还可以trunc一下,再划点vlan? 然后帮助它把spanning tree收敛起来?
靠谱。比楼下那些bonding的高级。

2014-05-06 15:20 GMT+08:00 liyaoshi <liya...@gmail.com>:
> 您收到此邮件是因为您订阅了Google网上论坛中的“Shanghai Linux User Group”论坛。

liyaoshi

unread,
May 8, 2014, 3:30:08 AM5/8/14
to sh...@googlegroups.com
vlan tag 需要对端同时支持vlan tag,这个跟spanningtree 不是一个层面的东西吧

如果bonding的话,就不需要spanning tree了吧?

关键是我还没看明白他最后想要干嘛?

如果只是当backup ,我觉得bridge是最好的办法

插在上面不用动,而且用的时候可以两个口一起工作,带宽 双倍,

而且
bridge的时候vlan和spanning tree 才有意义啊



david pu

unread,
May 15, 2014, 12:29:46 AM5/15/14
to sh...@googlegroups.com
其实是个很蛋疼的需求。
你可以认为有个很蛋疼的modem,上面居然还跑Linux,然后和一个AP(application
processor)接着。同时有UART和USB UTMI连接可以用。
于是一个更蛋疼的需求来了,需要在高速传输时走USB,低速的时候走UART。USB上跑NCM,UART上跑RAW IP包,需要这个无缝切换,不能断哦亲。
研究了几天bonding,发现太高大上了,想来还是用很猥琐的raw socket直接强插以太网包省事哈哈哈。

liyaoshi

unread,
May 15, 2014, 2:05:38 AM5/15/14
to sh...@googlegroups.com
华为的?

liyaoshi

unread,
May 15, 2014, 2:22:36 AM5/15/14
to sh...@googlegroups.com
我不理解的是,为毛低速不能走USB ?
大家一起走usb 不是很happy么?


在 2014年5月15日 下午12:29,david pu <pulq...@gmail.com>写道:

david pu

unread,
May 15, 2014, 2:29:02 AM5/15/14
to sh...@googlegroups.com
usb UTMI比较费电呗。 HSIC又没有。

liyaoshi

unread,
May 15, 2014, 2:52:12 AM5/15/14
to sh...@googlegroups.com
要不你开两条路由,NCM 一条,ppp一条,

你怎么判断是高速应用还是低速应用啊?

juju

unread,
May 15, 2014, 2:59:59 AM5/15/14
to sh...@googlegroups.com
高大上地用动态路由协议呗,里面可以设置每条路由的带宽限制……

liyaoshi

unread,
May 15, 2014, 3:30:09 AM5/15/14
to sh...@googlegroups.com
关键你串口不设带宽限制,最多也就个10Mbps,他们用的话,估计也就是115200bps

liyaoshi

unread,
May 15, 2014, 3:37:24 AM5/15/14
to sh...@googlegroups.com
动态路由是比较简单,但是一个 HTTP SESSION可能会被打断,
我不知道他们最后定义切换并且ip保持一致这个需求怎么定义出来的
个人理解你们的应用,
4G lte , 3G 接入, gprs gsm接入 接入的BIAS多不是一个,你怎么保证你的ip一致啊?
出去的IP肯定会变。

还是说,看网页的时候用4G走usb,看小说的时候,4G走UART,

如果是这个需求,我只能说你们刻舟求剑了。

david pu

unread,
May 15, 2014, 5:33:55 AM5/15/14
to sh...@googlegroups.com
模式切换的时候IP本来就是一致的哦,不会变。。

liyaoshi

unread,
May 15, 2014, 6:11:26 AM5/15/14
to sh...@googlegroups.com
3G ppp拨号 LTE LPP的
IP我记得是变得
3G得到10网段的 LTE 210的

我们用华为909

Sherlock

unread,
Sep 15, 2014, 10:30:01 PM9/15/14
to Shanghai Linux User Group
Linux Advance Router
可以按照连接速度设置比重,从多个口出去,回到机器后数据包会重组,貌似10年前就有人这么做了。
==========
      InitX
==========

李伟斌

unread,
Sep 17, 2014, 10:07:42 PM9/17/14
to sh...@googlegroups.com
链路聚合?

发自我的 iPhone

Gene Wu

unread,
Sep 18, 2014, 2:31:51 AM9/18/14
to SHLUG

我记得大卫同学是arm的

Gmail

unread,
Sep 18, 2014, 10:02:00 AM9/18/14
to sh...@googlegroups.com
arm是个公司?


Wizard

unread,
Sep 19, 2014, 8:47:34 PM9/19/14
to shlug
这么老的线索,被顶上来了。 正好这两天在看vlan,有点困惑顺便凑个热闹。

说vlan有几种封装方式 ISL 802.1q,不外乎就是加点头,里面有个vlan tag。
这个我是明白的。 文档上说要设备,驱动,交换机都支持vlan才能用,我略微有点困惑。

1. 一台机器的一个网口插在一个交换机的网口上
如果这个交换机的网口配置了vlan 5(我的理解是要配置的), 那是不是
我这个机器上的port也一定要配置成vlan 5?
如果我这个机器的网口不支持vlan呢? 经过交换机的网口会自动添加vlan tag么?

2. 我看有的linux vlan配置文档上有写 eth0, eth0.5, 后面那个是配置成vlan 5的网口
从物理上讲,这两个接口是从一个端口出去的。 那这两个口都能工作?

3. 我猜啊,如果一个端口配置成了vlan 5, 比如说eth0.5. 那么所有从这个端口出去的包
都会加上vlan tag? 手头木有交换机可以配置,所以也不知道这个玩意怎么测。
然后要从这个端口进来的包也必须有vlan tag 且 为 5?

vlan这个东西听了很久了,但一直不太清楚。还请大侠赐教啊
Wizard

Alpha Cheng

unread,
Sep 19, 2014, 11:48:31 PM9/19/14
to sh...@googlegroups.com
有误请指正

先讲一句,用tcpdump解码以太网帧,你会发现新大陆

1. 交换机配置了网卡未必要配置,取决于交换机上这个VLAN口的工作方式。没记错的话,Access模式交换机会自动把带tag的包拿掉tag部分丢给网卡,也会给网卡的包打上tag转发走;Trunk模式的话要看包带不带tag,不带的话就打上默认的vlan id,带的话就直接转发走,不动tag部分;还有一个General,记不清了也没用过。Access/Trunk/General似乎是Cisco发明(?)的叫法,IEEE里面就叫tagged和untagged.

2. 两个口都能工作(FB下测试过,Linux估计也是吧),实际上走的都是eth0的网线

3. 从eth0.5出去的包都会打上5的标签,同时,打5标签的包也都会进入eth0.5

Regards.

Afa Cheng

Disclaimer:

This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message, which arise as a result of e-mail transmission. If verification is required please request a hard-copy version.

Wizard

unread,
Sep 20, 2014, 10:00:24 PM9/20/14
to shlug
多谢答复。

昨天问了个朋友,说如果机器卡上配了vlan 5, 但是交换机上配了vlan 6,好像不一定能工作。

然后我有好奇一下,那这样的话在linux内部能模拟一个带vlan功能的switch么?
比如建立几个有vlan的虚拟网口,然后把虚拟网口加入到一个bridge中?

Alpha Cheng

unread,
Sep 20, 2014, 10:30:11 PM9/20/14
to sh...@googlegroups.com

2014-09-20 22:00 GMT-04:00 Wizard <wizard...@gmail.com>:
昨天问了个朋友,说如果机器卡上配了vlan 5, 但是交换机上配了vlan 6,好像不一定能工作。

​交换机端口如果是Trunk Mode的话可以转发走,转发的包就带vlan 5的标签​,如果是Access Mode的话这个包会被丢弃

然后我有好奇一下,那这样的话在linux内部能模拟一个带vlan功能的switch么?
比如建立几个有vlan的虚拟网口,然后把虚拟网口加入到一个bridge中?

我在FreeBSD下这么搞过,不过用的
不是
bridge,是ipnat的转发​,做访问控制的,那Linux
理论上​也可以


Regards.

Afa.L Cheng

Wizard

unread,
Sep 21, 2014, 11:13:45 AM9/21/14
to shlug
多谢, 我再研究研究。
Reply all
Reply to author
Forward
0 new messages