Linux Learning CentOS (29)--linux Network card Advanced command, IP alias and multiple network card binding method _linux

Source: Internet
Author: User
Tags aliases

This essay will explain in detail the Linux system's advanced command of the network card, IP alias, and the knowledge of multiple NIC bindings under Linux.

First, the Network card Advanced command

In a previous essay on the CentOS of Linux Learning (ix)--LINUX System network Environment configuration, detailed explanation of the Linux system under the network environment Configuration knowledge, we understand some of the network configuration of some basic commands. This will be supplemented by some advanced commands for network adapters under Linux systems.

①mii-tool command

Mii-tool command We can use to view the NIC status information, including whether the Ethernet connection is normal, what type of network card is used, etc.

[Root@xiaoluo ~]# mii-tool eth0
eth0:no autonegotiation, 100basetx-fd, link ok

We can see from the output information, the current Ethernet connection is normal, Ethernet speed is 100M per second, through this command we can see the bottom of the network card some information, when we are in the upper layer through ping, traceroute and other commands for network scheduling, if found that the network still can not connect unimpeded, You can use this command to see if there is a problem with the Ethernet connection.

②ethtool command

The Mii-tool command allows you to view some of the underlying information for the NIC, but if we want to see more detailed information about the NIC, we can use the Ethtool command, which lists all the information for the network card in detail.

[Root@xiaoluo ~]# ethtool eth0
Settings for eth0:
  supported ports: [TP]
  supported link modes:  10baset/h Alf 10baset/full 
              100baset/half 100baset/full 
              1000baset/full supported 
  frame pause
  use:no 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
  : Unknown
  Supports WAKE-ON:UMBG
  wake-on:d Current Message
  level:0x00000007 (7)
          DRV probe link
  Link Detected:yes

Including the network card support link rate, duplex mode and so on information can be found

If we want to check the driver information of the NIC, we can add the-i parameter after the Ethtool command, then we can display the driver information of the NIC.

[Root@xiaoluo ~]# ethtool-i eth0

driver:e1000
version:7.3.21-k8-napi
: firmware-version 
: 0000:00:03.0
supports-statistics:yes
supports-test:yes
supports-eeprom-access:yes
Supports-register-dump:yes
Supports-priv-flags:no

If we also need to check the current bottom of the network card work status information, you can add the-s parameter after the command

[Root@xiaoluo ~]# ethtool-s eth0 NIC statistics:rx_packets:3255 tx_packets:898 rx_bytes:477575 tx_bytes 
   : 2228309 rx_broadcast:2190 tx_broadcast:198 rx_multicast:0 tx_multicast:6 rx_errors:0 tx_dropped:0 multicast:0 collisions:0 rx_length_errors:0 rx_over_errors:0 rx_crc_errors:0 rame_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:263 tx_tcp_seg_failed:0 rx_flow_control_xon:0 Rx_flow_cont
   rol_xoff:0 tx_flow_control_xon:0 tx_flow_control_xoff:0 rx_long_byte_count:477575 rx_csum_offload_good:0 Rx_csum_offload_errors:0 alloc_rx_buff_failed:0 tx_smbus:0 rx_smbus:0 dropped_smbus:0

 

Including the number of packets sent by the network card, how many packets received to see the information.

So through the Mii-tool and ethtool These two commands, we can see the network card more low-level information and the physical information of the network card, etc., which may be convenient for us in the network scheduling

Second, IP alias

In a Linux system, we can configure multiple IP addresses on a single physical network card to implement functions like sub-interfaces, which we call IP aliases. Of course, on other operating systems, such as Windowns, Mac OS also supports the configuration of multiple IP addresses on a physical network card. For example, our Linux host as a DHCP server, it may have to allocate multiple IP addresses for different segments of the network, in the Linux system, we use IP alias to implement on a physical network card to configure multiple IP addresses.

"Note:" To use IP aliases to configure multiple IP addresses, we first need to turn off the NetworkManager service

On the CentOS or Rhel, will be enabled by default Nerworkmanager this service to the network card management, NetworkManager service is actually our operating system on the upper right of the two small computer icons, we can click on the graphical interface to specify which network card to use, But if we need to use an IP alias, we have to disable this service.

[Root@xiaoluo ~]# service NetworkManager stop
stopping networkmanager daemon:              [OK]//Stop our NetworkManager services, at this time We can see that the icon in the upper right-hand corner is gone.

