The Docker container cannot resolve the domain name problem

  • 2020-06-19 12:05:39
  • OfStack

Found the problem

Recently, I deployed a project that required access to the external network within the project. Upload file to a cloud, but report directly to 1 unknown host , can not resolve the domain name, and then for a long time to find the reason, the following blah blah blah, to see a detailed solution:

The solution

Linux system does not turn on IP forwarding by default. To confirm the status of IP forwarding, you can view /proc file system and use the following command:


cat /proc/sys/net/ipv4/ip_forward
0

If the value in the above file is 0, IP forwarding is prohibited; If it is 1, the IP forwarding function has been turned on. To turn on the IP forwarding function, you can directly modify the above file:


echo 1 > /proc/sys/net/ipv4/ip_forward

Change the contents of the file from 0 to 1. Disabling IP forwarding changes the 1 to 0.

The above command does not save the changes to the IP forwarding configuration. The original value will be used the next time the system starts up. To permanently modify the IP forwarding, you need to modify the /etc/ sysctl.conf file and modify the value of the following line:


net.ipv4.ip_forward = 1

Changes can be made by restarting the system to take effect, or by executing the following command to take effect:


sysctl -p /etc/sysctl.conf

With the above configuration, IP forwarding is turned on permanently

conclusion


Related articles: