IPTABLES脚本命令

发布时间 2023-05-31 15:31:25作者: 往事已成昨天

iptables命令

图片图片

教程每周二、四、六更新

图片

 

iptables命令

查看帮助文档:

[root@m01 ~]# iptables -h
我们先看看前面用到的几个命令中设计到的参数:-t table用来指定需要操作的表,默认是filter表。使用的时候把table换成表名字(filter、nat、mangle、raw、security)即可-v指定显示详细信息-n把地址和端口用数字输出,而不是显示域名等名字信息。-L列出一个链或所有链中的规则查看默认表的规则的时候可以直接这样使用:
[root@m01 ~]# iptables -L

接下来看看iptables的其他用法:

环境准备:

systemctl stop firewalld.service
systemctl disable firewalld. service

iptables添加时,需要考虑好想要实现什么样的效果,因为这涉及到:

  • 要实现哪种功能:判断添加在哪张表上

  • 报文流经的路径:判断添加在哪个链上

  • 报文的流向:判断源和目的

  • 匹配规则:业务需要

先来看看iptables的使用格式:

[root@m01 ~]# man 8 iptables
iptables [-t table] {-A|-C|-D} chain rule-specification
ip6tables [-t table] {-A|-C|-D} chain rule-specification
iptables [-t table] -I chain [rulenum] rule-specification
iptables [-t table] -R chain rulenum rule-specification
iptables [-t table] -D chain rulenum
iptables [-t table] -S [chain [rulenum]]
iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]
iptables [-t table] -N chain
iptables [-t table] -X [chain]
iptables [-t table] -P chain target
iptables [-t table] -E old-chain-name new-chain-name

rule-specification = [matches...] [target]
match = -m matchname [per-match-options]
target = -j targetname [per-target-options]
下一节,我们通过一个实例,看看iptables如何使用。

 

雷哥开通了抖音(云计算雷哥)和微信视频号,求关注!!!和大家一起学习 技术!

图片

推荐阅读

 

《一站式教程之集群架构》:

ansible剧本-roles进阶

ansible 大结局 - 练习

iptable防火墙-简介

netfilter之firewalld与nftables

iptables详解-iptables组成

iptables-表和链的对应关系

 

看完本文有收获?请分享给更多人

推荐关注「Cloud研习社」,带你从零开始掌握云计算技术!

Cloud研习社
为Linux云计算零基础同学服务,致力于打造一套完整的linux云计算教程。包括新手学习路线、linux、存储、集群架构以及Docker,K8S,DevOps等
193篇原创内容

图片


图片

 

Cloud研习社
收录于合集 #linux
 248
上一篇Keepalived脑裂的解决和预防(附脚本)下一篇Kubernetes Pod 是如何获取 IP 地址的?
阅读 146