Advanced commands for CentOS Nic, IP alias, and multi-nic binding

Source: Internet
Author: User

Advanced commands for CentOS Nic, IP alias, and multi-nic binding

This article will explain in detail the advanced Nic commands, IP aliases, and multi-nic binding knowledge in Linux.

I. Nic advanced commands

In the previous article, CentOS (9), the Network Environment configuration of the Linux system, explained in detail the network environment configuration of the Linux system, we learned some basic commands about network configuration. Here we will add some advanced commands for NICs in Linux.

Mii-tool command

The mii-tool command can be used to view the NIC status information, including whether the Ethernet connection is normal and which type of NIC is used.

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

We can see from the output that the current Ethernet connection is normal and the Ethernet speed is MB per second. Through this command, we can see some information at the underlying layer of the NIC, when we run ping, traceroute, and other commands on the upper layer to troubleshoot network errors, if we find that the network still cannot be connected smoothly, we can use this command to check whether the Ethernet connection is faulty.

Ethtool command

You can use the mii-tool command to view some underlying information of the NIC. However, if you want to view more detailed information about the NIC, you can use the ethtool command, it can list all the information of the network card in detail.

[root@xiaoluo ~]# ethtool eth0Settings 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 connection rate and duplex mode supported by the NIC.

If we want to view the driver information of the NIC, we can add the-I parameter after the ethtool command to display the driver information of the NIC.

[root@xiaoluo ~]# 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 you want to view the current underlying working status of the network adapter, you can add the-S parameter after the command.

[root@xiaoluo ~]# 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 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

Including the number of packets sent by the network card and the number of packets received by the network card.

Therefore, through the mii-tool and ethtool commands, we can see more underlying information of the NIC and physical information of the NIC, which may facilitate network troubleshooting.

Ii. IP alias

In Linux, We can configure multiple IP addresses on a physical network card to implement functions similar to sub-interfaces, which we call an IP alias. Of course, in other operating systems, such as windowns and mac OS, multiple IP addresses can be configured on one physical Nic. For example, a Linux host, as a DHCP server, may have to assign multiple IP addresses to different CIDR blocks. In a Linux system, we use the IP alias to configure multiple IP addresses on a physical network card.

Note :]To use an IP alias to configure multiple IP addresses, you must first disable the NetworkManager service.

In CentOS or RHEL, The NerworkManager service is enabled by default to manage the NIC. the NetworkManager service is actually the two icons on the top right of the operating system, you can click the one on the graphic interface to specify which Nic to use. However, if you need to use an IP alias, you must disable this service.

[Root @ xiaoluo ~] # Service NetworkManager stopStopping NetworkManager daemon: [OK] // stop our NetworkManager service. At this time, we can find that the icon in the upper right corner is missing [root @ xiaoluo ~] # Chkconfig NetworkManager off // the NetworkManager service will be started by default, so we will set it to boot not to start [root @ xiaoluo ~] # Chkconfig -- list | grep NetworkManagerNetworkManager 0: off 1: off 2: off 3: off 4: off 5: off 6: off

After the NetworkManager service is stopped, we can use the IP alias technology to configure multiple IP addresses. Here we useThe command syntax format is as follows:

Ip addr add 172.25.215.40/24 dev etho label eth0: 0The following eth0: 0 indicates that an IP alias is added to the eth0 Nic. The following 0 indicates the alias number, and the second one can be written as eth0: 1.

We first run the ifconfig command to view the information of our current Nic.

[root@xiaoluo ~]# 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: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)

In this case, the eth0 Nic information will be displayed. At this time, we use the ip command to add an IP alias to eth0.

[root@xiaoluo ~]# ip addr add 172.25.215.31/24 dev eth0 label eth0:0[root@xiaoluo ~]# 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 (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:1lo 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 time we have an eth0: 0 Nic, which is actually an IP alias of the eth0 Nic. There are two IP addresses on eth0, in this case, we can ping the two IP addresses through the external host. If we need to save this information permanently, we needIn the/etc/sysconfig/network-scripts file, create an ifcfg file. in a configuration file such as eth0: 0 and what is the new IP alias, create a file corresponding to the name in this directory.

[Root @ xiaoluo ~] # Cd/etc/sysconfig/network-scripts/[root @ xiaoluo 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-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 // The PREFIX is 24, which is actually equivalent to the subnet mask with 24-bit ONPARENT = yes // eth0: 0 is the IP alias of eth0, and yes indicates that it is attached to eth0

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

3. bind multiple NICs

