9 ways to view IP addresses in Linux

Source: Internet
Author: User


[Email protected] ~]# ifconfig

Eth0 Link encap:ethernet HWaddr da:de:be:41:89:18

inet addr:192.168.150.53 bcast:192.168.150.255 mask:255.255.255.0

Inet6 addr:fe80::d 8de:beff:fe41:8918/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:184255445 errors:0 dropped:0 overruns:0 frame:0

TX packets:51947 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:12701252470 (11.8 GiB) TX bytes:4422271 (4.2 MiB)

Interrupt:17


Method 1: Match inet addr This line, the 2nd paragraph is displayed with a colon delimiter, the 1th paragraph is displayed again as a space separator

[Email protected] ~]# ifconfig eth0 |grep ' inet addr ' |cut-d:-f2 |cut-d ""-f1

192.168.150.53

Method 2: Match inet addr This line; Replaces the string from the beginning to the addr: with NULL, replacing the string from bcast to end again with empty

[Email protected] ~]# ifconfig eth0 |grep ' inet addr ' |sed ' s/^.*addr://g ' |sed ' s/bcast.*$//g '

192.168.150.53

Method 3: Match inet addr this line; or a space as a delimiter, and then print the 4th column

[[email protected] ~]# ifconfig eth0 |grep ' inet addr ' |awk-f[: ""]+ ' {print $4} '

192.168.150.53

Method 4: Match inet addr this line; To: As a delimiter, print the 2nd column, and then print the first column

[[email protected] ~]# ifconfig eth0 |grep ' inet addr ' |awk-f: ' {print $} ' |awk ' {print $} '

192.168.150.53

Method 5:

[[email protected] ~]# ifconfig eth0|sed-nr ' 2s#^.*addr: (. *) Bcast.*$#\1#g ' P

192.168.150.53

Method 6:

[email protected] ~]# ifconfig eth0 |awk '/inet addr:/ {print $} ' |awk-f: ' {print $} '

192.168.150.53

Method 7:

[Email protected] ~]# ifconfig eth0 |awk '/inet addr:/ {print $} ' |awk-f: ' {print $} '

192.168.150.53

Method 8:

[[email protected] ~]# ifconfig eth0 |awk ' nr==2 {print $} ' |awk-f: ' {print $} '

192.168.150.53

Method 9:

[email protected] ~]# IP Add |awk-f ' [/]+ ' nr==8 {print $} '

192.168.150.53



This article is from the "M April Days" blog, please be sure to keep this source http://msiyuetian.blog.51cto.com/8637744/1733259

9 ways to view IP addresses in Linux

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.