Linux learns CentOS of 29 Linux nic advanced commands IP aliases and how to bind multiple nic

  • 2020-05-13 04:14:18
  • OfStack

This essay will explain in detail the network card advanced command of the Linux system, the IP alias, and the multi-network card binding under Linux

1. Network card advanced command

In the previous essay, Linux learned the network environment configuration of CentOS(9)--Linux system, explained the network environment configuration of Linux system in detail, and we learned some basic commands about network configuration. Here we will add some advanced commands about network CARDS on the Linux system.

1) mii - tool command

The mii-tool command can be used to see the network card status information, including whether the Ethernet connection is normal, what type of network card is being used, and so on


[root@xiaoluo ~]# mii-tool eth0
eth0: no autonegotiation, 100baseTx-FD, link ok

We can see from the output of information, the current Ethernet connection is normal, the rate of Ethernet is 100 M per second, through this command, we can see network CARDS at the bottom of the 1 some information, sometimes when we are in the upper network through ping, traceroute command line mistake, if it is found that the network is unable to connect, then you can use this command to check whether there is something wrong with Ethernet connection

(2) ethtool command

The mii-tool command allows you to see some of the underlying information about your network card, but if you want to see more details about your network card, you can use the ethtool command, which lists all the details about your network card


[root@xiaoluo ~]# 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: 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 other information can be viewed

If we want to see the driver information of the network card, we can add the -i parameter after the ethtool command to display the driver information of the network card


[root@xiaoluo ~]# ethtool -i eth0

driver: e1000
version: 7.3.21-k8-NAPI
firmware-version: 
bus-info: 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 see the current underlying working status of the network card, we 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_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: 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: 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

Information including how many packets the network card sends and how many packets it receives can be seen.

So through the mii-tool and ethtool commands, we can see more of the underlying information of the network card and the physical information of the network card, etc., which may provide convenience for us in network troubleshooting

2. IP alias

In the Linux system, we can configure multiple IP addresses on a physical network card to achieve a function similar to the subinterface, which we call the IP alias. Of course, other operating systems, such as windowns and mac os, also support the configuration of multiple IP addresses on one physical network card. For example, if our Linux host serves as an DHCP server, it may assign multiple IP addresses for different network segments. In the Linux system, we configure multiple IP addresses on a physical network card through the IP alias.

[note:] to configure multiple IP addresses using the IP alias, we first need to turn off the NetworkManager service

Will be enabled by default in CentOS or RHEL NerworkManager this service to manage the network card, NetworkManager service is our operating system, the two little computer icon at the upper right we can click in a graphical interface that used to specify which network card, but if we need to use IP alias, it is necessary to disable this service


[root@xiaoluo ~]# service NetworkManager stop
Stopping NetworkManager daemon:              [ OK ]  //  Shut us down NetworkManager Service, we can see that the icon in the top right corner is missing 

[root@xiaoluo ~]# chkconfig NetworkManager off  //  NetworkManager The service will boot by default, so we set it to not boot 

