# 激活附加的内网 IPv4 地址

在为您的弹性算力实例分配附加的内网 IPv4 地址后，您需要访问该实例并配置内网 IPv4 以使其生效。

{% hint style="info" %} <mark style="color:blue;">**注意**</mark>

* <mark style="color:blue;">配置过程可能会因操作系统及其版本而略有不同。请根据您的具体情况相应配置。以下步骤仅供参考。</mark>
* <mark style="color:blue;">所有示例均使用网卡</mark> <mark style="color:blue;">`eth0`</mark> <mark style="color:blue;">作为示例，请替换为您实际的网卡名称。</mark>
  {% endhint %}

## 在 Linux 实例上配置内网 IPv4

### **RHEL 系列操作系统**

**适用操作系统**：CentOS, AlmaLinux 等。

1. **检查当前网络信息**：
   * 在云服务器上查看当前网络详情并使用 `route -n` 检查默认网关。

     ```sh
     route -n
     ```
2. **修改网络配置文件**：
   * 如果配置单个内网 IPv4 地址，请编辑以下文件：

     ```sh
     sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
     ```
   * 示例配置文件内容：

     ```sh
     DEVICE=eth0:0
     BOOTPROTO=static
     HWADDR=00:0C:29:6F:62:A7
     ONBOOT=yes
     IPADDR=172.16.2.6       # 附加内网 IPv4
     NETMASK=255.255.255.0   # 子网掩码
     GATEWAY=172.16.2.1      # 网关
     ```
3. **激活网络接口或重启网络服务**：
   * 激活网络接口：

     ```sh
     sudo ifup eth0:0
     ```
   * 或者重启网络服务：

     ```sh
     sudo systemctl restart network
     ```
4. **验证配置**：
   * 使用 `ifconfig` 或 `ip addr show` 检查配置。

     ```sh
     ifconfig
     ```

### **Rocky 操作系统**

在 Rocky 中，你可以使用 **NetworkManager** 提供的 `nmcli` 命令行工具来配置附加的内网 IPv4 地址。

1. **禁用 cloud-init 网络配置：**
   * Cloud-init 可能在实例重启时覆盖网络设置。为防止配置失败，需要创建一个文件来禁用 cloud-init 网络配置：

     ```sh
     sudo vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
     ```
   * 在文件中添加以下内容：

     ```yaml
     network: {config: disabled}
     ```
2. **检查当前网络连接：**
   * 运行以下命令：

     ```bash
     nmcli con show
     ```
   * 操作系统发行版本不同，网络连接名称也会有差异，以下仅为示例：<br>

     <div align="left"><figure><img src="/files/KlsazGS40RrpYvScVJzG" alt="" width="563"><figcaption></figcaption></figure></div>
3. **配置附加的内网 IPv4 地址和网关：**
   * 运行以下命令以配置 `eth0` 的附加内网 IPv4 地址、默认网关和子网掩码：

     ```shell
     sudo nmcli con modify "System eth0" ipv4.addresses 172.16.2.1/24,172.16.2.3/24,172.16.2.5/24   # Additional private IPv4
     sudo nmcli con modify "System eth0" ipv4.gateway 172.16.2.1      # Gateway
     ```
4. **激活网络配置：**
   * 运行以下命令以使变更生效：

     ```shell
     sudo systemctl restart NetworkManager
     ```

     如果没有返回任何消息，则配置已生效。
5. **验证配置：**
   * 使用 `ip addr show` 检查配置：

     ```sh
     ip addr show
     ```

### **Debian 系列操作系统**

**适用操作系统**：Ubuntu, Debian。

1. **检查当前网络信息**：
   * 在云服务器上查看当前网络详情并使用 `route -n` 检查默认网关。

     ```sh
     route -n
     ```
2. **修改网络配置文件**：
   * 编辑网络配置文件：

     ```sh
     sudo vi /etc/network/interfaces
     ```
   * 示例配置文件内容：

     ```sh
     auto eth0:0
     iface eth0:0 inet static
     address 172.16.2.2      # 附加内网 IPv4
     netmask 255.255.255.0   # 子网掩码
     gateway 172.16.2.1      # 网关
     ```
3. **重启网络服务**：
   * 重启网络服务：

     ```sh
     sudo systemctl restart networking
     ```
4. **验证配置**：
   * 使用 `ifconfig` 或 `ip addr show` 检查配置。

     ```sh
     ifconfig
     ```

### **SLES 系列操作系统**

**适用操作系统**：OpenSUSE。

1. **修改网络配置文件**：
   * 编辑网络配置文件：

     ```sh
     sudo vi /etc/sysconfig/network/ifcfg-eth0
     ```
   * 示例配置文件内容：

     ```sh
     IPADDR_0=172.16.2.8     # 附加内网 IPv4
     NETMASK_0=255.255.255.0 # 子网掩码
     ```
2. **重启网络服务**：
   * 重启网络服务：

     ```sh
     sudo systemctl restart network
     ```
3. **验证配置**：
   * 使用 `ifconfig` 或 `ip addr show` 检查配置。

     ```sh
     ifconfig
     ```

## 在 Windows 实例上配置内网 IPv4

1. **查看网络信息**：
   * 打开 **Windows PowerShell** 并运行以下命令以查看 IP 地址、子网掩码和默认网关信息：

     ```sh
     ipconfig /all
     ```
2. **打开网络和共享中心**：
   * 转到 **控制面板** > **网络和互联网** > **网络和共享中心**，并点击 **以太网** 适配器进行编辑。
3. **编辑以太网属性**：
   * 在 **以太网状态** 对话框中，点击 **属性**。
4. **配置 IPv4 设置**：
   * 选择 **Internet 协议版本 4 (TCP/IPv4)** 并点击 **属性**。
5. **填写网络信息**：
   * 使用第 1 步中获取的值填写以下字段：
     * 内网 IP 地址
     * 子网掩码
     * 默认网关
     * 首选 DNS 服务器
     * 备用 DNS 服务器（如适用）
6. **配置附加的内网 IPv4**：
   * 点击 **高级** 并添加附加的内网 IPv4。
   * 在 **高级 TCP/IP 设置** 对话框中，点击 IP 地址部分下的 **添加**。
   * 填写额外的内网 IPv4 和子网掩码，然后点击 **添加**。
7. **保存并验证配置**：
   * 点击所有对话框中的 **确定** 以保存设置。
   * 在 **以太网状态** 对话框中，点击 **详细信息** 查看已配置的 IP 信息。
8. **测试连接**：
   * 使用 ping 从同一全球 VPC 内的其他实例测试额外内网 IPv4 的连接性。


---

# 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://docs.console.zenlayer.com/welcome/cn/elastic-compute/get-started/manage-instances/activate-an-additional-private-ipv4-address.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.
