连接 0.0.0.0/32 发生了什么

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 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

目录
相关文章
|
7月前
|
网络协议 算法 Linux
服务端如何准备连接
【4月更文挑战第1天】服务端创建套接字涉及`socket()`函数。
|
弹性计算 安全 关系型数据库
介绍两种连接方式
介绍两种连接方式
181 1
|
SQL 关系型数据库 MySQL
|
弹性计算 Linux 网络安全
连接服务器的几种方式
本文撰写了3种连接阿里云服务器的方式
3623 2
连接服务器的几种方式
|
存储 缓存 网络协议
网络是这样连接的
网络是这样连接的
连接到网络
http://developer.android.youdaxue.com/training/basics/network-ops/connecting.html#security In order to perform network operations in your application, your manifest must include the following permissions:
320 0
|
机器人
BearyChat 连接服务
BearyChat 连接服务
118 0
|
关系型数据库 MySQL 数据库
mysql数据库(1):连接与断开服务器
mysql数据库(1):连接与断开服务器
186 0
mysql数据库(1):连接与断开服务器
|
SQL 存储 数据库
SYSPROCESSES 查看连接
原文:SYSPROCESSES 查看连接 SELECT at.text,sp.* FROM[Master].[dbo].[SYSPROCESSES] sp CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS at WHERE hostprocess=3616 以上语句作用: 查询客户端进程PID 为3616的程序,与此数据库的所有的连接数,每个连接最后执行的语句以及每个连接的详细信息。
1029 0