[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 the IP alias technique to configure multiple IP addresses. Here we use the command ip. The syntax of the command is as follows:


ip addr add 172.25.215.40/24 dev etho label eth0:0

The following eth0:0 means that we add an IP alias to the eth0 network card. The following 0 means the alias number. The second alias name can be written as eth0:1

We first look at our current network card information through the ifconfig command


 [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: ::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 and we will add an IP alias to eth0 via the ip command


[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 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 (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 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: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 can see that at this point, we have a piece of eth0:0 network card, in fact, this is an IP alias of eth0 network card, eth0 has two IP addresses, at this point, we can access ping through the host ping outside the two IP addresses, if we need to permanently save this information, We need to create a configuration file with the name ifcfg.eth0:0 under the file /etc/sysconfig/ network-scripts. What is the new IP alias


[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-bnep   ifup-post   net.hotplug
ifdown    ifdown-ppp   ifup-eth   ifup-ppp    network-functions
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   ifup-tunnel
ifdown-ipv6 ifup      ifup-plip   ifup-wireless

[root@xiaoluo network-scripts]# vi ifcfg-eth0:0

DEVICE=eth0:0    //  The device name 
IPADDR=172.25.215.31  //  IP address 
PREFIX=24  //  The prefix is 24 , in fact, is equivalent to the subnet mask has 24 position 
ONPARENT=yes  //  eth0:0 is eth0 the IP Alias, yes Means attached to eth0

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

3. Multi-network card binding

Why use multi-network card binding technology? We know that if we use 1 network card for network data transmission, its speed is limited, even if it is a gigabit network card, its speed is limited, in order to improve the bandwidth, we can bind multiple physical network CARDS into 1 logical network card, so the network card rate is the rate of multiple network CARDS.

Linux supports the binding of multiple physical network CARDS into one logical network card. The bound logical network CARDS can use all the physical network CARDS in parallel, which can improve the bandwidth and network stability

After we bind multiple physical network CARDS into one logical network card, our IP address is required to be configured on this logical network card instead of multiple physical network CARDS

3 modes of network card binding are supported under Linux:

Mode 0: balanced rotation training using this mode to carry out multi-network card binding we can improve the network bandwidth, the traffic is from the binding of the multi-network card on the average distribution

Mode 1: active backup using this mode to carry out multi-network card binding we can improve the stability of the network, this mode will not improve the network bandwidth, only 1 piece of network card in the flow, only when this network card failure, binding in 1 other physical network card will work

Mode 3: broadcast mode 1 is generally not used

If we want to increase the network bandwidth through too many network card bindings, we choose mode 0, and if we want to improve the network stability, we choose mode 1

Let's take a look at how to configure network card binding

After the network card binding, we need to give our logical network card a name, usually in the form of bondn, n stands for the number, such as /dev/bond0, /dev/bond1

Then we need to create the configuration file of the logical network card in the directory /etc/sysconfig/ network-scripts, such as:

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


[root@xiaoluo network-scripts]# vi ifcfg-bond0

DEVICE=bond0  // The device name 
IPADDR=172.25.215.200  // The network card ip address 
PREFIX=24  // Subnet mask 24 position 
ONBOOT=yes  // Powered up yes
BOOTPROTO=none  // Start the protocol because we are manually configuring it IP , so it's set to none If yes DHCP Dynamic allocation, then set to dhcp
USERCTL=no  // Turn off user controls 
BONDING_OPTS="mode=1 miimon=5"  // This is a bond Network card the most important configuration, our bond Network card is actually based on 1 called bonding , followed by the configuration parameters, where we use the pattern 1( Take the initiative to backup )

Since we are going to use multi-network card binding, we will add another network card here, and then we can add a new network card according to the prompt. We will add a network card eth1 here, and use ifconfig to view 1:


[root@xiaoluo ~]# 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: Unknown
  Supports Wake-on: umbg
  Wake-on: d
  Current message level: 0x00000007 (7)
          drv probe link
  Link detected: yes
0

At this time, we have two network CARDS in the computer, because we need to bind these two network CARDS to the logical network card bond0, so we need to add two statements in the configuration files of the two network CARDS:

MASTER=bond0// bind the two network CARDS to the logical network card bond0
SLAVE=yes//SLAVE=yes means the two network CARDS are attached to the bond0 network card


[root@xiaoluo ~]# 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: Unknown
  Supports Wake-on: umbg
  Wake-on: d
  Current message level: 0x00000007 (7)
          drv probe link
  Link detected: yes
1

Said before bond0 the network adapter is configured by 1 is called bonding driver, so we need to add driver support bond0 this card, will add to the driver/etc/modprobe d/this directory


[root@xiaoluo ~]# 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: Unknown
  Supports Wake-on: umbg
  Wake-on: d
  Current message level: 0x00000007 (7)
          drv probe link
  Link detected: yes
2

Below this folder are all the configuration files that we need to drive for our system. At this time, we need to add a configuration file named bonding.conf to our bonding


 [root@xiaoluo modprobe.d]# vi bonding.conf

alias bond0 bonding

Once configured, we can activate our bond0 network card via ifup bond0


[root@xiaoluo ~]# 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: Unknown
  Supports Wake-on: umbg
  Wake-on: d
  Current message level: 0x00000007 (7)
          drv probe link
  Link detected: yes
4

At this point, we can use ifconfig command to view 1 current network card information:


[root@xiaoluo ~]# 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: Unknown
  Supports Wake-on: umbg
  Wake-on: d
  Current message level: 0x00000007 (7)
          drv probe link
  Link detected: yes
5

At this point, we used ping command to ping to our host outside, and found that ping can be connected normally


[root@xiaoluo ~]# 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: Unknown
  Supports Wake-on: umbg
  Wake-on: d
  Current message level: 0x00000007 (7)
          drv probe link
  Link detected: yes
6

At this time, our bond0 network card has been successfully configured. It is composed of two physical network CARDS. We can set the network card binding mode of bond0 according to our needs, for example, to improve network bandwidth or network stability

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

Links: the original http: / / www cnblogs. com xiaoluo501395377 / archive 2013/05/26/3100065. html


Related articles: