First, the phenomenon problem record
Environment for rhel7.5
Use Docker to build a big data environment, docker container suddenly can not connect to the external network, before can
The phenomenon is that the host can be pinged, the host can access the Internet, and docker containers can also communicate with each other, but docker containers cannot access the Internet
Two, online about 4 kinds of solutions
1. The forward is not set. Net.ipv4. ip_forward=1 is required
2.DNS Settings. If the IP address can be pinged but the domain name cannot be pinged, set DNS 8.8.8.8 or 114.114.114.114
3. Docker service is faulty. Restart docker service
4. Docker0 virtual bridge problem, rebuild the bridge
I tried to solve these four problems for several days. I was about to reinstall the system, but I refitted. Finally, I changed the default network segment of Docker0. It is possible that a user in the network has recently used a new address in section 172, and the conflict has inactivated my network
3. Modify the default steps of Docker0
1. Stop the window and delete Docker0
service docker stop
ip link set dev docker0 down
brctl delbr docker0
2. Change the default segment from 172.17.0.1 to 192.168.100.0 in the vi /etc/docker/daemon.json file
{
“registry-mirrors”:[ “https://ao8i8s13.mirror.aliyuncs.com”,”http://hub- mirror.c.163.com” ],
“live-restore”:true,
“BJP” : “192.168.100.1/24”
}
Restart the Docker service
service docker start
4. View the configuration
ifconfig docker0
Iv. Introduction to Docker Networking mode
Docker is a bridge by default. Create a virtual docker0 with the default network segment 172.17.0.1. The docker on the host uses NAT mode to bind dock0 to the network adapter of the host, which requires the host to set the forwarding flag net.ipv4.ip_forward=1
Check the command
sysctl -p
The command to write 1
echo 1 > /proc/sys/net/ipv4/ip_forward
Or use the vi
vi /etc/sysctl.conf
Container url
To start a container, add 1 to the last bit of 172.17.0.1 as the container’S IP address.
Docker can also use host networking, –network=host in this way, the container has no IP, the network is the same as the host
You can also network with macVLAN, a virtual network adapter, which simulates two network adapters on a machine connected to different network segments
Five, url type introduction
Ipv4 addresses are classified into A, B, C, D, and E. D and E have no host or network address for multicast or reserved
The first three types of private addresses are as follows, with categories 1 and 255 indicating the range of addresses available for this network and this network broadcast
Class A: 10.0.0.1-10.255.255.254 Mask 255.0.0.0 Class B: 172.16.0.1-172.31.255.254 Mask 255.255.0.0 Class C: 192.168.0.1-192.168.255.254 Subnet mask 255.255.255.0
When you enter the IP address, IP /24 indicates class C. If the IP address is 172, the IP address is /16, which is one to the digit of the mask