generated from cotes2020/chirpy-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
title: iptables | ||
date: 2024-04-12 00:00:00 +0800 | ||
categories: [root, linux] | ||
tags: [linux, iptables] | ||
author: ahern | ||
--- | ||
|
||
![img.png](./assets/images/img_5.png){:height="10%" width="60%"} | ||
|
||
## 基本概念 | ||
|
||
- iptables由表、链、规则组成;表包含链,链包含规则 | ||
- 包含filter、nat、mangle、raw等几种内建表,filter最常用 | ||
|
||
各种链: | ||
|
||
- INPUT 链:处理来自外部的数据。 | ||
- OUTPUT 链:处理向外发送的数据。 | ||
- FORWARD 链:数据转发。通过路由表后发现目的地址非本机,则匹配该链中的规则。 | ||
- PREROUTING 链:处理刚到达本机并在路由转发前的数据包。 | ||
- POSTROUTING 链: 处理即将离开本机的数据包。 | ||
|
||
## 常用命令 | ||
|
||
> 命令格式,默认 -t filter:iptables [ -t 表名] 命令选项 [链名] [条件匹配] [-j 处理动作或跳转] | ||
> {: .prompt-tip } | ||
|
||
|
||
列出链及规则,显示行号 | ||
|
||
``` | ||
iptables -L -n -v --line-numbers | ||
``` | ||
|
||
|
||
|
||
删除INPUT 链,行号为1的规则 | ||
|
||
``` | ||
iptables -D INPUT 1 | ||
``` | ||
|
||
|
||
|
||
在INPUT 链新增规则 | ||
|
||
``` | ||
iptables -I INPUT -s 0.0.0.0/0 -p tcp -m multiport --dports 8123,9000 -j ACCEPT | ||
``` | ||
|
||
- -I: 在第1行插入 | ||
|
||
- -A: 在最后1行追加 | ||
|
||
|
||
|
||
删除指定链中的所有规则(慎用) | ||
|
||
``` | ||
iptables -F INPUT | ||
``` | ||
|
||
|
||
|
||
规则备份和恢复 | ||
|
||
- `service iptables save`保存规则到/etc/sysconfig/iptables | ||
|
||
- `iptables-save > my.ipt`重定向规则到my.ipt | ||
|
||
- `iptables-restore < my.ipt`从my.ipt中恢复规则 | ||
|
||
|
||
|
||
## 规则 | ||
|
||
- 链中规则至上而下执行 | ||
|
||
## 参考 | ||
- [iptables 概念、原理及相关操作介绍](https://juejin.cn/post/7135399062588620813#heading-5) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.