Redhat和RockyLinux和AnolisOS (firewalld防火墙的配置方法)

firewall-cmd

#启动防火墙
systemctl status firewalld
systemctl restart firewalld
systemctl enable firewalld

#开启 NAT 转发 
#查询:firewall-cmd --query-masquerade
firewall-cmd --permanent  --add-masquerade
firewall-cmd --reload

# Manger管理端添加
systemctl restart firewalld
systemctl enable firewalld
firewall-cmd --permanent  --add-masquerade
firewall-cmd --permanent --add-port=2376/tcp
firewall-cmd --permanent --add-port=2377/tcp
firewall-cmd --permanent --add-port=7946/tcp
firewall-cmd --permanent --add-port=7946/udp
firewall-cmd --permanent --add-port=4789/udp
firewall-cmd --permanent --add-port=80/tcp 
firewall-cmd --permanent --add-port=443/tcp 
firewall-cmd --permanent --add-port=22/tcp 
firewall-cmd --reload
firewall-cmd --list-ports
systemctl restart docker

# node 端添加
systemctl restart firewalld
systemctl enable firewalld
firewall-cmd --permanent  --add-masquerade
firewall-cmd --permanent --add-port=2376/tcp
firewall-cmd --permanent  --add-port=7946/tcp
firewall-cmd --permanent --add-port=7946/udp
firewall-cmd --permanent --add-port=4789/udp
firewall-cmd --permanent  --add-port=80/tcp
firewall-cmd --permanent  --add-port=443/tcp 
firewall-cmd --permanent  --add-port=22/tcp 
firewall-cmd --reload
firewall-cmd --list-ports
systemctl restart docker
  • 注册22端口不要忘记添加

ufw防火墙

ufw allow 22/tcp
ufw allow 2376/tcp
ufw allow 2377/tcp
ufw allow 7946/tcp
ufw allow 7946/udp
ufw allow 4789/udp
ufw reload
ufw status
ufw enable
systemctl restart docker

iptables防火墙

systemctl stop firewalld
systemctl disable firewalld
yum install iptables-services
systemctl start iptables
systemctl enable iptables

iptables -L INPUT --line-numbers 
systemctl restart docker