Ubuntu 虛擬網卡設定方式

今天需要在自己的Linux上新增一個虛擬的網段來滿足一些需求,於是就上網查了一下設定方式,順手做個筆記避免日後遺忘,順便提供給各位參考摟。


# sudo vi /etc/network/interfaces 增加虛擬網卡設定
auto eth0
iface eth0 inet static
address 192.168.1.253
netmask 255.255.255.0
gateway 192.168.1.254

====以下為虛擬網卡設定====
auto eth0:0
iface eth0:0 inet static
address 192.168.2.253
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
====以上為虛擬網卡設定====

# sudo /etc/init.d/networking restart 重新啟動網路服務
* Reconfiguring network interfaces…                                                  
SIOCSIFFLAGS: Cannot assign requested address                  [ OK ]

# route  確認是否有新增虛擬網卡的Route產生
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     *               255.255.255.0   U     0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
default         my.router       0.0.0.0         UG    100    0        0 eth0

# ping 192.168.1.100
  測試192.168.1.X 是否連線
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=128 time=0.112 ms
64 bytes from 192.168.1.100: icmp_seq=2 ttl=128 time=0.116 ms
— 192.168.1.100 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.112/0.114/0.116/0.002 ms

#ping 192.168.2.100
測試192.168.2.X 是否連線
PING 192.168.2.100 (192.168.2.100) 56(84) bytes of data.
64 bytes from 192.168.2.100: icmp_seq=1 ttl=128 time=5.22 ms
64 bytes from 192.168.2.100: icmp_seq=2 ttl=128 time=0.122 ms
— 192.168.2.100 ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1006ms
rtt min/avg/max/mdev = 0.122/2.671/5.221/2.550 ms

以上就是在Ubuntu上面新增一張虛擬網卡的方式


用LINE傳送
加入LINE頻道 加入TG頻道

Leo
Leo

喜愛旅遊並沉迷科技應用數十年無法自拔的重度 3C 上癮者!

發表迴響