WARNING: IPv4 forwarding is disabled. Networking will not work.

时间:2021-04-14 02:26:45

1:Test environment

[root@docker-node1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@docker-node1 ~]# uname -r
3.10.0-862.2.3.el7.x86_64
[root@docker-node1 ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"

2:WARNING

[root@docker-node1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@docker-node1 ~]# docker run -it -d --name rhel01 centos bash
WARNING: IPv4 forwarding is disabled. Networking will not work.
379dc7446fb41541fc8d9fd6786ba573c5b9e7a67f077e36eab5747a7bceff42

3:Solution

[root@docker-node1 ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
[root@docker-node1 ~]# cat /etc/sysctl.conf 
net.ipv4.ip_forward=1
[root@docker-node1 ~]# systemctl restart network.service 
[root@docker-node1 ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

4:Success

[root@docker-node1 ~]# docker run -it -d --name rhel01 centos bash
773cb6d6143c1d4b7e69236c04b18e3164b92048d7fe0d57aaa074dd6ad2e34c
[root@docker-node1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
773cb6d6143c        centos              "bash"              12 seconds ago      Up 12 seconds                           rhel01