[Root@xiaoluo ~]# chkconfig NetworkManager off//NetworkManager This service will boot up by default, so we set it to boot without booting

[Root@xiaoluo ~]# chkconfig--list | grep networkmanager
NetworkManager   0:off  1:off  2:off  3:off  4:off 5:off 6:off

After stopping the NetworkManager service we can use IP alias technology to configure multiple IP addresses, here we use the IP command, the command syntax format is as follows:

IP addr Add 172.25.215.40/24 dev Etho label eth0:0

Behind the eth0:0 says, we add an IP alias to eth0 this network card, the latter 0 means a name, the second alias can be written eth0:1

We first use the Ifconfig command to view our current network card information

 [Root@xiaoluo ~]# ifconfig
eth0   Link encap:ethernet hwaddr 08:00:27:d7:f8:84 inet addr:172.25.215.40 
     bcast:172.25.215.255 mask:255.255.255.0
     inet6 addr:fe80::a00:27ff:fed7:f884/64 scope:link up
     BROADCAST RUNNING multicast mtu:1500 metric:1
     RX packets:5801 errors:0 dropped:0 overruns:0 frame:0
     TX packets:2011 errors : 0 dropped:0 overruns:0 carrier:0
     collisions:0 txqueuelen:1000 
     RX bytes:819876 (800.6 KiB) TX bytes:2288399 (2.1 MiB)

lo    Link encap:local loopback 
     inet addr:127.0.0.1 mask:255.0.0.0 inet6
     ::: Addr Scope: Host up
     loopback RUNNING mtu:16436 metric:1
     RX packets:167 errors:0 dropped:0 overruns:0 frame:0
     TX packets:167 errors:0 dropped:0 overruns:0 carrier:0 collisions:0
     txqueuelen:0 
     RX bytes:14861 (14.5 KiB) TX bytes:14861 (14.5 KiB)

At this time our eth0 network card information will be displayed, we at this time through the IP command to eth0 add an IP alias

[Root@xiaoluo ~]# ip addr Add 172.25.215.31/24 dev eth0 label eth0:0 [Root@xiaoluo ~]# ifconfig eth0 Link encap:ethernet hwaddr 08:00:27:d7:f8:84 inet addr:172.25.215.40. 215.255 mask:255.255.255.0 Inet6 addr:fe80::a00:27ff:fed7:f884/64 scope:link up broadcast RUNNING MTU
     : 1500 metric:1 RX packets:6323 errors:0 dropped:0 overruns:0 TX packets:2011 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:914440 (893.0 KiB  ) TX bytes:2288399 (2.1 MiB) eth0:0 Link encap:ethernet hwaddr 08:00:27:d7:f8:84 inet addr:172.25.215.31 bcast:0.0.0.0 mask:255.255.255.0 up BROADC AST RUNNING multicast mtu:1500 metric:1 lo Link encap:local loopback inet addr:127.0.0.1 mask:255.0.0.0 T6 Addr::: 1/128 scope:host up loopback RUNNING mtu:16436 metric:1 RX packets:167 errors:0 dropped:0 overruns:0
     frame:0 TX packets:167 errors:0 dropped:0 overruns:0 carrier:0 Collisions:0 txqueuelen:0

 RX bytes:14861 (14.5 KiB) TX bytes:14861 (14.5 KiB)

We see that at this time we're out a piece of eth0:0 NIC, in fact, this is a eth0 network card IP alias, eth0 has two IP address, at this time we through the outside of the host ping these two IP addresses can ping, if we need to permanently save this information, we need in the/etc/sysconfig/ Network-scripts This file to create a name for ifcfg.eth0:0 Such a configuration file, what is the new IP alias, then create a file in this directory that corresponds to the name

[Root@xiaoluo ~]# cd/etc/sysconfig/network-scripts/

[root@xiaoluo network-scripts]# ls
ifcfg-eth0  IFDOWN-ISDN  ifup-aliases ifup-plusb   init.ipv6-global
ifcfg-lo   ifdown-post Ifup-post   net.hotplug
ifdown    ifdown-ppp   ifup-eth    ifup-ppp
IFDOWN-BNEP ifdown-routes ifup-ippp   ifup-routes  network-functions-ipv6  ifdown-eth Ifdown-sit   Ifup-ipv6   ifup-sit
ifdown-ippp ifdown-tunnel ifup-isdn
Ifdown-ipv6 ifup      ifup-plip   ifup-wireless

