headscale服务器搭建

一、安装 Headscale(推荐使用二进制方式)

1
2
3
4
5
6
7
8
9
10
11
12
13

# 1. 安装依赖
sudo apt update
sudo apt install curl unzip sqlite3 -y

# 2. 下载最新版 Headscale(从 GitHub)
curl -L https://github.com/juanfont/headscale/releases/latest/download/headscale_amd64 -o /usr/local/bin/headscale

# 3. 添加执行权限
chmod +x /usr/local/bin/headscale

# 4. 验证
headscale version

或者直接从github下载再上传到/usr/local/bin
https://github.com/juanfont/headscale/releases

2.创建headscale的配置文件

https://headscale.net/stable/ref/configuration/#__tabbed_1_1

示例配置文件地址
https://github.com/juanfont/headscale/blob/v0.26.1/config-example.yaml

将配置文件放在/etc/headscale/config.yaml
修改其中的server_url 为自建服务的域名,如hs.xxxx.com

3.创建服务启动headscale

在/etc/systemd/system/中创建配置文件headscale.service

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=Headscale coordination server
After=network.target

[Service]
ExecStart=/usr/local/bin/headscale serve --config /etc/headscale/config.yaml
WorkingDirectory=/var/lib/headscale
Restart=on-failure
RestartSec=5s
User=root

[Install]
WantedBy=multi-user.target

启动命令

1
2
3
systemctl daemon-reload
systemctl enable --now headscale
systemctl start headscale

4.在hs.xxxx.com域名中反向代理本地的8080端口

可以直接在bt面板中添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#PROXY-START/

location ^~ /
{
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
# proxy_hide_header Upgrade;

add_header X-Cache $upstream_cache_status;

#Set Nginx Cache


set $static_filegP1e2FBI 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_filegP1e2FBI 1;
expires 1m;
}
if ( $static_filegP1e2FBI = 0 )
{
add_header Cache-Control no-cache;
}
}

#PROXY-END/

部署自己derp服务

使用golang编译derper

安装golang
Debian/Ubuntu:

1
2
sudo apt update
sudo apt install -y golang

CentOS

1
sudo yum install -y golang

使用git 领取源码并构建

1
2
3
git clone https://github.com/tailscale/tailscale.git
cd tailscale/cmd/derper
go build

成功后,会生成一个可执行的文件 derper

使用systemd 服务启动derper

创建配置文件/etc/systemd/system/derper.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=DERP relay server
After=network.target

[Service]
ExecStart=/usr/local/bin/derper \
--hostname=derp.xxxx.com \
--certdir=/www/server/panel/vhost/cert/derp.xxxx.com \
--a=:3443 \
--http-port=3080 \
--stun
Restart=on-failure

[Install]
WantedBy=multi-user.target

启动derper

1
2
3
systemctl daemon-reload
systemctl enable --now derper
systemctl start derper

创建一个网站 derp.xxxx.com
在网站的根目录下创建一个derp.json的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"Regions": {
"900": {
"RegionID": 900,
"RegionCode": "mt_derp",
"RegionName":"China",
"Nodes": [
{
"Name": "1",
"RegionID": 900,
"HostName": "derp2.xxxx.com",
"IPv4": "xx.xxx.xxx.xx",
"IPv6": "2001:db8::1"
}
]
}
}
}

derp网站添加伪静态中配置

1
2
3
4
5
6
7
8
9
10
location =/derp.json {
root /www/wwwroot/derp.xxxx.com;
}

location =/derpmap/default {
default_type application/json;
alias /www/wwwroot/derp.xxxx.com/derp.json;
}


derp网站添加反向代理本地3443端口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#PROXY-START/

location ^~ /
{
proxy_pass http://127.0.0.1:3443;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
# proxy_hide_header Upgrade;

add_header X-Cache $upstream_cache_status;

#Set Nginx Cache


set $static_file0D4f5j1b 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_file0D4f5j1b 1;
expires 1m;
}
if ( $static_file0D4f5j1b = 0 )
{
add_header Cache-Control no-cache;
}
}

