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。
![](https://i-blog.csdnimg.cn/blog_migrate/765a6150b84e53cbc2260424eb33d83a.png)
2、iptables的使用
iptables的策略文件:/etc/sysconfig/iptables;
iptables的更新方式:
<1> 刷新iptables的规则列表:iptables -F
<2> 填写自己的规则列表:iptables -A INPUT -j DROP
<3> 规则列表的保存:service iptables save
![](https://i-blog.csdnimg.cn/blog_migrate/cf1bfc2a836333be4f24a5d4cc3e0953.png)
【注】清空原策略文件: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 | 转化目的地址 |
![](https://i-blog.csdnimg.cn/blog_migrate/a795b37ee6aaf6311c27730b9f8b1535.png)
![](https://i-blog.csdnimg.cn/blog_migrate/ed09fe3bee3287facc3c49e0c44e470c.png)
![](https://i-blog.csdnimg.cn/blog_migrate/292ef6eb8cd30de91f9db7b301b5448a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/367a58c0437d3c13ba2b274b81caa633.png)
nat表参数的实验环境:
<1>服务器为双网卡,且中间路由功能开启;
![](https://i-blog.csdnimg.cn/blog_migrate/6cc00385abb553e914ab93c394582c0d.png)
<2>对应的域内的网关为该路由的地址。
![](https://i-blog.csdnimg.cn/blog_migrate/cd01bfe1ac1031b27f13c09784348f58.png)
设置策略:
![](https://i-blog.csdnimg.cn/blog_migrate/842904346a2c24f8a8603dde50c51ff1.png)
![](https://i-blog.csdnimg.cn/blog_migrate/14944bac58b64a200b71fa60d1eccc58.png)
![](https://i-blog.csdnimg.cn/blog_migrate/373628dc89f84e2f94a537adb6f4baf2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fa274a26e193d8726408151779c2b8d8.png)
【注】1、默认规则为ACCEPT,更改默认规则只能改为:ACCEPT/DROP;
2、在删除链之前,必须删除其中的策略。