Linux command line to get IP address __linux

Source: Internet
Author: User
Tags get ip

/sbin/ifconfig | Grep-a1 ' ^eth1 ' | grep ' inet addr: ' | Awk-f: ' {print $} ' | awk ' {print $} ' | Grep-e ' ^10\.| ^172\.| ^192\. ' | Head-n1

Analysis of each parameter

/sbin/ifconfig display information for all IP addresses

Grep-a1 ' ^eth1 ' filters out two lines that start with eht1

grep ' inet addr: ' In the information selected in the last step of the race, further races are selected to inet addr:

Awk-f: ' {print $} ' to: Print the second field for the split symbol, inet addr:10.12.193.226 bcast:10.12.193.255 mask:255.255.255.0, where the first field is inet add R: The second one is

10.12.193.226 Bcast

awk ' {print '} ' continues to filter further in the information from the previous step, where the default is to use a space as a separator, and to output the first field 10.12.193.226

Grep-e ' ^10\.| ^172\.|  ^192\. ' This is to filter the IP address that starts with 10, 172, 192, | This is or is meant to be,------------This parameter indicates that the regular expression

HEAD-N1 Output First line

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.