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) 否则可能会出现无法上网的情况

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