What is the role bind 0.0.0.0 is it?

Background Description :

  Today, we are looking at the contents of redis, to see my colleagues in the configuration file bind configured to listen to 0.0.0.0, does not understand what it meant to a query, the record in this case.

Explanation :

0.0.0.0 In the server environment, refers to all of ipv4 addresses on the server, if there are two ip 192.168.30.10 and 10.0.2.15 on the machine, redis in the configuration, if the configuration is listening on the address 0.0.0.0, so, by these two ip addresses we are able to reach this redis services. At the same time it, but also be able to access the local 127.0.0.1 redis access to services.

 

Test Verification:

1. bound to 0.0.0.0

[aiprd@hadoop1 redis]$ src/redis-server ./redis.conf 
[aiprd@hadoop1 redis]$ ps -ef | grep redis
aiprd     2422     1  0 11:53 ?        00:00:00 src/redis-server 0.0.0.0:6379
aiprd     2426  1401  0 11:53 pts/0    00:00:00 grep redis

 

2. Local ip address

[aiprd@hadoop1 redis]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:21:8b:7e brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
    inet6 fe80::a00:27ff:fe21:8b7e/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:9f:16:be brd ff:ff:ff:ff:ff:ff
    inet 192.168.30.10/24 brd 192.168.30.255 scope global eth1
    inet6 fe80::a00:27ff:fe9f:16be/64 scope link 
       valid_lft forever preferred_lft forever

Note: The local address 127.0.0.1, . 10.0 2.15 , . 192.168 30.10

3. 3 are accessible via ip address

[aiprd@hadoop1 redis]$ src/redis-cli
127.0.0.1:6379> auth yksSLR7AU#7G6Wz
OK
127.0.0.1:6379> exit
[aiprd@hadoop1 redis]$ 
[aiprd@hadoop1 redis]$ src/redis-cli -h 192.168.30.10
192.168.30.10:6379> auth yksSLR7AU#7G6Wz
OK
192.168.30.10:6379> exit
[aiprd@hadoop1 redis]$ src/redis-cli -h 10.0.2.15
10.0.2.15:6379> auth yksSLR7AU#7G6Wz
OK
10.0.2.15:6379> exit

Note: The three addresses is able to access.

 

4. bound to the address 192.168.30.10

[aiprd @ hadoop1 Redis] $ src / Redis server ./ redis.conf 
[aiprd @ hadoop1 Redis] $ ps -ef | grip Redis | grip -v grip 
aiprd      2434      1   0  11 : 57 ?        00 : 00 : 00 src / Redis server 192.168 . 30.10 : 6379

 

The above are accessed through address

[aiprd@hadoop1 redis]$ src/redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
[aiprd@hadoop1 redis]$ src/redis-cli -h 10.0.2.15
Could not connect to Redis at 10.0.2.15:6379: Connection refused
Could not connect to Redis at 10.0.2.15:6379: Connection refused
not connected> exit
[aiprd@hadoop1 redis]$ src/redis-cli -h 192.168.30.10
192.168.30.10:6379> auth yksSLR7AU#7G6Wz
OK
192.168.30.10:6379> 

NOTE: After the discovery is bound to 192.168.30.10, only this address is accessible, but then, access to 127.0.0.1 are not visit the.

 

Summary :

So: In summary, if it is bound to address 0.0.0.0 on all machines can access the service, if a particular ip it can only be bound to a specific ip can reach redis service.

 

Documentation Created : May 27, 2019 11:48:12

Guess you like

Origin www.cnblogs.com/chuanzhang053/p/10929903.html