Linux under the shell to get the native IP address

Source: Internet
Author: User

Method Two
/sbin/ifconfig-a|grep inet|grep-v 127.0.0.1|grep-v Inet6|awk ' {print $} ' |tr-d ' addr: '

Method One
Get the native IP address and save it in a variable
arg=ifconfig eth0 |grep "inet addr"| cut -f 2 -d ":"|cut -f 1 -d " "
Ipaddr= < Span class= "Mrow" id= "mathjax-span-200" > a r g e c h o Ipadd

This assumes that your interface name is eth0, it is possible that your interface is not this, you need to change it.

Introduction to cut Parameters
-D is used to define the delimiter, which defaults to the TAB key.
-F indicates which field to get, 2 means the second field to be split with the delimiter specified by-D
Of course, you can also get a specific number of characters in each line of the file by cut, for example:
Cut-c3-5/etc/passwd
is the third to fifth character of each line in the output/etc/passwd file.
The-C and-f parameters can be followed by the following sub-parameters:
n Nth character or field
N-from the first character or field to the end of the file
N-m from Nth to first M characters or fields
-m character or field from first to second

Linux under the shell to get the native IP address

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.