Linux text musketeers matching NIC IP address big PK (CentOS 7 system)

Source: Internet
Author: User
Tags get ip egrep

Operation and maintenance engineers in the process of configuration often need to get the IP address of the target server network card, which way to get more convenient, bloggers today take everyone to use the Linux text Three Musketeers to obtain the IP address of the network card, and finally we will compare.


Lab Environment:

System: CentOS 7.2

Network card number: Dual NIC


Linux text The Three Musketeers grep

Get the IP address in the ifconfig output

Ifconfig | Egrep-o "\< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-1][0-9]|22[0-3]) \>. (\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \>\.) {2}\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4]) \> "

Get the IP address in the network card configuration file

Egrep-o "\< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-1][0-9]|22[0-3]) \>. (\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \>\.) {2}\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4]) \> "/etc/sysconfig/network-scripts/ifcfg-eth*

/etc/sysconfig/network-scripts/ifcfg-eth0:10.29.88.57

/etc/sysconfig/network-scripts/ifcfg-eth1:118.190.87.211

Advantages:

The matching rule is strong, can obtain the IP address in the ifconfig output, and can obtain the IP address in the network card configuration file, the matching rule does not need to make any changes.

Disadvantages:

Command lengthy, not easy to remember


the Three Musketeers of the Linux text sed

Get the IP address in the ifconfig output

Ifconfig | Sed-rn ' s/^.*inet (. *) net.*/\1/p '

Get the IP address in the network card configuration file

Sed-rn ' s/^.*ipaddr= (. *)/\1/p '/etc/sysconfig/network-scripts/ifcfg-eth*

Advantages:

Shorter command, easier memory

Disadvantages:

Generic not strong, get the network card configuration file IP address matching rules need to be adjusted large


Linux Text the Three Musketeers of awk

Get the IP address in the ifconfig output

Ifconfig | awk '/inet/{print} '

Get the IP address in the network card configuration file

Awk-f= '/ipaddr/{print $ '/etc/sysconfig/network-scripts/ifcfg-eth*

Advantages:

The shortest command, the most easy to remember

Disadvantages:

More general, the matching rules need to be adjusted to obtain the IP address in the NIC configuration file.


Get IP address use effect in ifconfig output

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/03/E3/wKiom1mir4iRa0J5AAEzJ16rs68887.png "title=" The Three Musketeers take Ip.png "alt=" Wkiom1mir4ira0j5aaezj16rs68887.png "/>

Get the IP address usage effect in the NIC configuration file

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/03/E3/wKiom1mit4rgPIVjAAB_WAcCPLY518.png "title=" Network adapter profile IP address gets the. png "alt=" Wkiom1mit4rgpivjaab_waccply518.png "/>

compared with the actual case, it is not difficult to find that the Three Musketeers of the Linux text, awk practicality and convenience are very strong (a small number of commands can handle complex text matching), so recommend the OPS engineer in the work more use awk, of course, please do not doubt, I'm not the official awk marketing staff. ^..)

This article is from the "Love Firewall" blog, be sure to keep this source http://183530300.blog.51cto.com/894387/1959780

Linux text musketeers matching NIC IP address big PK (CentOS 7 system)

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.