Why do we need to use the multi-nic binding technology? We know that if we use a network card for network data transmission, the speed is limited, even if it is a gigabit network card, its speed is also limited, in order to increase the bandwidth, we can bind multiple physical NICs to a logical Nic, so that the NIC speed is the speed of multiple NICs.

Linux supports binding multiple physical NICs into one logical Nic. The bound logical Nic can be used in parallel to form all its physical NICs. In this way, the bandwidth and network stability can be improved.

After we bind multiple physical NICs to a logical Nic, our IP address must be configured on this Nic, instead of multiple physical NICs.

In Linux, three Nic binding modes are supported:

① Mode 0:When balancing the round training mode to bind multiple NICs, we can increase the network bandwidth. The traffic is evenly allocated from the bound multiple NICs.

② Mode 1:When active backup is used to bind multiple NICs, we can improve the network stability. This mode does not increase the bandwidth of the network, and only one Nic is driving traffic at a time, only when this Nic fails will other physical NICs bound together work

③ Mode 3:Broadcast mode is generally not used.

If you want to increase network bandwidth by binding too many NICs, select mode 0. If you want to improve network stability, select mode 1.

Next let's take a look at how to configure Nic binding

① After the NIC is bound, we need to give a name to our logical Nic. The format is bondn. n indicates the number, for example,/dev/bond0,/dev/bond1.

② Then we need to create the configuration file for the logical Nic in the/etc/sysconfig/network-scripts directory, for example:

/Etc/sysconfig/network-scripts/ifc-bond0

[Root @ xiaoluo network-scripts] # vi ifcfg-bond0DEVICE = bond0 // device name IPADDR = 172.25.215.200 // Nic IP address PREFIX = 24 // subnet mask 24-bit ONBOOT = yes // boot yesBOOTPROTO = none // startup protocol, because we manually configure the IP address, set it to none. If it is dynamically allocated through DHCP, set to dhcpUSERCTL = no // Disable User Control BONDING_OPTS = "mode = 1 miimon = 5 "//This is the most important configuration of the bond Nic. Our bond Nic is actually configured based on a driver called bonding, followed by the configuration parameters. Here we use mode 1 (active backup)

Because we need to bind multiple NICs, we can add another Nic here, and then add a new Nic as prompted. Here we will add a NIC eth1 and use ifconfig to check it:

[root@xiaoluo 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 Metric: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:Link 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) TX bytes:468 (468.0 b)eth1 Link encap:Ethernet HWaddr 08:00:27:F4:7D:CC inet6 addr: fe80::a00:27ff: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)

Now we have two NICs in our computer, because we need to bind these two NICs to the logical Nic bond0, therefore, we need to add two statements in the configuration file of the two NICs:

MASTER = bond0 // bind these two NICs to the logical Nic bond0. SLAVE = yes // SLAVE = yes indicates that these two NICs are attached to the NIC bond0.
[root@xiaoluo 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[root@xiaoluo network-scripts]# vi ifcfg-eth1DEVICE=eth1BOOTPROTO=noneTYPE=EthernetPEERDNS=yesIPV6INIT=noONBOOT=noUSERCTL=noHWADDR=08:00:27:f4:7d:ccMASTER=bond0SLAVE=yes

As mentioned before, the bond0 Nic is actually configured through a driver called bonding, so we also need to add driver support for the bond0 Nic and add the driver to/etc/modprobe. d/under this directory

[root@xiaoluo network-scripts]# cd /etc/modprobe.d/[root@xiaoluo modprobe.d]# lsanaconda.conf blacklist-visor.conf dist.conf openfwwf.confblacklist.conf dist-alsa.conf dist-oss.conf

This folder is all the driver configuration files required by our system. We need to add a configuration file named bonding. conf to our bonding.

[root@xiaoluo modprobe.d]# vi bonding.confalias bond0 bonding

After the configuration, we can use ifup bond0 to start our bond0 Nic.

[root@xiaoluo 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:

[root@xiaoluo network-scripts]# ifconfigbond0 Link encap:Ethernet HWaddr 08:00:27:D7:F8:84 inet addr:172.25.215.200 Bcast:172.25.215.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fed7:f884/64 Scope:Link UP BROADCAST RUNNING 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 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 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 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)

In this case, we ping the host outside us and find that the host can be pinged normally.

[root@xiaoluo network-scripts]# ping 172.25.215.25PING 172.25.215.25 (172.25.215.25) 56(84) bytes of data.64 bytes from 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 172.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***********************************************************************************

At this time, our bond0 Nic has been configured successfully. It consists of two physical NICs. We can, as needed, for example, you need to increase network bandwidth or improve network stability to set the bond0 Nic binding mode.

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.