#PROXY-END/

修改/etc/headscale/config.yaml的
在derp下urls 中添加 https://derp.xxxx.com/derp.json

重启headscale

1
systemctl restart headscale

验证derp服务是否已经安装成功
在安装了tailscale 并登录了自建的服务的本地命令行运行

1
tailscale netcheck

结果类似

1
2
3
4
5
6
7
8
9
10
11
Report:
* Time: 2025-06-23T06:39:37.609746Z
* UDP: false
* IPv4: (no addr found)
* IPv6: no, but OS has support
* MappingVariesByDestIP:
* PortMapping:
* CaptivePortal: false
* Nearest DERP: China
* DERP latency:
- mt_derp2: 10.5ms (China)

headscale 后台管理页面

项目地址:
https://github.com/gurucomputing/headscale-ui

下载之后上传解压到/www/wwwroot/headscale_ui/web

在hs.xxxx.com的网站中配置伪静态

1
2
3
4
5

location /web {
alias /www/wwwroot/headscale_ui/web;
index index.html;
}

然后访问https://hs.xxxx.com/web

需要先在setting 中填入apikey

在安装headscale的服务器上执行命令创建apikey

1
headscale apikeys create

填入apikey,然后保存

抓取nuxt.js网站并将内容转成pdf

1.直接使用python+playwright获取渲染之后html源代码

避免需要去处理js,使用flask搭建一个接口,传入url 获取源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from flask import Flask, request
from playwright.sync_api import sync_playwright

@app.route('/html/url', methods=['POST'])
def get_html():
url = request.form.get('url')
html = get_html_by_url(url)
return html

def get_html_by_url(url):
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto(url, wait_until="networkidle")
html = page.content()
browser.close()
return html
if __name__ == '__main__':
app.run(debug=False, use_reloader=False)

2.将获取的源代码 转成pdf

2.1 下载支持汉字的字体文件

下载字体是为了避免出现乱码
https://fonts.google.com/?lang=zh_Hans
从下载的字体包中选择一个上传到本地,我选择了
NotoSerifSC-Regular.ttf

2.2 php安装扩展

1
composer require barryvdh/laravel-dompdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    use Barryvdh\DomPDF\Facade\Pdf;
use QL\QueryList;

public static function html2PDF($data)
{
$html = $data->content;
//处理懒加载的图片
$ql = QueryList::html($html);
$ql->find('img')->each(function ($item) {
$data_src = $item->attr('data-src');
$src = $item->attr('src');
//去除?后的内容
$data_src = substr($data_src, 0, strrpos($data_src, '?'));
$src = substr($src, 0, strrpos($src, '?'));

if ($src != $data_src) {
$item->attr('src', $data_src);
}
});
$html = $ql->getHtml();
$html = str_replace(' ', ' ', $html); // 替换 HTML 中的 
$html = preg_replace('/\x{00A0}/u', ' ', $html); // 替换 Unicode 不可见空格

//指定字体避免乱码
// 加字体样式
$style = '
<style>
@font-face {
font-family: "Noto_Serif_SC";
src: url("' . storage_path('fonts/NotoSerifSC-Regular.ttf') . '");
}
body {
font-family: "Noto_Serif_SC", DejaVu Sans, sans-serif;
}
p { line-height: 1.5; font-size: 14px; }
</style>
';

$html = $style . $html;

$pdf = Pdf::loadHTML($html, 'UTF-8');

$cate_id = $data->cate_id;
$cate = Db::table('cate')->where('id', $cate_id)->first();
$cate_name = $cate->name;
$relativePath = 'pdf/' . $cate_name . '/' . str_replace('姓名:', '', $data->title) . '.pdf';

// 确保目录存在
Storage::disk('public')->makeDirectory('pdf');
// 保存 PDF 文件到指定路径
$re = Storage::disk('public')->put($relativePath, $pdf->output());
dump("$cate_name,$data->title,$re");

}


