最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】CentOS中如何查看主机的内网IP和外网IP

CentOS crifan 6928浏览 0评论

折腾:

【记录】购买百度云服务:BCC云主机

期间,想要了解此处买到的百度的云服务器的CentOS中的内网IP和外网IP

再去搜:

centos 查看ip

参考:

CentOS 查看IP,端口 修改IP,打开端口生效 – lhj588 – 博客园

centos 7 查看内网ip和外网ip – CSDN博客

去试试:

[root@instance-jb4q99qd ~]# ifconfig | grep broadcast

        inet 192.168.0.4  netmask 255.255.240.0  broadcast 192.168.15.255

[root@instance-jb4q99qd ~]#

[root@instance-jb4q99qd ~]# ifconfig -a

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1400

        inet 192.168.0.4  netmask 255.255.240.0  broadcast 192.168.15.255

        inet6 fe80::f816:3eff:fe65:1b39  prefixlen 64  scopeid 0x20<link>

        ether fa:16:3e:65:1b:39  txqueuelen 1000  (Ethernet)

        RX packets 15232  bytes 22401678 (21.3 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 11971  bytes 3707501 (3.5 MiB)

        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 1  (Local Loopback)

        RX packets 6  bytes 518 (518.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 6  bytes 518 (518.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@instance-jb4q99qd ~]# curl ifconfig.me

106.12.26.141

另外,本地电脑直接打开:

What Is My IP Address? – ifconfig.me

也可以看到类似信息:

所以再去BCC主机中试试其他命令:

[root@instance-jb4q99qd ~]# curl ifconfig.me

106.12.26.141

[root@instance-jb4q99qd ~]# curl ifconfig.me/host

[root@instance-jb4q99qd ~]# curl ifconfig.me/ua

curl/7.29.0

[root@instance-jb4q99qd ~]#  curl ifconfig.me/port

43114

[root@instance-jb4q99qd ~]# curl ifconfig.me/lang

[root@instance-jb4q99qd ~]# curl ifconfig.me/mime

*/*

[root@instance-jb4q99qd ~]# curl ifconfig.me/all

ip_addr: 106.12.26.141

remote_host:

user_agent: curl/7.29.0

port: 48866

lang:

connection:

keep_alive:

encoding:

mime: */*

charset:

via:

forwarded:

[root@instance-jb4q99qd ~]# curl ifconfig.me/all.json

{“connection”:””,”ip_addr”:”106.12.26.141″,”lang”:””,”remote_host”:””,”user_agent”:”curl/7.29.0″,”charset”:””,”port”:”43124″,”via”:””,”forwarded”:””,”mime”:”*/*”,”keep_alive”:””,”encoding”:””}

[root@instance-jb4q99qd ~]# curl ifconfig.me/all.xml

<info>

  <charset></charset>

  <connection></connection>

  <encoding></encoding>

  <forwarded></forwarded>

  <ip_addr>106.12.26.141</ip_addr>

  <keep_alive></keep_alive>

  <lang></lang>

  <mime>*/*</mime>

  <port>48870</port>

  <remote_host></remote_host>

  <user_agent>curl/7.29.0</user_agent>

  <via></via>

</info>

[root@instance-jb4q99qd ~]#

【总结】

CentOS 7中查看当前主机:

  • 内网IP:

    • ifconfig -a

    • 输出结果中的broadcast的部分

    • 此处结果是:192.168.15.255

  • 外网IP:通过访问别的查询网站而获得当前的外网IP,比如:

    • curl ifconfig.me

    • 或:curl icanhazip.com

    • 此处结果是:106.12.26.141

转载请注明:在路上 » 【已解决】CentOS中如何查看主机的内网IP和外网IP

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.198 seconds, using 22.13MB memory