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
端口修改成功