自己搭建去除水印Iopaint

1.安装Iopaint

pip3安装Iopaint

1
pip3 install iopaint

直接命令行测试启动

1
iopaint start --model=lama --device=cpu --port=8080

启动的时候会默认下载模型
如果下载不了,可以自己用魔法下载再上传到默认的目录
文件名为big-lama.pt

1
/root/.cache/torch/hub/checkpoints

启动成功后网页端会监听本地的8080端口

2.创建systemd服务

1
vim /etc/systemd/system/iopaint.service

配置文件

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=IOPaint Service
After=network.target

[Service]
User=root
WorkingDirectory=~
ExecStart=iopaint start --model=lama --device=cpu --port=8080
Restart=always

[Install]
WantedBy=multi-user.target

启动服务

1
2
3
sudo systemctl daemon-reload
sudo systemctl start iopaint
sudo systemctl enable iopaint

查看状态

1
sudo systemctl status iopaint

如果启动失败,监听日志

1
journalctl -u iopaint -xe -f

3.创建网站,反向代理本地8080端口,添加bash auth 密码验证

android_root

1.开启开发者模式

链接点击手机系统版本号,开启开发者模式
开启开发者模式中的允许OEM解锁

2 下载Magisk

github 地址

1
https://github.com/topjohnwu/Magisk

3.小米手机秒解锁BL

1.下载unlocktool,,网址,www.unlocktool.net

2.咸鱼购买临时账号 

3.手机开启开发者模式,开启OEM解锁 ,usb链接手机

4.登录进入unlocktool,点击右侧CONFIG,下载安装libusb 驱动
选择上面的芯片品牌MEDIATEK
 点击,左下方的菜单 PERM | UNLOCKV BL

5.先关机,再同时按开机键+音量减,进入fastboot 模式,这时候在右侧的COM接口能看到手机 

6.再同时按 开机键+音量加 ,看到右侧开始有输出就是在解锁了

4.下载红米10A 线刷包

1
https://xiaomirom.com/download/redmi-9a-9i-9at-9a-sport-10a-10a-sport-dandelion-stable-V12.5.21.0.RCDCNXM/#china-fastboot

从中获取images文件夹中获取文件boot.img

5.修补boot.img

上传boot.img到手机

• 打开 Magisk,点击“安装” > “选择并修补一个文件”,选择 boot.img;

• 修补后,会生成一个 magisk_patched-xxxx.img 文件。

6.刷入修补后的镜像

将magisk_patched-29000_SH1FS.img 文件上传到电脑
手机进入 Fastboot 模式 ,
在电脑终端,进入放置img文件的文件夹,然后运行:

1
fastboot flash boot magisk_patched-29000_SH1FS.img

再重启验证是否安装成功

1
fastboot reboot

打开magsik ,显示了版本号,则是root成功

开机状态重启进入fastboot

1
adb reboot bootloader

双参登录测试

1
e5589f47a5e84a1c873dbce83709d863-4752898956----dfb02eeb2c5b81d0eae4045f7dcf8300----ANDROID_52942458fbd55fbd', requestBody 'NOT SUPPORT'----DFP40694923474658F6D91DE87B2A1CC9FD2F8147EDED4A782A3C3A4700E9C3D----Cg9rdWFpc2hvdS5hcGkuc3QSoAEkYdJJ38uIUsKhAqsx-ItlDXlTJIi9gVxuJLIvDgOPmQmI6MyDjf8iyu3TxTbuvACOESZ7Zz1tIAKIf97e4Pfk9WNP6dOJUcZ8eK-4vmrnQ8WixfWZsS--O0SbopRPrWPRgzihcWFzW-7QgjANxuG6xhnrzMj_Tp7sa_s0iC5uaiAUbWlI5Pku1ZQAXQiqi-kTurxLWnTZXdsdqqEU8FC1GhJmQmJkX-pJEqgjQbtJv1UuVkwiICWRwU_RQ8MZ44YXX4PAAcGnzenga_0yx7hWzBom6szaKAUwAQ

