Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Ubuntu 建立虛擬網卡 (IP Alias) 實現單網卡多 IP:修改 /etc/network/interfaces 完整範例

編輯:關於 Linux

單張實體網卡可建立多個虛擬介面 (eth0:1, eth0:2...) 各自綁定不同 IP/子網,適用於單機運行多服務、測試多網段環境。本文示範編輯 /etc/network/interfaces 新增 eth0:1、eth0:2 靜態 IP 配置、service networking restart 重啟網路驗證 ifconfig 顯示多介面。子網規劃建議避免重疊,但技術上允許同子網多 IP。

配置檔範例

auto eth0
iface eth0 inet static
  address 192.168.1.100
  netmask 255.255.255.0
  gateway 192.168.1.1

auto eth0:1
iface eth0:1 inet static
  address 192.168.2.100
  netmask 255.255.255.0

auto eth0:2
iface eth0:2 inet static
  address 192.168.3.100
  netmask 255.255.255.0

生效與驗證

sudo service networking restart
ifconfig
# 應顯示 eth0, eth0:1, eth0:2 三介面各自 IP

虛擬網卡無需額外硬體,修改網路配置檔即時生效,是單機多 IP 最經濟方案。

Copyright © Windows教程網 All Rights Reserved