# 端口映射

## 简介

**端口映射**就是将外网主机的IP地址的一个端口映射到内网中一台机器，提供相应的服务。当用户访问该IP的这个端口时，服务器自动将请求映射到对应局域网内部的机器上。端口映射有动态和静态之分。

### 准备

要开始端口映射,你必须确定以下内容

* 关闭防火墙或允许软件 **不会?看这里** \[[**Windows10**](https://support.microsoft.com/zh-cn/help/4028544/windows-10-turn-windows-defender-firewall-on-or-off)] \[[**Windows7**](https://zhidao.baidu.com/question/332263896304727805.html)]
* 将软件列入杀毒软件的白名单 **端口映射使用API操作** 可能出现拦截
* 判断自己是否拥有外网 **让别人Ping你IP就可以了** [**不会ping?看这里**](https://jingyan.baidu.com/article/fa4125ace1adf028ac709295.html)
* 给予软件管理员权限 **不会?** **右键 > 以管理员身份运行**
* 开启路由器的**端口映射**功能又名**虚拟服务器**

## **映射**

### **使用灵工艺开服器端口映射**

{% hint style="warning" %}
**声明:**&#x5F00;服器自带端口映射功能是使用**API**进行**代替手动操作**并**不能100%**&#x6210;功
{% endhint %}

![开服器自带端口映射样例截图](/files/-M7lO7-tMzEilWwkIFno)

**本机IP:**&#x4E00;般情况下软件启动是会自动读取软件运行电脑本机内网IP地址，但依旧建议手动查看确认 \[[查看本机IP地址教程](https://zhidao.baidu.com/question/176937209572275764.html)]

**外部端口:**&#x4EE3;表了外面访问你这台电脑的端口，例如你开启了Minecraft服 使用了**23333端口** 则需要使用 IP:23333 进入服务器

**内部端口:**&#x4EE3;表了你要将映射的内部端口，例如**Minecraft默认端口**为**25565** 内部端口代表了你需要将这个软件使用的端口映射到外部端口上，**然后就可以使用外部端口访问内部端口的内容**

{% hint style="success" %}
内部端口和外部端口是可以使用同一个的
{% endhint %}

### **开启映射**

{% hint style="info" %}
映射之前**需要关闭**服务器,映射后再开启,否则有很大几率不成功
{% endhint %}

#### **如果配置没有问题,直接点开`开启映射`按钮会弹出提示**

![成功提示](/files/-M7lOBA2at-TunxATMfk)

### 开启失败

![失败提示(Windows10系统样式)](/files/-M7lOEs6LHKn2CkF7_2M)

![失败提示(Windows7系统样式)](/files/-M7lOJrVmXFNZ4VtkTaK)

{% hint style="danger" %}
出现上图问题一般为**系统设置**问题或路由器**设置问题** 建议**重新配置 \[**[**准备**](broken://pages/-LrU7gtje7a0LbUtzQgt#jian-jie)**]** 阶段的内容

**如果还是不行,不要灰心,尝试下面的手动操作**
{% endhint %}

## 其他方法映射

### 手动映射

1. 关闭游戏服务端
2. 打开路由器后台地址
3. 找到 **端口映射** 或 **虚拟服务器**区 块进入
4. 添加映射 **外部端口** 与 **内部端口** 与上方内容一样
5. IP地址填写本机(开服务器的电脑)
6. 协议类型 建议选择 **ALL(全部)**
7. 完成

### DMZ主机

{% hint style="warning" %}
DMZ主机是将整台电脑暴露在外网下(但要拥有外网),**不需要端口映射**
{% endhint %}

1. 登录路由器后台
2. 找到DMZ主机区块然后开启
3. 将DMZ主机设置为开服电脑IP
4. 保存退出
5. 不需要再次端口映射

{% hint style="danger" %}
**不建议电脑小白使用此方法,造成后果与本教程/工作室无关**
{% endhint %}

### 借助Frp软件

{% hint style="warning" %}
注意:**Frp**并非**本地的端口映射**,Frp是将你的端口通过**内网穿透**到**对外服务器上**
{% endhint %}

| # | 名称                                    | 类型      |
| - | ------------------------------------- | ------- |
| 1 | [Sakura Frp](https://www.natfrp.org/) | 免费版/商业版 |

{% hint style="info" %}
以上软件由群友推荐与本工作室无任何相关利益\
本文档仅推荐 **公益/免费/商业版(拥有个人免费)** 的软件，如出现变更协议突然取消免费变为收费(高价)可通过用户群反馈移除
{% endhint %}

## 捐助我们

{% content-ref url="/pages/-M7hq9lfYUf1jD1tsDd9" %}
[捐助我们](/donate.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://olddocs.nullcraft.org/tutorial/port-mapping.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
