# 配置额外的弹性 IP

对于非 /32 的弹性 IP 网段，仅会自动将**网关 IP**分配到实例。\
其余 IP 在使用前，必须在操作系统内手动完成配置。

**当前支持的操作系统：**

* Ubuntu
* CentOS
* ESXi

**配置前准备：**

在开始配置前，请确保已获取以下信息：

* 已分配的 EIP 网段（例如：`203.0.113.16/28`）
* 网关 IP（系统自动分配）
* 子网掩码（例如：`/28` → `255.255.255.240`）
* 主网卡名称（例如：`wan0`）

可通过以下命令查看网卡名称：

```bash
ip addr
```

## Ubuntu 配置方法

适用于 Ubuntu 18.04 及以上版本（基于 Netplan 的系统）

#### 步骤 1：编辑 Netplan 配置文件

```bash
sudo nano /etc/netplan/00-installer-config.yaml
```

#### 步骤 2：在 addresses 下添加 IP

示例：

```yaml
network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 203.0.113.17/28
        - 203.0.113.18/28
      gateway4: 203.0.113.16
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
```

#### 步骤 3：应用配置

```bash
sudo netplan apply
```

## CentOS 配置方法

适用于 CentOS 7 / 8

#### 步骤 1：编辑网卡配置文件

```bash
sudo nano /etc/sysconfig/network-scripts/ifcfg-wan0
```

#### 步骤 2：添加 IP

示例：

```
IPADDR1=203.0.113.17
PREFIX1=28

IPADDR2=203.0.113.18
PREFIX2=28
```

#### 步骤 3：重启网络服务

```bash
sudo systemctl restart network
```

或：

```bash
sudo nmcli connection reload
```

## ESXi 配置方法

#### 步骤 1：登录 ESXi Web 管理界面

进入：

```
Networking → VMkernel NICs
```

#### 步骤 2：编辑 VMkernel 适配器

* 添加额外的 IPv4 地址
* 使用与弹性 IP 网段相同的子网掩码
* 确认网关配置正确

#### 步骤 3：保存并应用配置

## 临时配置（Linux，仅用于测试）

如仅需临时测试额外的弹性 IP，而不希望修改永久配置，可使用以下命令：

```bash
sudo ip addr add 203.0.113.17/28 dev wan0
```

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

<mark style="color:blue;">此方式为非持久化配置，系统重启后将自动失效。</mark>
{% endhint %}

如需手动移除该 IP：

```bash
sudo ip addr del 203.0.113.17/28 dev wan0
```

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

* <mark style="color:blue;">请勿修改系统自动分配的网关 IP。</mark>
* <mark style="color:blue;">所有新增的弹性 IP 必须使用与分配网段相同的前缀长度。</mark>
* <mark style="color:blue;">请确保安全组及防火墙规则已正确放行相关流量。</mark>
  {% endhint %}


---

# 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/bare-metal/get-started/configure-additional-elastic-ips.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.
