连接 0.0.0.0/32 发生了什么

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 Tair(兼容Redis),内存型 2GB
简介: 根据RFC 3330, 1700 的描述, 0.0.0.0/32 可以用作当前网络的源地址。 0.0.0.0/8 - Addresses in this block refer to source hosts on "this" network. Address 0.0.0.0/32

根据RFC 3330, 1700 的描述, 0.0.0.0/32 可以用作当前网络的源地址。

0.0.0.0/8 - Addresses in this block refer to source hosts on "this" network.  
Address 0.0.0.0/32 may be used as a source address for this host on this network; 
other addresses within 0.0.0.0/8 may be used to refer to specified hosts on this network.
[RFC1700, page 4].

0.0.0.0/32 作为目标地址使用时,与127.0.0.1含义一样。
但是0.0.0.0还有更多的含义,如下

IP address numbers in Internet Protocol (IP) version 4 (IPv4) range from 0.0.0.0 up to 255.255.255.255. The IP address 0.0.0.0 has several special meanings on computer networks. It cannot be used as a general-purpose device address, however.

IPv6 networks have a similar concept of an all-zeros network address.

0.0.0.0 on Clients

PCs and other client devices normally show an address of 0.0.0.0 when they are not connected to a TCP/IP network. A device may give itself this address by default whenever they are offline. It may also be automatically assigned by DHCP in case of address assignment failures.  When set with this address, a device cannot communicate with any other devices on that network over IP.

0.0.0.0 can also theoretically set as a device's network (subnet) mask rather than its IP address. However, a subnet mask with this value has no practical purpose. Both the IP address and network maskare typically assigned as 0.0.0.0 on a client together.  

Software Application and Server Uses of 0.0.0.0
Some devices, particularly network servers, possess more than one IP network interface. TCP/IP software applications use 0.0.0.0 as a programming technique to monitor network traffic across all of the IP addresses currently assigned to the interfaces on that multi-homed device.

While connected computers do not use this address, messages carried over IP sometimes include 0.0.0.0 inside the protocol header when the source of the message is unknown.

The Use of 0.0.0.0 vs. 127.0.0.1 on Local Networks

Students of computer networks sometimes confuse the usages of 0.0.0.0 and 127.0.0.1 on IP networks. Whereas 0.0.0.0 has several defined uses as described above, 127.0.0.1 has the one very specific purpose of allowing a device to send messages to itself.

Troubleshooting IP Address Problems with 0.0.0.0

If a computer is properly configured for TCP/IP networking yet still shows 0.0.0.0 for an address, try the following to troubleshoot this problem and obtain a valid address:

On networks with dynamic address asssignment support, release and renew the computer's IP address. Failures with DHCP assignment can be intermittent or persistent. If the failures persist, troubleshoot the DHCP server configuration: Common causes of failure include having no available addresses in the DHCP pool.
For networks that require static IP addressing, configure a valid IP address on the computer.

0.0.0.0/32 可以用来表示当前网络,与0.0.0.0建立连接,实际上是与回环地址建立连接。

如下

# ping 0.0.0.0
PING 0.0.0.0 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.033 ms

如果把回环地址shutdown,连接0.0.0.0会不行.

# ifdown lo

$ psql -h 0.0.0.0
psql: could not connect to server: Connection timed out
        Is the server running on host "0.0.0.0" and accepting
        TCP/IP connections on port 1921?

# ping 0.0.0.0
PING 0.0.0.0 (127.0.0.1) 56(84) bytes of data.
^C
--- 0.0.0.0 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 1999ms

所以连接0.0.0.0匹配的PostgreSQL服务端的pg_hba.conf条目是127.0.0.1/32。而不是0.0.0.0/0 。

pg_hba.conf
host all all 127.0.0.1/32  trust

参考
https://www.rfc-editor.org/rfc/rfc1700.txt
https://www.rfc-editor.org/rfc/rfc3330.txt
http://compnetworking.about.com/od/workingwithipaddresses/g/0_0_0_0_ip-address.htm

目录
相关文章
|
存储 安全 API
C++ 17 新特性 C++ String View:了解C++ 17 std::string_view的使用场景
C++ 17 新特性 C++ String View:了解C++ 17 std::string_view的使用场景
591 2
Python使用ffmpeg下载m3u8拼接为视频
Python使用ffmpeg下载m3u8拼接为视频
|
人工智能 自然语言处理 算法
如何学习AIGC
【1月更文挑战第21天】如何学习AIGC
683 1
如何学习AIGC
|
12月前
|
存储 测试技术 Linux
【Docker项目实战】使用Docker部署Radicale日历和联系人应用
【10月更文挑战第4天】使用Docker部署Radicale日历和联系人应用
581 2
【Docker项目实战】使用Docker部署Radicale日历和联系人应用
|
Linux 网络安全
linux如何关闭防火墙
记住,关闭防火墙可能会降低系统安全性,请在真正需要的情况下关闭,并确保你在网络环境中采取其他安全措施。
531 0
|
网络安全 数据安全/隐私保护 Windows
vb实现一键自动填写密码登录ssh
不使用密钥登录ssh的情况下。在windows下dos窗口中远程ssh登录常用基本命令
1033 0
|
数据安全/隐私保护
Burpsuite系列 -- Intruder模块介绍
Burpsuite系列 -- Intruder模块介绍
413 0
Burpsuite系列 -- Intruder模块介绍
|
SQL 关系型数据库 MySQL
云时代,最好用的MySQL客户端工具推荐
本文完整对比了12种MySQL图形客户端(GUI)工具,从产品体验、功能完整度、云适配、计费模式、OS兼容性等多个角度进行评估与分析,给出推荐。下面产品推荐与整体得分图,读者可根据自己的实际情况选择。
2343 0
云时代,最好用的MySQL客户端工具推荐
|
搜索推荐 Java 开发工具
【Framework】🤡 速通 Android AOSP基础(下)
本文并非笔者亲身实践,是借鉴了参考文献处几位大佬的文章总结得出。asop源码的下载费时,笔者没有编译扫写源码的需求,只是解BUG或了解底层机制时看看源码,SDK自带的android.jar和一些在线源码站点已经够用。环境搭建流程基本是一致的,遇到问题善用搜索引擎~
478 0