Linux下获取内网ip和公网ip

介绍

内网ip

执行ifconfig,其中172.17.110.104就是内网ip

[fyadmin@iZ2zebscni6kr6xwuv0o50Z conf]$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.110.104  netmask 255.255.240.0  broadcast 172.17.111.255
        ether 00:16:3e:30:2d:6d  txqueuelen 1000  (Ethernet)
        RX packets 2120866153  bytes 2539673016393 (2.3 TiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 592915885  bytes 1001667995843 (932.8 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
        loop  txqueuelen 1  (Local Loopback)
        RX packets 317194565  bytes 51302306314 (47.7 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 317194565  bytes 51302306314 (47.7 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

外网ip

执行curl ifconfig.me,其中39.106.179.67就是外网ip

curl ifconfig.me
39.106.179.67

参考博客

[1]https://blog.csdn.net/qq_31382921/article/details/53836523
内网ip
[2]https://blog.csdn.net/sforiz/article/details/6417017

你可能感兴趣的:(Linux)