Firewall để kiểm soát truy cập theo policy trên cổng hoặc tên dịch vụ.
Centos 6 sử dụng IPtables, Centos 7 sử dụng Firewalld
Table of Contents
Mở cổng firewall trên Centos 7
Cách 1: mở theo số port tương ứng với từng dịch vụ
Ví dụ mở cổng cho webserver chạy http và https qua port 80 và 443
#mo port 80 giao thuc tcpfirewall-cmd --permanent --add-port=80/tcp
#mo port 443 giao thuc tcpfirewall-cmd --permanent --add-port=443/tcp
Cách 2: mở theo tên dịch vụ
#mo port cho webserver cho giao thuc httpfirewall-cmd --permanent --add-service=http
#mo port cho webserver cho giao thuc httpsfirewall-cmd --permanent --add-service=https
Mở một dải các cổng
#mo mot dai port tu 200 den 300firewall-cmd --permanent --add-port=200-300/tcp
Kiểm tra lại các cổng đang mở, các dịch vụ đang được phép
#liet ke cac cong dang mofirewall-cmd --list-ports
# liet ke cac dich vu dang duoc cho phepfirewall-cmd --list-services
Áp dụng thay đổi reload lại FirewallD
##### reload lai firewalld de ap dung thay doifirewall-cmd --reload
Mở cổng firewall trên Centos 6
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPTiptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
Để mở cổng ra cho iptables thì thay thế INPUT bằng OUTPUT
Ví dụ:
iptables -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPTiptables -A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT
Liệt kê danh sách policy hiện tại và lưu lại thay đổi
iptables -L -niptables-save | tee /etc/sysconfig/iptables
Áp dụng thay đổi trên firewall
service iptables restart
Leave A Comment?