[Root@xiaoluo network-scripts]# VI ifcfg-eth0:0

device=eth0:0//Device name
ipaddr=172.25.215.31//IP address
prefix=24//prefix is 24, in fact, is equivalent to subnet mask has 24-bit
Onparent=yes/ /eth0:0 is a eth0 IP alias, yes is attached to eth0

By adding the above configuration file, our IP alias information can be permanently saved.

Three, multiple network card binding

Why use multiple NIC binding technology? We know that if the use of a network card to carry out data transmission, the speed is limited, even if the Gigabit network card, the speed is limited, we in order to improve the bandwidth, we can be more than a physical network card binding to a logical network card, so the speed of the network card is more than the rate of

Linux supports the binding of multiple physical network cards into a single logical network card, the binding logical network card can be used in parallel with all the physical network card, which can improve the bandwidth and network stability

After we have a number of physical network card binding to a logical network card, our IP address is required to be configured on this logical network card, rather than multiple physical network card

Linux supports three modes of network adapter bindings:

① mode 0: Balanced rotation Use this mode for multiple NIC bindings we can increase the bandwidth of the network, and its traffic is distributed evenly from the multiple network adapters.

② Mode 1: Active backup Use this mode for multiple network card binding we can improve the stability of the network, this mode will not improve the bandwidth of the network, each time only a single network card in the flow, only when this network card failure, bound together with other physical network card will work

③ mode 3: Broadcast mode This mode is generally not

If we want to increase the bandwidth of the network through multiple NIC bindings, choose Mode 0, and if you want to improve the stability of the network, select mode 1

Now let's look at how to configure the network card bindings

① NIC Binding we need to give our logical network card a name, usually the format for the bondn,n is the number of representatives, such as/DEV/BOND0,/dev/bond1

② then we need to create the configuration file for this logical network card in the/etc/sysconfig/network-scripts directory, such as:

/etc/sysconfig/network-scripts/ifc-bond0

[Root@xiaoluo network-scripts]# VI ifcfg-bond0

DEVICE=BOND0//device name
ipaddr=172.25.215.200//network card IP address
prefi X=24//Subnet mask 24 bit
onboot=yes//boot up Yes Bootproto=none/
boot protocol, because we are manually configured IP, so set to none, if it is dynamically allocated through DHCP, then set to Dhcp
   userctl=no//Close off user control
bonding_opts= "mode=1 miimon=5"/This is the main configuration of the bond network card, our bond card is actually based on a driver called bonding to configure, followed by configuration parameters, here we are using Mode 1 (active backup)

Because we want to use a multiple network card binding, so we add a card here, and then according to the prompts can add a new network card, we add a network card eth1, use Ifconfig to view:

[Root@xiaoluo network-scripts]# ifconfig bond0 Link encap:ethernet, hwaddr 00:00:00:00:00:00 inet.  bcast:172.25.215.255 mask:255.255.255.0 up broadcast RUNNING MASTER multicast mtu:1500 RX metric:1
     errors:0 dropped:0 overruns:0 frame:0 
     TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 RX bytes:0 (0.0 b) TX bytes:0
     (0.0 b) eth0 Link encap:ethernet hwaddr 08:00:27:d7:f8:84 inet6 addr:fe80::a00:27ff:fed7:f884/64
     Up broadcast RUNNING multicast mtu:1500 metric:1 RX packets:1285 errors:0 dropped:0 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:221706 (216.5 KiB) T X bytes:468 (468.0 b) eth1 Link encap:ethernet hwaddr 08:00:27:f4:7d:cc inet6 addr:fe80::a00:27ff:fef4:7dcc/64 S Cope:link up broadcast RUNNING multicast mtu:1500 metric:1 RX packets:1196 errors:0 dropped:0 Overruns: 0 frame:0 TX packets:95 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:216126 (211.0 KiB)  TX bytes:4806 (4.6 KiB) 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:16436 metric:1 RX packets:73 errors:0 dropped:0 overruns:0 frame:0 
     TX packets:73 errors:0 dropped:0 overruns:0 carrier:0 collisions:0

 RX bytes:6330 (6.1 KiB) TX bytes:6330 (6.1 KiB)

At this time we have two network card inside the computer, because we need to bind the two network cards to bond0 this logical network card, so we want to two network card configuration file add two statements:

