Iptables
iptables 組件是一種工具,也稱爲用戶空間(userspace),它使插入、修改和除去信息包過濾表中的規則變得容易
Red Hat Linux 7.0 版本之前使用的是 Iptables
Red Hat Linux 7.0 版本之後使用的是 Firewall
規則(rules
):網絡管理員預定義的條件
鏈(chains
): 是數據包傳播的路徑
表(tables
):內置3個表filter
表,nat
表,mangle
表分別用於實現包過濾網絡地址轉換和包重構的功能
filter
表
是系統默認的,INPUT(進入的包),FORWORD(轉發的包),OUTPUT(處理本地生成的包),filter表只能對包進行授受和丟棄的操作
nat
表
網絡地址轉換,PREROUTING(修改即將到來的數據包),OUTPUT(修改在路由之前本地生成的數據包),POSTROUTING(修改即將出去的數據包)
mangle
表
PREROUTING,OUTPUT,FORWORD,POSTROUTING,INPUT
實驗環境
yum install iptables-services -y
安裝 Iptables
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
systemctl start iptables.service
systemctl enable iptables.service
Filter
表
iptables -t filter -nL
查看規則
iptables -F
service iptables save
iptables -t filter -A INPUT -p tcp --dport 22 -j REJECT
iptables -t filter -A INPUT -s 172.25.254.30 -p tcp --dport 22 -j REJECT
iptables -D INPUT 2
iptables -nL
iptables -t filter -I INPUT -s 172.25.254.30 -p tcp --dport 22 -j REJECT
插入規則
iptables -t filter -R INPUT 1 -s 172.25.254.30 -p tcp --dport 22 -j DROP
iptables -S INPUT
iptables -N redhat
iptables -E redhat WESTOS
iptables -X WESTOS
iptables -F
添加規則
iptables -nL
iptables-save > /etc/sysconfig/iptables
iptabls -F
systemctl restart iptables.service
iptables -nL
iptables -F
清空規則
新建規則
iptables -nL
Nat
表
地址僞裝
添加規則
查看規則
測試
SELinux
修改服務端口
getenforce
yum install httpd
systemctl start httpd
netstat -antlupe | grep httpd
vim /etc/httpd/conf/httpd.conf
Listen 8080
systemctl restart httpd.service
端口修改成功
vim /etc/httpd/conf/httpd.conf
Listen 8888
systemctl restart httpd.service
端口修改錯誤
SELinux 防火牆 httpd 服務裏沒有 8888 端口
setenforce 0
systemctl restart httpd.service
netstat -antlupe | grep httpd
當我們設置 SELinux 爲警告級別時,端口修改成功
setenforce 1
systemctl restart httpd.service
設置成強制級別時,修改端口又出現錯誤
semange port -l grep http
查看 http 在 SELinux 中的端口號沒有 8888 端口
semanage port -a -t http_port_t tcp 8888
給 SELinux 添加 tcp 8888 端口
semanage port -l | grep http
添加 tcp 8888 端口成功
systemctl restart httpd.service
netstat -antlupe | grep httpd
端口修改成功