> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://jimcloud.crisp.help/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Ubuntu 20增加 IP 到网卡 eth0

在 Ubuntu 系统中，可以通过修改网络配置文件来为网卡 `eth0` 增加多个 IP 地址。以下是具体步骤：

### 步骤 1：打开网络配置文件

对于 Ubuntu 18.04 及以上版本，通常使用 Netplan 进行网络配置。打开终端，使用文本编辑器（如 `nano` 或 `vim`）编辑 Netplan 配置文件，通常位于 `/etc/netplan/` 目录下。

```bash
sudo nano /etc/netplan/01-netcfg.yaml
```

### 步骤 2：修改配置文件

在配置文件中，添加第二个 IP 地址到 `eth0` 网卡。以下是一个示例配置：

```yaml
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.1/24
        - 192.168.1.2/24
      gateway4: 192.168.1.254  # 根据实际情况修改网关
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
```

### 步骤 3：应用配置

保存并关闭编辑器后，运行以下命令应用新的网络配置：

```bash
sudo netplan apply
```

### 步骤 4：验证配置

使用以下命令验证 IP 地址是否已成功配置：

```bash
ip addr show eth0
```

你应该能够看到 `eth0` 网卡上有两个 IP 地址：`192.168.1.1` 和 `192.168.1.2`。

### 注意事项

- 确保 `/etc/netplan/` 目录下的 YAML 文件名与上面的示例相符，文件名可以不同，但扩展名必须是 `.yaml`。
- 如果你的 Ubuntu 版本较旧（例如 16.04 及以下），则需要修改 `/etc/network/interfaces` 文件，配置示例如下：

```bash
auto eth0
iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    gateway 192.168.1.254

iface eth0:1 inet static
    address 192.168.1.2
    netmask 255.255.255.0
```

然后运行以下命令重启网络服务：

```bash
sudo systemctl restart networking
```

完成以上步骤后，你就可以在 Ubuntu 系统的 `eth0` 网卡上成功配置多个 IP 地址。