如果我们想绑定外网,我们不能直接绑定公网,我们应该使用ifconfig命令:
root@iZj6cieuk3vo5t4ghf2ur2Z:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet a.b.c.d netmask 255.255.240.0 broadcast 172.31.175.255
inet6 fe80::216:3eff:fe01:2b9f prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:01:2b:9f txqueuelen 1000 (Ethernet)
RX packets 226405 bytes 72077054 (72.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 167597 bytes 67562446 (67.5 MB)
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 32070 bytes 2602960 (2.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 32070 bytes 2602960 (2.6 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
其中,eth0 中的 inet中 的 a.b.c.d就是我们真正应该监听的地址,这样我们从外网就可以正常访问了
en代表以太网卡,第二行中的inet代表网卡的ip地址,netmask代表子网掩码,broadcast代表广播地址,第三行的inet6代表网卡的ipv6地址
lo代表主机的回环地址,IP地址固定为127.0.0.1,子网掩码八位,表示本机