问题原因:
[root@kubernetes ~]# docker run -i -t centos /bin/bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
解决方法:
1、编辑/usr/lib/sysctl.d/00-system.conf文件,添加IPv4转发:
[root@kubernetes ~]# vi /usr/lib/sysctl.d/00-system.conf
----------添加以下内容--------
net.ipv4.ip_forward=1
2、重启网络服务
[root@kubernetes ~]#systemctl restart network
3、重启docker容器
[root@kubernetes ~]# docker run -i -t centos /bin/bash
[root@2d593911faeb /]# ping www.baidu.com
PING www.a.shifen.com (111.13.100.91) 56(84) bytes of data.
64 bytes from 111.13.100.91 (111.13.100.91): icmp_seq=1 ttl=52 time=21.7 ms
64 bytes from 111.13.100.91 (111.13.100.91): icmp_seq=2 ttl=52 time=21.7 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 21.705/21.741/21.778/0.151 ms