Linux NIC advanced commands, IP aliases, and multi-NIC bindings

Source: Internet
Author: User
Tags aliases

This essay will explain in detail the Linux network Card Advanced command, IP alias and Linux under the multi-NIC binding knowledge

First, the Network card Advanced command

In a previous essay, the Linux Learning CentOS (ix)--LINUX System network environment configuration, detailed explained the Linux system under the network environment configuration and so on the knowledge, we have learned some basic commands about the network configuration. Some of the advanced commands for network cards in Linux systems are added here.

mii-tool command

Mii-tool command We can use to view the network card status information, including the Ethernet connection is normal, the use of which type of network card and so on

[Email protected] ~]# mii-tool eth0eth0:no autonegotiation, 100basetx-fd, link ok

We can see from the output information, the current Ethernet connection is normal, the rate of Ethernet is 100M per second, through this command we can see some information on the bottom of the network card, when we sometimes in the upper layer through ping, traceroute and other commands to network wrong, if found that the network is still unable to connect unimpeded, You can then use this command to see if there is an Ethernet connection problem.

ethtool command

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

[[email protected] ~]# Ethtool eth0settings for eth0:    supported ports: [TP]    supported link modes:   10baset/ha LF 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: Unknown    Supports WAKE-ON:UMBG    wake-on:d Current    message level:0x00000007 (7)                   DRV probe link    Link detected:yes

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

If we want to see the driver information of the network card, we can display the driver information of the NIC by adding the-I parameter after the Ethtool command.

[Email protected] ~]# ethtool-i eth0driver:e1000version:7.3.21-k8-napifirmware-version:bus-info: 0000:00:03.0supports-statistics:yessupports-test:yessupports-eeprom-access:yessupports-register-dump: Yessupports-priv-flags:no

If we still need to check the current underlying operating status information of the NIC, you can add the-s parameter after the command.

[[email protected] ~]# ethtool-s eth0nic 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_errors:0 tx_dropped:0 multicast:0 collisions:0 rx_length_errors:0 rx_over_errors:0 R x_crc_errors:0 rx_frame_errors:0 rx_no_buffer_count:0 rx_missed_errors:0 tx_aborted_errors:0 tx_c arrier_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_lo      ng_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_control_xoff:0 tx_flow_control_xon:0 tx_flow_control_xoff:0 Rx_long     _byte_count:477575rx_csum_offload_good:0 rx_csum_offload_errors:0 alloc_rx_buff_failed:0 tx_smbus:0 rx_smbus:0 Drop ped_smbus:0

This includes information such as how many packets are sent by the NIC, how many packets are received, and so on.

So through the two commands of Mii-tool and Ethtool, we can see the network card more underlying information and network card physical information and so on, which may provide us with the convenience of network scheduling

Second, IP aliases

In a Linux system, we can configure multiple IP addresses on a physical network card to implement sub-interface-like functions, 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 want to assign multiple IP addresses for different segments of the network, in the Linux system, we use IP aliases to configure multiple IP addresses on a physical network card.

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

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

[[Email protected] ~]# service NetworkManager stopstopping NetworkManager daemon:                            [  OK  ]//  To stop our NetworkManager service, we can find the icon in the upper right corner is missing [[email protected] ~]# chkconfig NetworkManager off// NetworkManager This service will boot up by default, so we set it to boot without booting [[email protected] ~]# Chkconfig--list | grep networkmanagernetworkmanager     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 IP This 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 Said, we give eth0 this nic add an IP alias, the back of that 0 means the name, the second alias can be written eth0:1

We start by ifconfig command to view the information of our current network card

[Email protected] ~]# ifconfigeth0      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 :  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:.: 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)

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

[[email protected] ~]# IP addr Add 172.25.215.31/24 dev eth0 label eth0:0[[email protected] ~]# Ifconfigeth0 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:6323 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:914440 (8    93.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 broadcast RUNNING multicast mtu:1500 metric:1lo Link encap:local Loopback inet addr:127.0.0.1 M ask:255.0.0.0 Inet6 Addr::: 1/128 scope:host up LOOPBACK RUNNING mtu:16436 metric:1 RX Packet s: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 saw, at this point, we came out a piece of eth0:0 Network card, in fact, this is a eth0 NIC IP alias, eth0 on the two IP address, at this time we through the outside of the host ping this two IP address can be ping through, if we need to permanently save this information, we need to /etc/ Sysconfig/network-scripts This file to create a name for ifcfg.eth0:0 Such a configuration file, the new IP alias is what, then in this directory to create a file corresponding to the name can be

[Email protected] ~]# cd/etc/sysconfig/network-scripts/[[email protected] network-scripts]# lsifcfg-eth0   IFDOWN-ISDN    ifup-aliases  ifup-plusb     init.ipv6-globalifcfg-lo     ifdown-post    IFUP-BNEP     Ifup-post      net.hotplugifdown       ifdown-ppp     ifup-eth      ifup-ppp       NETWORK-FUNCTIONSIFDOWN-BNEP  ifdown-routes  ifup-ippp     ifup-routes    network-functions-ipv6ifdown-eth   ifdown-sit     Ifup-ipv6     ifup-sitifdown-ippp  ifdown-tunnel  ifup-isdn     Ifup-tunnelifdown-ipv6  Ifup           ifup-plip     ifup-wireless[[email protected] network-scripts]# VI ifcfg-eth0:0device=eth0:0// Device name ipaddr=172.25.215.31//IP address
prefix=24//prefix is 24, in fact is equivalent to the subnet mask has 24 bits onparent=yes//eth0:0 is eth0 IP alias, yes is attached to eth0

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

Three, multi-nic binding

