Hướng dẫn cài Iptables trên CentOS7

 

Trong Centos7 Firewalld là tường lửa mặc đinh. Nếu các bạn muốn sử dụng tường lửa Iptables như trên Centos6 các bạn phải cài thêm.

Các bước cài Iptables trên Centos7

Stop FirewallD service:

sudo systemctl stop firewalld

Disable FirewallD service khi tự động khởi động cùng hệ thống:

sudo systemctl disable firewalld

Khoá luôn FirewallD service bếu muốn start bởi dịch vụ khác:

sudo systemctl mask --now firewalld

Cài đặt và enbale Iptables

Chạy lệnh sau để cài package từ CentOS repositories:

sudo yum install iptables-services

Chạy lệnh sau để start Iptables service:

sudo systemctl start iptables
sudo systemctl start ip6tables

Cho phép Iptables service start cùng hệ thống:

sudo systemctl enable iptables
sudo systemctl enable ip6tables

Kiểm tra trạng thái iptables service status:

sudo systemctl status iptables
sudo systemctl status ip6tables

Kiểm tra các iptables rules hiện tại:

sudo iptables -nvL
sudo ip6tables -nvL

Kết quả:

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination 
5400 6736K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 
2 148 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0 
3 180 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination 
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 4298 packets, 295K bytes)
pkts bytes target prot opt in out source destination

Lời kết

Qua bài viết này mình đã chia sẻ các bạn làm thế nào để sử dụng tường lửa Iptables trên Centos 7.

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

Bài viết liên quan

Leave a Reply

Your email address will not be published. Required fields are marked *