Chinaunix

标题: 单网卡 多ip 网桥设置 [打印本页]

作者: hinetworking    时间: 2013-07-12 12:22
标题: 单网卡 多ip 网桥设置
系统ubuntu  能做到吗?
配置单网卡多ip时:
auto eth0:0
iface eth0:0 inet static
    address 192.168.100.15
    netmask 255.255.128.0
    dns-nameservers 192.168.0.97


auto eth0:1
iface eth0:1 inet static
    address 10.10.100.1
    netmask 255.255.255.0
两个ip都能使用

我一旦配置网桥后:
auto eth0:0
iface eth0:0 inet static
    address 192.168.100.15
    netmask 255.255.128.0
    dns-nameservers 192.168.0.97

auto br1
iface br1 inet static
    bridge_ports eth0:1
    address 10.10.100.1
    netmask 255.255.255.0
服务器就不能ping通同网段的192.168.100.16了,
求教,单网卡如何配置多ip,如何配置网桥

作者: GB_juno    时间: 2013-07-13 14:10
先建网桥
auto br1
iface br1 inet static
        bridge_ports eth0
        bridge_stp off
再按照普通网卡的方式配置br1:0和br1:1。
auto br1:0
iface br1:0 inet static
    address 192.168.100.15
    netmask 255.255.128.0
    dns-nameservers 192.168.0.97
作者: hinetworking    时间: 2013-07-15 11:03
本帖最后由 hinetworking 于 2013-07-15 11:11 编辑

auto br0
iface br0 inet static
    bridge_ports eth0
    bridge_stp off

auto br0:0
iface br0:0 inet static
    address 192.168.100.15
    netmask 255.255.128.0
    dns-nameservers 192.168.0.97

auto br0:1
iface br0:1 inet static
    address 10.10.100.1
    netmask 255.255.255.0

我如上配置后,重启网络,得到如下信息:
Missing required variable: address
Missing required configuration variables for interface br0/inet.
Failed to bring up br0.
Cannot find device "br0:0"
Failed to bring up br0:0.
Cannot find device "br0:1"
Failed to bring up br0:1.


查看网络,如下:
eth0      Link encap:Ethernet  HWaddr e0:db:55:07:e1:70
          inet6 addr: fe80::e2db:55ff:fe07:e170/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:330716 errors:0 dropped:0 overruns:0 frame:0
          TX packets:249609 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:31917792 (31.9 MB)  TX bytes:25359245 (25.3 MB)
          Interrupt:35

eth0:0    Link encap:Ethernet  HWaddr e0:db:55:07:e1:70
          inet addr:192.168.100.15  Bcast:192.168.127.255  Mask:255.255.128.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:35

eth0:1    Link encap:Ethernet  HWaddr e0:db:55:07:e1:70
          inet addr:10.10.100.1  Bcast:10.10.100.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:35

网桥没有配置好,相当于多ip了


请问,该怎么修正?

回复 2# GB_juno


   
作者: GB_juno    时间: 2013-07-15 14:53
你把原来的eth0:0和eth0:1的相关配置删除..
先创建网桥br0.这个需要预装工具bridge_utils
apt-get install bridge_utils
创建网桥br0
brctl addbr br0
把网卡连到网桥
brctl addif br0 eth0
然后配置好br0:0和br0:1就可以了
作者: hinetworking    时间: 2013-07-15 16:45
我试了一下,还是不行,我觉得是网桥不支持这种虚拟网卡(eth0:0)的原因吧
多谢指导,也学到了不少
回复 4# GB_juno


   
作者: GB_juno    时间: 2013-07-15 18:06
我确定redhat是可以这样做的,因为我的服务器就这样弄的。ubuntu应该是差不多的吧
作者: hinetworking    时间: 2013-07-16 09:44
本帖最后由 hinetworking 于 2013-07-16 09:53 编辑

将配置全部写在interface中,
我这么设置过,之前失败,配置文件interface的内容和错误消息上次发给您短消息了
后来,照您的提示
先将eth0加入到网桥中
brctl addbr br0
brctl addif bro eth0
然后再在interface中配置br0:0和br0:1
auto br0:0
iface br0:0 inet static
    address 192.168.100.15
    netmask 255.255.128.0
    dns-nameservers 192.168.0.97

auto br0:1
iface br0:1 inet static
    address 10.10.100.1
    netmask 255.255.255.0
然后还是失败了,192那个网段ping不通了
回复 6# GB_juno


   
作者: GB_juno    时间: 2013-07-16 10:27
本帖最后由 GB_juno 于 2013-07-16 10:30 编辑

回复 7# hinetworking


哥们,之前没有收到你的短消息,我刚看了两遍..
你把eth0:0和eth0:1先ifdown一下,在配置文件里面只需要把br0配置。
  1. auto lo
  2. iface lo inet loopback

  3. auto eth0
  4. iface eth0 inet manual

  5. auto br0
  6. iface br0 inet static
  7.   bridge_ports eth0
  8.   bridge_stp off
  9.   bridge_fd 0
  10.   bridge_maxwait 0
复制代码
重启网络

  1. /etc/init.d/networking restart
复制代码
ifconfig看看有哪些网卡信息以及br0网桥在不在。
如果br0网桥起来了,使用ifconfig命令直接配置网桥br0:0和br0:1,当然这样的操作肯定是临时的,重启后消失
  1. sudo ifconfig br0:0 192.168.100.15 netmask 255.255.128.0 up
  2. sudo ifconfig br0:1 10.10.100.1 netmask 255.255.255.0 up
复制代码
先看看手动配置能不能通吧。
作者: hinetworking    时间: 2013-07-16 13:36
配置文件这么写的话,报错:
missing required variable:address
missing required configuration variable for interface br/inet
Failed to bring up br0

当然执行配置网桥br0:0 和 br0:1 命令的话,就提示:no such device
然后我手动加建立起br0

输入命令:
brctl addbr br0
brctl addif br0 eth0

再执行配置网桥br0:0和br0:1的命令,没有ping通


回复 8# GB_juno


   
作者: GB_juno    时间: 2013-07-16 14:20
直接用ifconfig配也不行..这个有点坑
网桥多IP就应该这样搞才对..我找台ubuntu试试。
作者: hinetworking    时间: 2013-07-16 16:20
   可以吗
回复 10# GB_juno


   
作者: GB_juno    时间: 2013-07-16 16:54
就按照我的方法做是可以的,实验过了,你看看附件,楼层贴图麻烦。

1.JPG (38.05 KB, 下载次数: 52)

ubuntu配置

ubuntu配置

2.JPG (0 Bytes, 下载次数: 46)

两个ip地址都能通

两个ip地址都能通

作者: GB_juno    时间: 2013-07-16 16:58
先建网桥

  1. brctl addbr br0
  2. brctl addif br0 eth0
复制代码
改配置文件,按照图1改
重启网络

  1. /etc/init.d/networking restart
复制代码
然后ifconfig就能看到3张虚拟网卡出现:br0、br0:0、br0:1
作者: hinetworking    时间: 2013-07-16 22:55
多谢GB_juno,我试试
GB_juno 发表于 2013-07-16 16:58
先建网桥改配置文件,按照图1改
重启网络然后ifconfig就能看到3张虚拟网卡出现:br0、br0:0、br0:1





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2