安装jadx

1
brew install jadx

mac上打开jadx图形界面

1
jadx-gui

安装apktool

1
brew install apktool

反编译

1
apktool d douyin-19-8-0.apk -o dy_src -r

修改smail 代码后再打包

1
apktool b dy_src -o douyin_mod.apk -r

添加java到环境变量

1
2
3
4
5
6
vim ~/.zshrc

export JAVA_HOME="/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home"
export PATH="$JAVA_HOME/bin:$PATH"

source ~/.zshrc

生成临时的keystore

1
2

keytool -genkeypair -v -keystore temp-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias temp-key

使用临时的key 给apk签名

1
2
3
4
5
/opt/homebrew/opt/openjdk/bin/jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 \
-keystore temp-keystore.jks \
-storepass 123456 \
-keypass 123456 \
-signedjar douyin_mod_signed.apk douyin_mod.apk temp-key

对apk对齐优化(可选)

1
zipalign -v 4 douyin_mod_signed.apk douyin_mod_aligned.apk

frida

安装frida

1
pip install frida-tools

查询cpu类型

1
adb shell getprop ro.product.cpu.abi

红米10A的cpu架构是armeabi-v7a

github下载frida-server

1
2
3
https://github.com/frida/frida/releases

frida-server-17.0.5-android-arm.xz

解压

1
xz -d frida-server-17.0.5-android-arm.xz

推送到手机

1
2
3
adb push frida-server-17.0.5-android-arm /data/local/tmp/frida-server
adb shell chmod 755 /data/local/tmp/frida-server
adb shell "/data/local/tmp/frida-server &"

直接adb shell “/data/local/tmp/frida-server &” 会没有权限
在安装了magisk的情况下,使用adbshell 切换到root用户

1
2
3
4
abd shell
su
adb shell "/data/local/tmp/frida-server &"

上面的已root运行frida-server的方式会问题,会报错
修改为安装magisk的模块,直接将frida注入
firda-inject的magisk的模块下载地址

1
https://github.com/ViRb3/magisk-frida/releases

确认 Frida-Server 在设备上正常运行(可跳过 frida-ps):

1
2
adb forward tcp:27042 tcp:27042
adb forward tcp:27043 tcp:27043
1
frida -U -n com.ss.android.ugc.aweme -l bypass_ssl.js

bypass_ssl.js内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Java.perform(function () {
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
var SSLContext = Java.use('javax.net.ssl.SSLContext');
var TrustManager = Java.registerClass({
name: 'dev.asd.trust.TrustManager',
implements: [X509TrustManager],
methods: {
checkClientTrusted: function (chain, authType) {},
checkServerTrusted: function (chain, authType) {},
getAcceptedIssuers: function () { return []; }
}
});
var TrustManagers = [TrustManager.$new()];
var SSLContextInit = SSLContext.init.overload('[Ljavax.net.ssl.KeyManager;', '[Ljavax.net.ssl.TrustManager;', 'java.security.SecureRandom');
SSLContextInit.implementation = function (keyManager, trustManager, secureRandom) {
console.log('Bypassing SSL Pinning');
SSLContextInit.call(this, keyManager, TrustManagers, secureRandom);
};
});

### 失败,电脑上无法链接手机上frida-server

下载别人修改好的libsscronet.so文件
上传覆盖到抖音

so文件百度网盘地址
https://link.juejin.cn/?target=https%3A%2F%2Fpan.baidu.com%2Fs%2F1BuL8vtIyd34b0y60jY3qXg
提取码1005

先上传到临时目录

1
2

adb push /Users/sevenli/Desktop/libsscronet.so /data/local/tmp/

