Docker容器

CentOS7 docker容器映射出的端口只监听在ipv6上的解决办法

本文主要是介绍CentOS7 docker容器映射出的端口只监听在ipv6上的解决办法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

docker容器起来以后,查看端口监听情况,如下图:

[root@backup01 gcc-8.1.0]# ss -tnl
State       Recv-Q Send-Q                     Local Address:Port                                    Peer Address:Port              
LISTEN      0      100                            127.0.0.1:25                                                 *:*                  
LISTEN      0      128                                    *:3330                                               *:*                  
LISTEN      0      5                                      *:8911                                               *:*                  
LISTEN      0      100                                [::1]:25                                              [::]:*                  
LISTEN      0      128                                 [::]:3330                                            [::]:*                  
LISTEN      0      128                                 [::]:10051                                           [::]:*                  
LISTEN      0      128                                 [::]:33060                                           [::]:*                  
LISTEN      0      5                                   [::]:8911                                            [::]:*                  
LISTEN      0      128                                 [::]:80                                              [::]:*

端口10051,80,33060只监听在ipv6上,使用ipv4无法访问。

解决办法如下:

编辑/etc/default/grub,加入一行:

GRUB_CMDLINE_LINUX="ipv6.disable=1 ..."

保存后重新配置grub并重启服务器

# grub2-mkconfig -o /boot/grub2/grub.cfg

# reboot

重启后结果:

[root@backup01 ~]# ss -tnl
State       Recv-Q Send-Q                     Local Address:Port                                    Peer Address:Port              
LISTEN      0      128                                    *:3330                                               *:*                  
LISTEN      0      128                                    *:10051                                              *:*                  
LISTEN      0      128                                    *:33060                                              *:*                  
LISTEN      0      5                                      *:8911                                               *:*                  
LISTEN      0      128                                    *:80                                                 *:*                  
LISTEN      0      100                            127.0.0.1:25                                                 *:*

正常了。

这篇关于CentOS7 docker容器映射出的端口只监听在ipv6上的解决办法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!