Vbox 上網與共享網絡配置

我們在使用VBOX 安裝Ubuntu虛擬機的時候,經常容易碰到一個現象,當我們將網卡設置成“網絡地址轉換(NAT)”的時候,能上網,但是IP與主機的不在一個網段,能上網,卻不能使用SAMBA共享,將網絡設置成“橋接網卡”,網段與主機一致卻不能上網。使用過程中經常需要切換網卡模式,顯得很繁瑣。


解決方式:

1,第一步在配置虛擬機的時候,開啓兩張網卡
2,將網卡一設置成 --網絡地址轉換(NAT)
3,將網卡二設置成–橋接網卡

開機查看網卡信息

VirtualBox:~$ ifconfig 
eth0      Link encap:Ethernet  HWaddr 08:00:27:53:de:0a  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::14a4:25e1:39b2:541f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4248 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2081 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:734042 (734.0 KB)  TX bytes:220577 (220.5 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:88:82:37  
          inet addr:192.168.1.21  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::9bfc:2f41:968b:43cd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8673 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2947 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:807596 (807.5 KB)  TX bytes:5095522 (5.0 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:712 errors:0 dropped:0 overruns:0 frame:0
          TX packets:712 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:110242 (110.2 KB)  TX bytes:110242 (110.2 KB)

用ping 檢測網絡狀況—本地局域網

VirtualBox:~$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=128 time=0.937 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=128 time=0.925 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=128 time=1.08 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=128 time=1.02 ms
64 bytes from 192.168.1.1: icmp_seq=5 ttl=128 time=1.07 ms
64 bytes from 192.168.1.1: icmp_seq=6 ttl=128 time=1.49 ms
64 bytes from 192.168.1.1: icmp_seq=7 ttl=128 time=1.03 ms
64 bytes from 192.168.1.1: icmp_seq=8 ttl=128 time=0.983 ms
^C
--- 192.168.1.1 ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7023ms
rtt min/avg/max/mdev = 0.925/1.067/1.492/0.174 ms

互聯網

VirtualBox:~$ ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=53 time=6.63 ms
64 bytes from 14.215.177.38: icmp_seq=2 ttl=53 time=6.93 ms
64 bytes from 14.215.177.38: icmp_seq=3 ttl=53 time=6.70 ms
64 bytes from 14.215.177.38: icmp_seq=4 ttl=53 time=12.0 ms
64 bytes from 14.215.177.38: icmp_seq=5 ttl=53 time=7.11 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4010ms
rtt min/avg/max/mdev = 6.638/7.879/12.014/2.075 ms

注意一定要將網卡一(eth0)做成—網絡地址轉換(NAT) 否則可能會出現無法上網的情況

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章