1、火墙工具切换
我们知道在Linux中默认的火墙管理工具为firewalld,但其模式比较傻瓜,那如何切换到iptables工具呢?一下为切换步骤:
<1> 安装iptables服务;
安装包:iptables-service
<2>关闭firewalld服务;
关闭firewalld服务:systemctl stop firewalld;
设置开机不启动:systemctl disable --now firewalld;
设置服务冻结:systemctl mask firewalld;
<3>开启iptables服务
设置开机启动:systemctl enable --now firewalld。
2、iptables的使用
iptables的策略文件:/etc/sysconfig/iptables;
iptables的更新方式:
<1> 刷新iptables的规则列表:iptables -F
<2> 填写自己的规则列表:iptables -A INPUT -j DROP
<3> 规则列表的保存:service iptables save
【注】清空原策略文件:iptables-save > /etc/sysconfig/iptables
3、iptables的常见命令
| 常见参数 | 效果 | |
| -t | 指定表的名称 | |
| -n | 对地址不做解析 | |
| -L | 对地址做解析 | |
| -A | 在链尾添加新策略 | |
| -p | 指定协议 | |
| --dport | 指定端口 | |
| -s | 指定来源 | |
| -j | 所跟操作 | |
| ACCEPT | 允许通过 | |
| DROP | 丢弃数据包 | |
| REJECT | 拒绝数据包 | |
| SNAT | 源地址转化 | |
| DNAT | 目的地址转化 | |
| -N | 创建新表 | |
| -E | 编辑新表 | |
| -X | 删除新表 | |
| -D | 删除规则 | |
| -I | 插入规则 | |
| -R | 更改规则 | |
| -P | 更改默认规则 | |
| -i | 网卡名称 匹配从这块网卡流入的数据 | |
| -o | 网卡名称 匹配从这块网卡流出的数据 | |
| --to-source | 转化源地址 | |
| --to-dest | 转化目的地址 | |
nat表参数的实验环境:
<1>服务器为双网卡,且中间路由功能开启;
<2>对应的域内的网关为该路由的地址。
设置策略:
【注】1、默认规则为ACCEPT,更改默认规则只能改为:ACCEPT/DROP;
2、在删除链之前,必须删除其中的策略。