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

Linux 新增虛擬網卡的三種實用方法詳解

編輯:關於 Linux

前言

單一實體網卡可建立多張虛擬網卡,各自擁有獨立 IP,適用於伺服器多 IP 需求或測試環境。

方法一:ifconfig 暫時建立(重開機失效)

sudo ifconfig eth0:0 192.168.10.10 up   # 建立
sudo ifconfig eth0:0 down                # 移除

注意:虛擬網卡 MAC 位址與實體網卡相同。

方法二:修改網卡設定檔(永久生效)

Ubuntu 編輯 /etc/network/interfaces:

auto eth0:0
iface eth0:0 inet static
address 192.168.10.10
netmask 255.255.255.0
# network 192.168.10.1
# broadcast 192.168.1.255

套用變更:sudo /etc/init.d/networking restart

方法三:建立 TAP 裝置搭配網橋(可用於虛擬機)

# 安裝工具
sudo apt-get install uml-utilities bridge-utils

# 建立 TAP
sudo tunctl -b -u $(whoami)   # 產生 tap0, tap1...

# 啟用 TAP
sudo ip link set tap0 up

# 建立網橋並加入 TAP
sudo brctl addbr br0
sudo ip link set br0 up
sudo brctl addif br0 tap0

# 設定網橋 IP
sudo ifconfig br0 192.168.100.1/24 up

TAP 裝置擁有獨立 MAC 位址,適合 KVM/QEMU 虛擬機網路。

總結

臨時測試用方法一;長期服務用方法二;需獨立 MAC 或給虛擬機用則用方法三。

Copyright © Windows教程網 All Rights Reserved