Mở iptables trên Docker Swarm

Mở iptables trên Docker Swarm

 

Để các container ở các VPS docker worker và Leader có thể thông được với nhau cần mở firewall, cụ thể mình dùng iptables

Nếu chưa cài iptables, tiến hành cài iptables trên Ubuntu.

apt-get install iptables-persistent

netfilter-persistent flush

Cài iptables trên centos​​ nếu chưa cài.

sudo yum install iptables-services

sudo systemctl start iptables

sudo systemctl start ip6tables

sudo systemctl enable iptables

sudo systemctl enable ip6tables

sudo systemctl status iptables

sudo systemctl status ip6tables

Mở các port

iptables -A INPUT -p tcp --dport 22 -j ACCEPT

iptables -A INPUT -p tcp --dport 2376 -j ACCEPT

iptables -A INPUT -p tcp --dport 2377 -j ACCEPT

iptables -A INPUT -p tcp --dport 7946 -j ACCEPT

iptables -A INPUT -p udp --dport 7946 -j ACCEPT

iptables -A INPUT -p udp --dport 4789 -j ACCEPT

Để lưu vĩnh viễn các rule, các rule vẫn hoạt động sau khi khởi động lại máy chủ.

nano /etc/iptables/rules.v4

Add dòng sau trên tất cả các node:

-A INPUT -p tcp --dport 22 -j ACCEPT

-A INPUT -p tcp --dport 2376 -j ACCEPT

-A INPUT -p tcp --dport 2377 -j ACCEPT

-A INPUT -p tcp --dport 7946 -j ACCEPT

-A INPUT -p udp --dport 7946 -j ACCEPT

-A INPUT -p udp --dport 4789 -j ACCEPT

Sau đó khởi động lại iptables

netfilter-persistent save

sudo systemctl restart docker

 

Chúc các bạn thành công.

Tham khảo:

https://www.digitalocean.com/community/tutorials/how-to-configure-the-linux-firewall-for-docker-swarm-on-ubuntu-16-04

BÀI VIẾT CÙNG CHUYÊN MỤC

BACKUP DỮ LIỆU LỚN TỪ LINUX UBUNTU 24.04 LTS LÊN GOOGLE DRIVE AN TOÀN, TỐI ƯU BĂNG THÔNG
BACKUP DỮ LIỆU LỚN TỪ LINUX UBUNTU 24.04 LTS LÊN ...

BACKUP DỮ LIỆU LỚN TỪ LINUX UBUNTU 24.04 LTS LÊN GOOGLE DRIVE AN TOÀN, TỐI ƯU ...

Top 5 hệ thống LMS tốt nhất năm 2026 – Giải pháp quản lý học tập hiện đại cho trường học và doanh nghiệp
Top 5 hệ thống LMS tốt nhất năm 2026 – Giải pháp quản ...

Top 5 hệ thống LMS tốt nhất năm 2026 – Giải pháp quản lý học tập hiện đại cho ...

Hướng dẫn cấu hình SSL Let's Encrypt nhiều Website IIS bằng Win-ACME (Windows Server 2025)
Hướng dẫn cấu hình SSL Let's Encrypt nhiều Website IIS ...

Hướng dẫn cấu hình SSL Let's Encrypt nhiều Website IIS bằng Win-ACME (Windows ...

Hướng Dẫn Sửa Lỗi Không Extend Được Ổ C Trên Windows Server 2025 Do Vướng Phân Vùng Recovery
Hướng Dẫn Sửa Lỗi Không Extend Được Ổ C Trên Windows ...

Hướng Dẫn Sửa Lỗi Không Extend Được Ổ C Trên Windows Server 2025 Do Vướng Phân ...

Cảnh Báo Đỏ: Chiến Dịch FortiBleed Rò Rỉ Hàng Chục Nghìn Thông Tin Quản Trị Tường Lửa Fortinet
Cảnh Báo Đỏ: Chiến Dịch FortiBleed Rò Rỉ Hàng Chục ...

Cảnh Báo Đỏ: Chiến Dịch FortiBleed Rò Rỉ Hàng Chục Nghìn Thông Tin Quản Trị ...