Several methods of IP address taking in Linux system

Source: Internet
Author: User

the method of taking the line of IP address in Linux system:
(1), ifconfig eth0 | grep "inet Addr"
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0
Note: grep filters the contents of the string containing "inet addr"
(2), ifconfig eth0 | Sed-n ' 2p '
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0
Note: sed-n ' 2p ' where-n parameter means "cancel default printing", 2p means "Print line 2nd"
(3), ifconfig eth0 | Sed-n '/inet addr/p '
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0
(4), ifconfig eth0 | Sed-n '/bcast/p '
inet addr:10.57.36.112 bcast:10.57.36.255 mask:255.255.255.0

several ways to take IP addresses from Linux systems:
(1), ifconfig eth0 | grep "inet addr" | Awk-f ":" ' {print $} ' | awk ' {print '} '
10.57.36.112
(2), ifconfig eth0 | grep "inet addr" | Sed ' s#^.*addr:# #g ' | Sed ' s#. bc.*$# #g '
10.57.36.112
(3), ifconfig eth0 | grep "inet addr" | Cut-d:-f2| Cut-d ""-f1
10.57.36.112
(4), ifconfig eth0 | grep "inet addr" | Awk-f "[:]+" ' {Print $4} '
10.57.36.112
Note: The method which takes the line of IP address can use one of the above 4 methods, then filter, replace or intercept to obtain ip!

This article is from the "Bruce_tan" blog, make sure to keep this source http://380281.blog.51cto.com/370281/1758063

Several ways to take IP addresses from Linux systems

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.