Linux IP别名和多网卡绑定


Linux IP别名和多网卡绑定
 
㈠ 网卡高级命令
          www.2cto.com  
           ① mii-tool eth0:查看网卡状态
        
           ② ethtool查看网卡设置
           
              ethtool -i eth0:查看网卡的驱动程序
              ethtool eth0:查看网卡物理特性
              ethtool -S eth0:查看网卡底层状态
          
        ㈡ IP别名
        
         一张物理网卡上配置多个IP,实现类似子接口之类的功能,称为IP别名
         在linux作DHCP服务器向多网段分配不同IP或者linux作路由器等时可能需要在一个物理接口上配置多个IP地址  www.2cto.com  
         
         ⑴ step_1
         redhat缺省使用NetworkManager对网卡进行管理,但仅限最基本的功能
         若要实现IP别名或者多网卡绑定,需要将此禁用
[sql] 
[root@localhost ~]# service NetworkManager stop  
停止 NetworkManager 守护进程:                             [确定]  
[root@localhost ~]# chkconfig NetworkManager off  
[root@localhost ~]# service NetworkManager status  
NetworkManager is stopped  
 
         ⑵ step_2
[sql] 
[root@localhost ~]# ifconfig eth0  
eth0      Link encap:Ethernet  HWaddr 00:0C:29:5E:10:AB  
          inet addr:192.168.1.112  Bcast:255.255.255.255  Mask:255.255.255.0  
          UP BROADCAST RUNNING MULTICAST  MTU:576  Metric:1  
          RX packets:520 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:287 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:0  
          RX bytes:82430 (80.4 KiB)  TX bytes:35734 (34.8 KiB)  
  
[root@localhost ~]# ip addr add 192.168.1.200/24 dev eth0 label eth0:0  
  
[root@localhost ~]# ifconfig  
eth0      Link encap:Ethernet  HWaddr 00:0C:29:5E:10:AB  
          inet addr:192.168.1.112  Bcast:255.255.255.255  Mask:255.255.255.0  
          UP BROADCAST RUNNING MULTICAST  MTU:576  Metric:1  
          RX packets:700 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:395 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:0  
          RX bytes:105711 (103.2 KiB)  TX bytes:48168 (47.0 KiB)  
  
eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:5E:10:AB  
          inet addr:192.168.1.200  Bcast:0.0.0.0  Mask:255.255.255.0  
          UP BROADCAST RUNNING MULTICAST  MTU:576  Metric:1  
 
         如果想要永久性添加IP别名,则可以在/etc/sysconfig/network-scripts/下添加别名配置文件:  www.2cto.com  
         配置文件名:
                   ifcfg-eth0:0
               内容:
                   DEVICE=eth0:0
                   IPADDR=192.168.1.200
                   PREFIX=24  //子网掩码
                   ONPARENT=yes //依附关系
                   
                   
        
        ㈢ 多网卡绑定
        
        linux支持将多张物理网卡绑定为一张逻辑网卡,以此来提高带宽和稳定性
        绑定后的物理网卡不在直接使用
        IP配置在绑定后的逻辑网卡上
        wlan不能绑定
        网卡绑定模式:
          模式0:平衡轮询
            --提高带宽
          模式1:主动备份
            --增加稳定性,只使用一块网卡
          模式2:广播
            --一般不用
        绑定后的逻辑网卡命名为bondn,n为编号,如/dev/bond0、/dev/bond1
        
        如果两块网卡在不同路由器上,也就是在不同的网段,那么不能使用网卡绑定来提高带宽
        服务器如果有连接到不同网段的两个地址,那么客户端访问服务器的时候进行LB最简单的方法就是使用DNS进行负载均衡
        客户端通过域名访问服务器,DNS中将域名解析到指定服务器的两个网卡的IP地址上就行了
        
        ⑴ step_1
        
        创建逻辑网卡的配置文件:
        /eth/sysconfig/network-scripts/ifcfg-bond0
        
        DEVICE=bond0
        IPADDR=192.168.1.200
        PREFIX=24
        ONBOOT=yes
        BOOTPROTO=none
        USERCTL=no
        BONDING_OPTS="mode=0 miimon=50 "
        
        ⑵ step_2
        
        将每张网卡先停掉:ifdown eth0,eth1
        之后修改每个属于该逻辑网卡的物理网卡的配置文件:
        /etc/sysconfig/network-scripts/ifcfg-eth0
        
        DEVICE=eth0
        BOOTPROTO=none
        ONBOOT=yes
        MASTER=bond0
        SLAVE=yes
        USERCTL=no
        第二张网卡eth1照猫画虎
        
        ⑶ step_3
        
        添加驱动程序
        /etc/modprobe.d/bonding.conf
        
        alias bond0 bonding
        
        
        ⑷ step_4
        
        service network stop
        service network start
        ifup bond0
        watch -n 1 ifconfig
 

相关内容

    暂无相关文章