查看抖音的存储路径

1
adb shell pm path com.ss.android.ugc.aweme

package:/data/app/~~6GFRK59nqVa2mAt8HxQ3tQ==/com.ss.android.ugc.aweme-LYq5WsM6oXhCSXuDutJpvw==/base.apk

再使用root 覆盖原始的so文件

1
2
3
4
5
6
7
8
9
10
11
12
13

adb shell
su # 如果需要 root 权限

# 备份原始文件
cp /data/app/~~6GFRK59nqVa2mAt8HxQ3tQ==/com.ss.android.ugc.aweme-LYq5WsM6oXhCSXuDutJpvw==/lib/arm/libsscronet.so /data/app/~~6GFRK59nqVa2mAt8HxQ3tQ==/com.ss.android.ugc.aweme-LYq5WsM6oXhCSXuDutJpvw==/lib/arm/libsscronet.so.bak

# 覆盖替换
cp /data/local/tmp/libsscronet.so /data/app/~~6GFRK59nqVa2mAt8HxQ3tQ==/com.ss.android.ugc.aweme-LYq5WsM6oXhCSXuDutJpvw==/lib/arm/libsscronet.so

# 修改权限
chmod 755 /data/app/com.ss.android.ugc.aweme-1/lib/arm/libsscronet.so
chown root:root /data/app/com.ss.android.ugc.aweme-1/lib/arm/libsscronet.so

重启抖音

1
2
adb shell am force-stop com.ss.android.ugc.aweme
adb shell monkey -p com.ss.android.ugc.aweme -c android.intent.category.LAUNCHER 1

失败,抖音19.8.0能抓包了,但是版本太低了.无法登录

install_socks5_on_ubuntu

在ubuntu虚拟机上安装socks5客户端

1.安装clash.meta

github地址
1
https://github.com/MetaCubeX/mihomo

下载解压linux-amd64版本
1
2
chmod +x clash
sudo mv clash /usr/local/bin/

创建配置文件目录

1
mkdir -p ~/.config/clash

添加配置文件

1
vim config.yaml

配置文件格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mode: rule
log-level: info
external-ui: ui
external-controller: 127.0.0.1:9090

proxies:
- name: sk1
type: socks5
server: 116.31.103.35
port: 1212
username: cai123
password: cai123
- name: sk2
type: socks5
server: 116.31.103.35
port: 7777
username: cai123
password: cai123

proxy-groups:
- name: auto
type: load-balance
proxies:
- sk1
- sk2

rules:
- MATCH,auto

1.2 创建服务

1
vim   /etc/systemd/system/clash.service

写入配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=Clash (Mihomo) Service
After=network.target

[Service]
User=root
Restart=always
ExecStart=/root/.config/mihomo/clash -f /root/.config/mihomo/config.yaml
WorkingDirectory=/root/.config/mihomo
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target

启用并启动服务

1
2
3
4
sudo systemctl daemon-reload          # 重新加载 systemd
sudo systemctl enable clash.service # 设置开机自启动
sudo systemctl start clash.service # 启动 Clash 服务
sudo systemctl status clash.service # 查看运行状态

2.安装 Yacd(Web UI 控制面板)

在配置文件添加web ui 路径

1
2
3
external-ui: ui
external-controller: 0.0.0.0:9090
secret: ""

控制面板的地址就是虚拟机的ip的9090端口

1
http://192.168.107.3:9090

2.2 在ubuntu上开启端口

安装ufw

1
2
sudo apt update
sudo apt install ufw

开启防火墙

1
sudo ufw enable

开启端口

1
2
3
4
5
sudo ufw allow 7890
sudo ufw allow 9090
sudo ufw allow ssh # 开放 22
sudo ufw allow http # 开放 80
sudo ufw allow https # 开放 443

查看状态和开放端口

1
sudo ufw status verbose

2.3 直接下载yacd的前端代码