Why use multi-nic binding technology? We know that if the network data transmission using a card is limited speed, even the Gigabit network card, its speed is also limited, we in order to improve the bandwidth, we can bind a number of physical network cards into a logical network card, so that the speed of the network card is the rate of multiple network cards.

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

After we bind multiple physical network cards into a logical NIC, our IP addresses are required to be configured on this logical NIC, not multiple physical network cards

There are three modes of NIC bindings supported under Linux:

① mode 0: balance rotation Using this mode for multi-NIC binding we can increase the bandwidth of the network, which is distributed evenly from the bound multi-block NIC

② Mode 1: Active backup using this mode for multi-NIC binding we can improve the stability of the network, this mode does not increase the bandwidth of the network, each time only one network card in the flow, only when the NIC fails, Other physical NICs that are bound together will work

③ mode 3: broadcast mode This mode is generally not used

If we want to increase the bandwidth of the network through multi-NIC binding, select mode 0, if you want to improve the stability of the network, select mode 1

Let's take a look at how to configure the NIC bindings

① NIC After binding we need to give our logical NIC a name, usually in the format of Bondn,n represents the number, such as/DEV/BOND0,/dev/bond1

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

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

[[Email protected] network-scripts]# VI ifcfg-bond0device=bond0//device name IPADDR=172.25.215.200//network card IP address prefix=24//Sub Netmask 24-bit onboot=yes//boot Yesbootproto=none//Start protocol, because we are manually configured IP, so set to none, if it is dynamically assigned through DHCP, then set to Dhcpuserctl=no//Shut down user control B onding_opts= "mode=1 miimon=5"// This is the bond network card the most important configuration, our bond network card is actually based on a driver called bonding configured, followed by configuration parameters, here we use mode 1 (active backup) 

Because we want to use multi-nic binding, so we add a piece of network card here, then we can add a new network card according to the hint, we add a NIC eth1 here, use Ifconfig to see:

[[email protected] network-scripts]# ifconfigbond0 Link encap:ethernet HWaddr 00:00:00:00:00:00 inet addr:172.25.215.200 bcast:172.25.215.255 mask:255.255.255.0 up broadcast RUNNING MASTER multicast MTU:1500 Me          Tric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen: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 Scope:li NK up broadcast RUNNING multicast mtu:1500 metric:1 RX packets:1285 errors:0 dropped:0 overruns:0 Fram          e:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:221706 (216. 5 KiB) TX bytes:468 (468.0 b) eth1 Link encap:ethernet HWaddr 08:00:27:f4:7d:cc inet6 addr:fe80::a00:27f F:FEF4:7DCC/64 Scope: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 txqueuelen:0 RX bytes:6330 (6.1 KiB) TX bytes:6330 (6.1 KiB)

At this point in our computer there are two network cards, because we need to bind the two network cards to the BOND0 This logical network card, so we have two network cards in the configuration file to add two statements:

MASTER=BOND0//Bind the two NICs to the BOND0 on this logical NIC Slave=yes//Slave=yes means that the two NICs are attached to the BOND0 network card
[Email protected] network-scripts]# VI ifcfg-eth0device=eth0hwaddr=08:00:27:d7:f8:84type=ethernetuuid= 2877e96e-6ddd-443b-a337-bafa7c77c6e5onboot=nonm_controlled=yesbootproto=noneipv6init=nouserctl=nomaster= Bond0slave=yes[[email protected] network-scripts]# VI ifcfg-eth1device=eth1bootproto=nonetype=ethernetpeerdns= Yesipv6init=noonboot=nouserctl=nohwaddr=08:00:27:f4:7d:ccmaster=bond0slave=yes

Previously said Bond0 this NIC is actually configured by a driver called bonding, so we also need to add driver support for bond0 This NIC, add this driver to the/etc/modprobe.d/directory

[Email protected] network-scripts]# cd/etc/modprobe.d/[[email protected] modprobe.d]# lsanaconda.conf   blacklist-visor.conf  dist.conf      openfwwf.confblacklist.conf  dist-alsa.conf        dist-oss.conf

This folder is all the configuration files that our system needs to drive, and we need to add a configuration file named Bonding.conf to our bonding.

[Email protected] modprobe.d]# VI bonding.confalias bond0 bonding

When configured, we can start our bond0 network card via Ifup bond0

[Email protected] network-scripts]# ifup bond0active Connection state:activatedactive connection path:/org/ Freedesktop/networkmanager/activeconnection/2

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

[Email protected] network-scripts]# ifconfig
Bond0 Link encap:ethernet HWaddr 08:00:27:d7:f8:84 inet addr:172.25.215.200 bcast:172.25.215.255 mask:25 5.255.255.0 Inet6 addr:fe80::a00:27ff:fed7:f884/64 scope:link up broadcast RUNNING MASTER multicast MT u: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 txqueuelen: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 B Roadcast 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 multicast mtu: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 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:81 errors:0 dropped : 0 overruns:0 frame:0 TX packets:81 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:7226 (7.0 KiB) TX bytes:7226 (7.0 KiB)

At this point we ping the host outside the ping command, we can see that the normal ping through the

[[email protected] network-scripts]# ping 172.25.215.25PING 172.25.215.25 (172.25.215.25) (+) bytes of data.64 bytes fr Om 172.25.215.25:icmp_seq=1 ttl=64 time=1.78 ms64 bytes from 172.25.215.25:icmp_seq=2 ttl=64 time=1.10 ms64 bytes from 1 72.25.215.25:icmp_seq=3 ttl=64 time=1.08 ms64 bytes from 172.25.215.25:icmp_seq=4 ttl=64 time=0.811 ms64 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, for example, to improve network bandwidth or improve network stability to set the BOND0 NIC binding mode can be

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

Linux network card advanced commands, IP aliases, and multi-nic bindings

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.