[Tiếng Việt bên dưới]
With a firewall, you can open ports temporarily or permanently. Temporary rules are deleted upon system reboot. If you wish to open ports temporarily, you can use the following commands (the port will be closed if the system is rebooted):
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=443/tcp
To open ports permanently, use these commands:
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=443/tcp
The "--permanent" option ensures rules persist even after system restarts. Next, you'll need to reload FirewallD for the changes to take effect. To reload FirewallD, use this command:
firewall-cmd --reload
Viewing Rules
After adding rules, you can verify their successful addition by running the following command:
firewall-cmd --permanent --zone=public --list-ports
Removing Rules
If you want to remove added rules, you can use the following commands:
firewall-cmd --permanent --zone=public --remove-port=80/tcp
firewall-cmd --permanent --zone=public --remove-port=443/tcp
Next, execute the following command to apply the changes:
firewall-cmd --reload Conclusion
[Tiếng Việt] Hướng dẫn mở Port 80 và 443 trong Firewall
Sử dụng tường lửa, bạn có thể mở port tạm thời hoặc vĩnh viễn. Các rule tạm thời sẽ bị xóa sau khi khởi động lại hệ thống.
- Nếu muốn mở bọn tạm thời các bạn dùng lệnh sau (Port sẽ bị đóng nếu khởi động lại hệ thống):
firewall-cmd --zone=public --add-port=80/tcp
firewall-cmd --zone=public --add-port=443/tcp
- Để mở port vĩnh viến các bạn dùng lệnh sau:
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=443/tcp
Tùy chọn –permanent đảm bảo các rule vẫn được áp dụng kể cả khi khởi động lại hệ thống. Tiếp theo, các bạn sẽ cần phải reload lại FirewallD để thay đổi có hiệu lực. Để reload FirewallD các bạn sử dụng lệnh sau:
firewall-cmd --reload
Xem các rule
Sau khi thêm các rule, bạn có thể xác minh xem rule đã được thêm thành công hay chưa bằng cách chạy lệnh sau.
firewall-cmd --permanent --zone=public --list-ports
Xóa rule
Nếu bạn muốn xoá rule đã thêm các bạn có thể sử dụng lệnh như sau:
firewall-cmd --permanent --zone=public --remove-port=80/tcp
firewall-cmd --permanent --zone=public --remove-port=443/tcp
Tiếp theo, chạy lệnh sau để áp dụng các thay đổi:
firewall-cmd --reload