Linux查询本机的内网IP和外网IP

2021/8/6 7:08:12

本文主要是介绍Linux查询本机的内网IP和外网IP,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

文章目录

    • 查询本机内网IP地址-ifconfig
      • 说明
    • 查询本机外网 IP 地址


查询本机内网IP地址-ifconfig

这里的eth0 的 inet 的值 172.14.116.91 即使内网ip。

[root@htlwk0001host ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.14.116.91  netmask 255.255.240.0  broadcast 172.14.127.255
        inet6 fe80::216:3eff:fe15:b7f3  prefixlen 64  scopeid 0x20<link>
        ether 00:16:3e:15:b7:f3  txqueuelen 1000  (Ethernet)
        RX packets 39472104  bytes 15521220904 (14.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38258459  bytes 15199147861 (14.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 17170519  bytes 9777458856 (9.1 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17170519  bytes 9777458856 (9.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
[root@htlwk0001host ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.14.116.91  netmask 255.255.240.0  broadcast 172.14.127.255
        inet6 fe80::216:3eff:fe15:b7f3  prefixlen 64  scopeid 0x20<link>
        ether 00:16:3e:15:b7:f3  txqueuelen 1000  (Ethernet)
        RX packets 39472688  bytes 15521320121 (14.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38259098  bytes 15199345538 (14.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

说明

  1. eth0:是指第一个物理网卡,具体叫光纤以太网接口卡,学名 Fiber Ethernet Adapter0。物理网卡这里指的是服务器上实际的网络接口设备,这里我服务器上双网卡,在系统中看到多个物理网卡则分别对应 eth0、eth1、eth2…,类似 Windows 装了好几个网卡,会显示本地连接1、本地连接2、本地连接3…
  2. lo:localhost 本地连接,127.0.0.1。
  3. en0:en0 是逻辑上的网络接口名,enx(x是一个数字,代表第几块网卡)是标准以太网接口,ent0 是物理设备,en0 是逻辑设备。查看网络接口信息时,假设看到三个网络接口,en0, en1, en2,但是只有 en1 的状态是 Available 的,说明目前只有这个口已经插上网线在使用,而其它的并没有在用。

查询本机外网 IP 地址

[root@htlwk0001host ~]# curl icanhazip.com
47.114.59.104


[root@htlwk0001host ~]# curl whatismyip.akamai.com
47.114.59.224[root@htlwk0001host ~]# 

[root@htlwk0001host ~]# curl tnx.nl/ip # 不行
127.0.0.1
--- after 12 years of service, tnx.nl/ip is no more. ---

[root@htlwk0001host ~]# curl myip.dnsomatic.com
47.114.59.224[root@htlwk0001host ~]# 

[root@htlwk0001host ~]# curl myip.ipip.net
当前 IP:47.114.59.104  来自于:中国 浙江 杭州  阿里云/电信/联通/移动/教育网

[root@htlwk0001host ~]# curl http://members.3322.org/dyndns/getip
47.114.59.104


[root@htlwk0001host ~]# curl ifconfig.me # 太慢了,不行
[root@htlwk0001host ~]# curl ident.me # 太慢了,不行

参考:https://blog.csdn.net/liaowenxiong/article/details/107688426



这篇关于Linux查询本机的内网IP和外网IP的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程