﻿# 如何在 Linux 下快速建立一個虛擬網卡 (虛擬 IP)

在 Ubuntu 裡，以往要新增虛擬 IP 我都要修改 /etc/network/interfaces 設定檔，然後再重新啟用網卡 ( /etc/init.d/networking restart )，有時後只是要做一些簡單的測試，這樣子修改實在大費周章，最近查到一個快速新增虛擬 IP 的方式。

如果你的介面卡是 eth0 且 IP 為 10.0.0.1，如過要新增一個虛擬 IP 為 10.0.0.2 且介面名稱為 eth0:0 時，可以直接打以下指令完成：

```
ifconfig eth0:0 10.0.0.1 up
```

如果要關閉這個虛擬 IP 可以將 up 改成 down 即可：

```
ifconfig eth0:0 down
```

這是暫時性的虛擬 IP 新增方法，非常方便快速。

如果要重開機自動設定虛擬 IP 就必須要修改 /etc/network/interfaces 設定檔了。

```
auto eth0:0
iface eth0:0 inet static
   address 10.0.0.2
   netmask 255.255.255.0
   network 10.0.0.0
   broadcast 10.0.0.255
```

**相關連結**

-   [Ubuntu Linux: Creating ethernet alias for eth0 network device](http://www.cyberciti.biz/tips/ubuntu-linux-creating-ethernet-alias-for-eth0-network-device.html)