MASTER=BOND0//Bind these two network cards to the BOND0 logical network card
Slave=yes//Slave=yes indicates that the two network adapters are attached to the BOND0 network card.

[Root@xiaoluo network-scripts]# VI ifcfg-eth0

device=eth0
hwaddr=08:00:27:d7:f8:84
type=ethernet
Uuid=2877e96e-6ddd-443b-a337-bafa7c77c6e5
onboot=no
nm_controlled=yes
bootproto=none
IPV6INIT= No
userctl=no
master=bond0
slave=yes

[Root@xiaoluo network-scripts]# vi ifcfg-eth1

DEVICE =eth1
bootproto=none
type=ethernet
peerdns=yes
ipv6init=no
onboot=no
HWADDR=08:00:27:F4:7D:CC
Master=bond0
Slave=yes

Before I said bond0 this NIC is actually configured with a driver called bonding, so we also need to add driver support for the BOND0 card, add this driver to/etc/modprobe.d/directory

[Root@xiaoluo network-scripts]# cd/etc/modprobe.d/

[root@xiaoluo modprobe.d]# ls
anaconda.conf  blacklist-visor.conf dist.conf   openfwwf.conf
blacklist.conf dist-alsa.conf    dist-oss.conf

This folder is down to the configuration file we need to drive the system, and we need to add a profile named bonding.conf to our bonding.

 [Root@xiaoluo modprobe.d]# VI bonding.conf

alias bond0 bonding

Once configured, we can start our bond0 network card via Ifup bond0.

[Root@xiaoluo network-scripts]# ifup bond0

Active connection state:activated
active connection path:/org/ Freedesktop/networkmanager/activeconnection/2

At this point we can use the Ifconfig command to view the current network card information:

[Root@xiaoluo network-scripts]# ifconfig bond0 Link encap:ethernet hwaddr 08:00:27:d7:f8:84 inet addr:172.25.215 bcast:172.25.215.255 mask:255.255.255.0 inet6 addr:fe80::a00:27ff:fed7:f884/64 scope:link up BROADCAST RUN
     NING MASTER multicast mtu:1500 metric:1 RX packets:8175 errors:0 dropped:0 overruns:0 frame:0 
     TX packets:117 errors:0 dropped:0 overruns:0 carrier:0 collisions:0  RX bytes:1417884 (1.3 MiB) TX bytes:6230 (6.0 KiB) eth0 Link encap:ethernet hwaddr 08:00:27:d7:f8:84 up broadcast
     RUNNING SLAVE multicast mtu:1500 metric:1 RX packets:4131 errors:0 dropped:0 overruns:0 frame:0 TX packets:22 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:711693 (695.0 KiB) TX bytes:1424 (1.3 KiB) eth1 Link encap:ethernet hwaddr 08:00:27:d7:f8:84 up broadcast RUNNING SLAVE MT
     u:1500 metric:1 RX packets:4044 errors:0 dropped:0 overruns:0 frame:0 TX Packets:95 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:706191 (689.6 KiB) TX byte s:4806 (4.6 KiB) 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:16436 metric:1 RX packets:81 errors:0 dropped:0 overruns:0 frame:0 
     TX packets:81 errors:0 dropped:0 overruns:0 carrier:0 collisions:0

 RX bytes:7226 (7.0 KiB) TX bytes:7226 (7.0 KiB)

At this point we ping our outside host and find that we can ping the

[Root@xiaoluo network-scripts]# ping 172.25.215.25
ping 172.25.215.25 (172.25.215.25) bytes of data.
Bytes from 172.25.215.25:icmp_seq=1 ttl=64 time=1.78 ms
bytes from 172.25.215.25:icmp_seq=2 ttl=64 time=1.10 Ms
Bytes from 172.25.215.25:icmp_seq=3 ttl=64 time=1.08 ms bytes from 172.25.215.25:icmp_seq=4 ttl=64 time=0.811 ms
   
    bytes from 172.25.215.25:icmp_seq=5 ttl=64 time=1.17 Ms
****************************************************** *****************************

   

This time our BOND0 network card has been configured successfully, it is composed of two physical network card, we can according to need, such as to improve network bandwidth or improve network stability to set BOND0 card binding mode can be

This essay explains some of the advanced commands of Linux network card and how to configure multiple IP addresses for a physical network card, which we call IP alias and, of course, our multiple NIC binding configuration!!!

Original link: http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/26/3100065.html

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.