2012年7月3日 星期二

有時候因為工作需要連接不同device,各家產品的ip區段不一樣時常需要手動切換
這時候可以使用虛擬網卡分別設定不同區段

Ubuntu

vim /etc/network/interface

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1 eth1:0 eth1:1 eth1:2

#auto eth1:0
iface eth1:0 inet static
address 10.0.0.100
netmask 255.0.0.0
network 10.0.0.0

#auto eth1:1
iface eth1:1 inet static
address 169.254.0.100
netmask 255.255.0.0
network 169.254.0.0

#auto eth1:2
iface eth1:2 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0

#auto eth1
iface eth1 inet dhcp

 XP:
 是在一張網卡上設定多ip,不過壞處是如果要改回dhcp還是必須變動
 
@echo off
netsh interface ip set address name="區域連線 2 " source=static addr=169.254.0.200 mask=255.0.0.0 gateway=169.254.0.1 gwmetric=30
netsh interface ip add address name="區域連線 2" 10.0.0.200 255.0.0.0 gateway=10.0.0.2 gwmetric=30
netsh interface ip add address name="區域連線 2 " 192.168.1.200 255.255.255.0 gateway=192.168.1.1 gwmetric=30


不過偶爾要小心如果發現設定完後不能透過另外一張網卡上網(ex:eth0,區域連線),通常需要手動調整routing table的順序