[root@py ~]# mii-tool eth0 #查看网卡状态
eth0: negotiated 100baseTx-FD, link ok #物理连接是否ok,宽带.....
[root@py ~]# ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes [root@py ~]# ethtool -i eth0 driver: e1000 version: 7.3.21-k8-NAPI firmware-version: bus-info: 0000:02:01.0 supports-statistics: yes supports-test: yes supports-eeprom-access: yes supports-register-dump: yes supports-priv-flags: no [root@py ~]# ethtool -S eth0 NIC statistics: rx_packets: 463 tx_packets: 107 rx_bytes: 70460 tx_bytes: 10258 rx_broadcast: 0 tx_broadcast: 0 rx_multicast: 0 tx_multicast: 0 rx_errors: 0 tx_errors: 0 tx_dropped: 0 multicast: 0 collisions: 0 rx_length_errors: 0 rx_over_errors: 0 rx_crc_errors: 0 rx_frame_errors: 0 rx_no_buffer_count: 0 rx_missed_errors: 0 tx_aborted_errors: 0 tx_carrier_errors: 0 tx_fifo_errors: 0 tx_heartbeat_errors: 0 tx_window_errors: 0 tx_abort_late_coll: 0 tx_deferred_ok: 0 tx_single_coll_ok: 0 tx_multi_coll_ok: 0 tx_timeout_count: 0 tx_restart_queue: 0 rx_long_length_errors: 0 rx_short_length_errors: 0 rx_align_errors: 0 tx_tcp_seg_good: 0 tx_tcp_seg_failed: 0 rx_flow_control_xon: 0 rx_flow_control_xoff: 0 tx_flow_control_xon: 0 tx_flow_control_xoff: 0 rx_long_byte_count: 70460 rx_csum_offload_good: 193 rx_csum_offload_errors: 0 alloc_rx_buff_failed: 0 tx_smbus: 0 rx_smbus: 0 dropped_smbus: 0
centos或rhel系统默认会启用networkmanager对网卡管理,以方便用户使用,但是如果使用子接口需要禁用networkmanager
[root@py ~]# service NetworkManager stop
Stopping NetworkManager daemon: [ OK ]
[root@py ~]# chkconfig NetworkManager off
创建ip别名
[root@py ~]# ip addr add 192.168.1.200/24 dev eth0 label eth0:0 [root@py ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:73:C3:A9 inet addr:192.168.1.105 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe73:c3a9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:581 errors:0 dropped:0 overruns:0 frame:0 TX packets:125 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:78780 (76.9 KiB) TX bytes:11500 (11.2 KiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:73:C3:A9 inet addr:192.168.1.200 Bcast:0.0.0.0 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:35 errors:0 dropped:0 overruns:0 frame:0 TX packets:35 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1918 (1.8 KiB) TX bytes:1918 (1.8 KiB)
永久添加ip别名
如果需要永久添加ip别名,则可以在/etc/sysconfig/network-scripts/下添加别名配置文件:
配置文件名:ifcfg-eth0
内容:
DEVICE
IPADDR
PREFIX
ONPARENT
[root@py ~]# cd /etc/sysconfig/network-scripts/ [root@py network-scripts]# ls ifcfg-eth0 ifdown-ib ifdown-ppp ifup-aliases ifup-ipv6 ifup-ppp init.ipv6-global ifcfg-lo ifdown-ippp ifdown-routes ifup-bnep ifup-isdn ifup-routes net.hotplug ifdown ifdown-ipv6 ifdown-sit ifup-eth ifup-plip ifup-sit network-functions ifdown-bnep ifdown-isdn ifdown-tunnel ifup-ib ifup-plusb ifup-tunnel network-functions-ipv6 ifdown-eth ifdown-post ifup ifup-ippp ifup-post ifup-wireless [root@py network-scripts]# vim ifcfg-eth0:0 [root@py network-scripts]# ls ifcfg-eth0 ifdown-eth ifdown-post ifup ifup-ippp ifup-post ifup-wireless ifcfg-eth0:0 ifdown-ib ifdown-ppp ifup-aliases ifup-ipv6 ifup-ppp init.ipv6-global ifcfg-lo ifdown-ippp ifdown-routes ifup-bnep ifup-isdn ifup-routes net.hotplug ifdown ifdown-ipv6 ifdown-sit ifup-eth ifup-plip ifup-sit network-functions ifdown-bnep ifdown-isdn ifdown-tunnel ifup-ib ifup-plusb ifup-tunnel network-functions-ipv6 [root@py network-scripts]# cat ifcfg-eth0:0 DEVICE=eth0:0 IPADDR=192.168.1.200 PREFIX=24 ONPARENT=yes
多网卡绑定
Linux支持多块物理网卡绑定为一个逻辑网卡,绑定后的逻辑网卡可以并行使用组成其的所有物理网卡,通过这样的方式用以提高带宽以及稳定性,绑定后物理网卡不直接使用,ip地址配置在绑定后的逻辑网卡上。
linux支持以下网卡绑定模式:
--模式0、平衡轮训
--模式1、主动备份
--模式3、广播
网卡绑定配置
绑定后的逻辑网卡命名为bondn,n为编号,如/dev/bond0/、/dev/bond1
创建绑定网卡的配置文件:
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0 #设备名称 IPADDR=192.168.1.200 #地址 PREFIX=24 #前缀 掩码24 ONBOOT=yes #开机是否启动 BOOTPROTO=none #因为是手动配置ip地址,启动协议匹配为空 USERCTL=no #用户控制 BONDING_OPTS="mode=1 miimon=50" #模块 驱动 引号内容 参数
我这块儿卡主了,配置逻辑网卡的时候电脑没电了,bond0设置完生效了,本来准备配置逻辑网卡,但是只有一块网卡可以用,添加了一块进来,没起作用反复重启配置终于搞定了,得重新搞了
通过setup可以添加网卡配置文件
DEVICE=eth0 BOOTPROTO=none HWADDR=00:0c:29:73:c3:a9 ONBOOT=yes MASTER=bond0 #从属于bond0 SLAVE=yes UUID="8375ffd0-fa14-4154-aaa2-1e39c117e9c1" TYPE=Ethernet USERCTL=no
第二块也一样
然后bond网卡添加驱动支持
alias bond0 bonding #配置文件 告诉我们现在bond0这个设备所使用的的驱动是bonding
[root@py network-scripts]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:73:C3:A9 inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe73:c3a9/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6 errors:0 dropped:0 overruns:0 frame:0 TX packets:24 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:360 (360.0 b) TX bytes:1656 (1.6 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:73:C3:B3 inet addr:192.168.1.112 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe73:c3b3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1 errors:0 dropped:0 overruns:0 frame:0 TX packets:11 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:60 (60.0 b) TX bytes:758 (758.0 b) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:480 (480.0 b) TX bytes:480 (480.0 b) [root@py network-scripts]# vim ifcfg-bond0 [root@py network-scripts]# ls ifcfg-bond0 ifdown-ippp ifup ifup-plip init.ipv6-global ifcfg-eth0 ifdown-ipv6 ifup-aliases ifup-plusb net.hotplug ifcfg-eth1 ifdown-isdn ifup-bnep ifup-post network-functions ifcfg-lo ifdown-post ifup-eth ifup-ppp network-functions-ipv6 ifdown ifdown-ppp ifup-ib ifup-routes ifdown-bnep ifdown-routes ifup-ippp ifup-sit ifdown-eth ifdown-sit ifup-ipv6 ifup-tunnel ifdown-ib ifdown-tunnel ifup-isdn ifup-wireless [root@py network-scripts]# vim ifcfg-eth0 [root@py network-scripts]# vim ifcfg-eth1 [root@py network-scripts]# cd /etc/modprobe.d/ [root@py modprobe.d]# ls anaconda.conf dist-alsa.conf libcxgb3.conf mlx4.conf vmware-tools.conf blacklist.conf dist.conf libcxgb4.conf network.conf bonding.conf dist-oss.conf libmlx4.conf openfwwf.conf [root@py modprobe.d]# vim bonding.conf [root@py modprobe.d]# ifup bond0 ./network-functions: line 522: /sys/class/net/bond0/bonding/miimom: No such file or directory ./network-functions: line 522: /sys/class/net/bond0/bonding/miimom: No such file or directory ./network-functions: line 522: /sys/class/net/bond0/bonding/miimom: No such file or directory Determining if ip address 192.168.1.200 is already in use for device bond0... RTNETLINK answers: File exists Error adding address 192.168.1.200 for bond0. RTNETLINK answers: File exists [root@py modprobe.d]# ifdown eth0 [root@py modprobe.d]# ifdown eth1 [root@py modprobe.d]# service network restart Shutting down interface bond0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface bond0: ./network-functions: line 522: /sys/class/net/bond0/bonding/miimom: No such file or directory ./network-functions: line 522: /sys/class/net/bond0/bonding/miimom: No such file or directory Determining if ip address 192.168.1.200 is already in use for device bond0... [ OK ] [root@py modprobe.d]# ifconfig bond0 Link encap:Ethernet HWaddr 00:0C:29:73:C3:A9 inet addr:192.168.1.200 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe73:c3a9/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:18 errors:0 dropped:0 overruns:0 frame:0 TX packets:32 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1080 (1.0 KiB) TX bytes:2162 (2.1 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:73:C3:A9 #现在我们可以看到这块网卡已经属于bond0了 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:7 errors:0 dropped:0 overruns:0 frame:0 TX packets:54 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:420 (420.0 b) TX bytes:3672 (3.5 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:73:C3:A9 #同样属于bond0 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:19 errors:0 dropped:0 overruns:0 frame:0 TX packets:14 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1140 (1.1 KiB) TX bytes:974 (974.0 b) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)
从外部ping一下看看效果,这块儿我在虚拟机上做的,现在遇到问题从外面ping不通,目前bond0网卡的配置是这样的
[root@py modprobe.d]# ethtool bond0 Settings for bond0: Supported ports: [ ] Supported link modes: Not reported Supported pause frame use: No Supports auto-negotiation: No Advertised link modes: Not reported Advertised pause frame use: No Advertised auto-negotiation: No Speed: 1000Mb/s Duplex: Full Port: Other PHYAD: 0 Transceiver: internal Auto-negotiation: off Link detected: yes
[root@py modprobe.d]# ethtool -S bond0 no stats available [root@py modprobe.d]# ethtool -i bond0 driver: bonding version: 3.7.1 firmware-version: 2 bus-info: supports-statistics: no supports-test: no supports-eeprom-access: no supports-register-dump: no supports-priv-flags: no
虚拟机两个网卡设置桥接就通了,我去,汗....................................