下载地址,下载yacd.tar.xz
1
2

https://github.com/haishanh/yacd/releases

将文件解压,里面有index.html文件,直接用这个目录当网站的根目录创建网站

进入网站输入 http://192.168.107.3:9090 和密码,进入管理界面

RSA密钥对 生成

  • RSA密钥对 生成
1
2
3
4
5
6
7

#生成私钥
openssl genrsa -out rsa_1024_priv.pem 1024

#生成公钥
openssl rsa -pubout -in rsa_1024_priv.pem -out rsa_1024_pub.pem

  • api请求使用公钥加密参数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

<textarea name="" id="key" cols="200" rows="10">-----BEGIN PUBLIC KEY-----
############################################################
############################################################
############################################################
############################################################
-----END PUBLIC KEY-----
</textarea>


<script src="/admin/static/jsencrypt.min.js"></script>
<script type="text/javascript">
$(function () {
$('#submit').click(function () {
test();
})
})

function test() {
let encrypt = new JSEncrypt();
let pub_key = $('#key').val();
encrypt.setPublicKey(pub_key);
let data = encrypt.encrypt("123456");
let csrf = '@csrf';
csrf = $(csrf).val();
$.post('{{url("admin/~~test~~/ajax")}}', {data: encodeURI(data).replace(/\+/g, '%2B'), _token: csrf}, function (res) {
console.log(res);
}, 'json')
}
</script>




  • 后端用私钥解密
1
2
3
4
5
6
7
8
9
10
11
12
13

$data = request()->post('data');
$private_key = file_get_contents(storage_path('rsa_1024_priv.pem'));//读取私钥
$privateKey = openssl_pkey_get_private($original);//这个函数可用来判断私钥是否是可用的,可用,返回资源,私钥可用file_get_content从文件中获取
$encrypted_data=null;
$result = openssl_private_decrypt(base64_decode(urldecode($data)), $encrypted_data, $private_key);


dump($result);
dump($encrypted_data);
exit;


在不用第三个变量的情况下交换两个变量的值

php有两个变量,在不使用第三个变量的情况下交换两个变量的值

1.如果是使用第三个变量

1
2
3
4
5
6
$a=100;
$b=200;

$c=$a; //将$a赋值给第三个变量$c
$a=$b; //将$b的值给$a;
$b=$c; //将$c,也就是之前$a的值赋值给$b;

使用第三个变量交换

2.使用list

1
2
3
4
$a=100;
$b=200;

list($b,$a)=array($a,$b);

使用list交换

宝塔 mysql 无法远程连接

宝塔下新建一个数据库,使用sqlyog无法远程连接.

第一次尝试解决

  • 权限设置为所有人,就是所有ip都可以连接
  • 宝塔’安全’菜单,放行3306端口
  • 云服务器安全组,防火墙添加规则放行3306端口

windows下使用telnet 监测服务器的端口是否开启

1
telnet 123.56.78.123  3306       #telnet 加ip或者域名 加 端口号

无法连接,所以centos7系统防火墙的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
netstat -tlunp               #查看主机监听的所有端口
iptables-save #查看iptables的所有规则
iptables -nL --line-number #按行号显示iptables规则

#没有3306端口的规则,添加一条
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
#或者
iptables -A IN_public_allow -p tcp -m tcp --dport 3306 -m conntrack --ctstate NEW,UNTRACKED -j ACCEPT

service iptables save #保存
service iptables restart #重启服务

#尝试还是不行,再次使用'iptables -nL --line-number'查看规则,发现在我新添加的3306规则上有一条
-A INPUT -j REJECT --reject-with icmp-host-prohibited

#按行号删除这一条
iptables -D INPUT 11 #删除第11行的iptables规则,上面这条在所有规则的11行

#再重新添加这一行,然后他就排到3306规则后面了
iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited

service iptables save #保存
service iptables restart #重启服务


再次尝试.ok