How To: Make VirtualBox Use Your Router’s DHCP to get an IP Address in Linux_the first address assigned to ipv6 virtual router -程序员宅基地

技术标签: path  linux  translation  windows  command  network  

How To: Make VirtualBox Use Your Router’s DHCP to get an IP Address in Linux

http://r3dux.org/2009/09/how-to-make-virtualbox-use-your-routers-dhcp-to-get-an-ip-address-in-linux/

r3dux | September 5, 2009

Update: The method below for getting a virtualbox IP from your DHCP works (in linux) – but it turns out there’s an easier way (kindly pointed out byMike in the comments below). You can just change your VirtualBox network settings fromNAT to Bridged Adapter and point it at eth0/wlan0 or whichever connection is being used for networking. Then, optionally, you can configure the MAC address of the bridged adapter and set your router to assign a specific IP to a specific bridged adapter. Also, the built-in Bridged Adapter method works to deploy solutions from XNA Game Studio to my Xbox 360, so I’m rapt! Thanks, Mike!

VirtualBox Bridged Adapter Settings

Note: The below bit is for linux only, the above method should work on any host OS!


VirtualBox is an awesome bit of kit and I <3 it long time ten-dorrah.

But by default when your virtual copy of Windows/Linux/Solaris/Whatever grabs an IP address, it does so throughNAT, and at version 3.0.4, this means it gives us a defaultCategory A network address (i.e. 10.x.y.z).

It’s a working cat-A address, as in it’s fully functional and can talk to the Internet and all that, but sometimes life is a lot easier if you have an IP in the same range as the DHCP pool your router is dishing out. For example, my lappy is 192.168.1.101 internally, my Wii might be 192.168.1.102, the NAS .103 etc, so I want my virtualboxen to take addresses like .104, .105 and such.

I’m doing this to bridge my wireless connection on wlan0, if you’re bridging an ethernet connection substitute eth0 or whatever connection as necessary.

Also, to perform the bridging using this method, you’ll need some tools (feel free tosudo apt-get install NAME-OF-TOOL as necessary):
- 1.) uml-utilities
- 2.) parprouted
- 3.) bcrelay

Now, with that lot installed, run the following commands (provided here in bash script form):

#!/bin/bash
 
# To use this script you will need the following utilities installed:
# 1.) uml-utilities 2.) parprouted  3.) bcrelay
# sudo apt-get install 'em
 
# Enable IP forwarding
sudo sysctl net.ipv4.ip_forward=1
 
# Create a TAP as your current logged in user (replace with -u YOUR-USER-NAME if you want...)
sudo tunctl -u $USER
 
# Tell tap0 to respond to ARP (Address Resolution Protocal) packets 
sudo sysctl net.ipv4.conf.tap0.proxy_arp=1
 
# Give your TAP (tap0) an IP address and enable it (make sure the IP address is OUTSIDE the DHCP range on your router)
sudo ip addr add 192.168.1.150/32 dev tap0
sudo ip link set tap0 up
 
# Run parprouted and make it add routes automatically for wlan0 and tap0 as needed
# Make the command "parprouted -d wlan0 tap0" to display routes added and additional info. No sudo necc. for this one.
parprouted wlan0 tap0
 
# Use bcrelay on your net connection and TAP to "rewrite the layer-2 header and forward broadcast messages between network interfaces"
# The "-d" in this instance MAKES bcrelay work as a daemon. Need to sudo this or it doesn't work.
sudo bcrelay -d -i tap0 -o wlan0

Now, fire up VirtualBox and for your machine of choice change the network selection from NAT to tap0 as shown:

VirtualBox-tap0

Then boot up your virtual machine and check the IP:

VirtualBox-bridged-IP

Great. Super. Smashing. =D

Note: The entire reason I wanted to grab an IP from the router was so my virtual copy of XP could be on the same network as my XBox 360, so I could deploy games to it throughXNA Studio 3.1, however XNA Studio is very fussy about timing when it comes to registering the 360, and although it can see the 360 using the bridge, and it tries to connect, it times out before it can fully establish a connection. I guess I’ll have to go with an IP routes method of bridging if I want it to work for that purpose, but as yet I haven’t quite figured it all out. Will keep trying when I have time, or if you know a way, feel free to call me technically incompetent and sling a solution in the comments! Cheers!




文件共享是Virtualbox 虚拟机和宿主机之间通信的工具。



从虚拟机中或许不能ping宿主机(win7)

在防火墙中 添加自定义策略:
a. 在控制面板中打开“Windows Firewall” (Control Panel All Control Panel ItemsWindows Firewall), 选择“Advanced Settings”
b. 右击“Inbound Rules”,选择“New Rule”,选“Custom”,下一步,选“All Programs”, 下一步,Protocol选择“ICMPv4”,下一步,设置本地和远端受限IP(根据情况设置,我这里设置 remote IP address 为IP段: 选 These IP Address,然后点Add添加Guest虚拟机所在的IP段), 下一步,默认, 下一步,默认,最后,输入防火墙规则名称和注释。
c. OK


http://www.dedoimedo.com/computers/virtualbox-network-sharing.html

This links explains the network sharing and folder sharing.

Adapter Type defines the virtualized hardware that VirtualBox will expose to your virtual machine.


Network Address Translation (NAT)

NAT means the virtual machines will have private IP addresses that are not routable from outside.

Your host is 192.168.1.1. The VirtualBox NAT device will be marked as 10.0.2.1.


Bridged Adapter:

Bridged Adapter means that any virtual machine running will try to obtain an IP address from the same source your currently active, default network address got its IP address. Hence the term bridged, as the two are connected.

Example: Your host has leased an address of 192.168.1.100 from the router. The virtual machine leases an address of 192.168.1.103 from the router. The two machines now share the same network and all standard rules apply. For all practical purposes, the virtual machine is another IP address on your LAN.

Host-only Adapter

Host-only Adapter is very interesting. It's very similar to Bridged Adapter, except that is uses a dedicated network device, called vboxnet0(linux) or Virtual Box Host Only Ethernet adapter, to lease IP addresses. 

Your host machine is the de-facto VirtualBox router, with the IP address of 192.168.56.1. The adapter is not in use if there are no virtual machines running with Host-only setup. However, once they come up, this adapter serves IP addresses to the virtual machines, creating an internal LAN, within your own network.

Example: Your host has the IP address of 192.168.56.1. Your virtual machine has the IP address of 192.168.56.101.

mask: 255.255.255.0


Sharing via network

Earlier, we mentioned that sharing via network is only possible for Bridged and Host-only network. Let's see two examples. The first step is to allow sharing in the guest machine.

Enabled

Then, you access the virtual machine via its IP address.

On Windows:

On Windows, use Start > Run > \\XXX.XXX.XXX.XXX and replace the triplets of Xs with the actual IP of the virtual machine.

On Linux:

Type smb://XXX.XXX.XXX.XXX in the address bar of the file manager. smb:// stands for the Samba network protocol. The triplets of Xs stand for the IP address of our guest machine.

With Bridged networking, it looks like this:

Success

With Host-only, it looks like this:

Success

Ignore the title Windows shares. Samba is usually used to share with Windows hosts. NFS is more typically used for Linux machines. Samba is preferred, because it works with both. For more about Samba sharing, please take a look at this tutorial.

Shared Folders

P.S. All of the above is identical for Windows and Linux guests, by the way. To this end, I decided to take the last set of screenshots demonstrating Shared Folders on a Windows machine.

Now, Shared Folders are quite simple to setup. Your first step is to configure a folder on your host that you wish to share. For any virtual machine, open the Settings menu and go to Shared Folders.

In the right pane, you will have a list of all shared folders on the machine. You can add and remove them as you see fit. The little icons to the right are used for that purpose.

Setup

Add new

Folder Path:

This is the actual, physical path that you wish to share. On Windows, the folder path will be something like C:\shared. On Linux, it will look something like /home/roger/shared.

Folder Name:

This is the name of the share that your guests will see. Please use names without spaces, something like Shared-folder or Banana. This name can be identical to the actual folder you're sharing, but it does not have to be. But please note, this is not a path! It's a symbolic name for virtual machines to use, as they do not see your physical hardware.

Once you've created the path, boot you virtual machine.

On Windows:

If your virtual machine is a Windows host, you can access the network share either via the command line or using the Tools > Map Network Drive option in the Explorer menu.

On the command line, you need to use the net use command.

net use <drive letter> \\vboxsvr\share-name

net use is the command for mounting network drives.

<drive letter> is the drive that will be assigned the share inside your virtual machine. It can be any free letter, like E:, G:, X:, etc.

\\vboxsvr\share-name is the path to the share. \\vboxsvr is the VirtualBox sharing server. share-name is the actual folder name from earlier. So if you called your share Rambo, then the path reads \\vboxsvr\Rambo.

The command then looks like:

net use h: \\vboxsvr\Rambo

Via the Tools menu in the Explorer, it looks like this:

Example

You can check Reconnect at logon, so you don't have to repeat this task every time you power on the virtual machine. Once you click Finish, you will have a new drive under your My Computer. Opening this new drive letter will take you into the Shared folder.

On Linux:

This is done by a simple command in a terminal windows:

mount -t vboxsf share mount_point

vboxsf is the pseudo-filesystem type used to mount the Shared Folder. It's an abstract translation layer for the virtual sharing service used by VirtualBox.

share is the name of the folder from earlier. Remember, the name and not the path! For example, if our share is called Banana then share = Banana.

mount_point is any directory in your Linux tree where you wish to mount the Shared folder to. For example, /home/roger/shares-go-here.

Thus, our command looks like:

mount -t vboxsf Banana /home/roger/shares-go-here

And then, everything that is inside the shared folder on your host will be visible inside the virtual machine by going to the above path.

To automate the task, you can add the mount option to the /etc/fstab menu. Again, for more details on how to do this, please refer to my Linux commands tutorial.

BTW, notice the help in the Settings menu, explaining how to achieve this!

Help









版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/techradio/article/details/7606580

智能推荐

JVM内存模型&&垃圾回收_java 堆和 native 堆之间来回复制数据-程序员宅基地

文章浏览阅读189次。概述:虚拟机自动内存管理机制下,不再需要像C/C++程序开发程序员这样为内一个new 操作去写对应的delete/free操作,不容易出现内存泄漏和内存溢出问题。正是因为Java程序员把内存控制权利交给Java虚拟机,一旦出现内存泄漏和溢出方面的问题,如果不了解虚拟机是怎样使用内存的,那么排查错误将会是一个非常艰巨的任务运行时数据区域:Java虚拟机在执行Java程序的过程中会把它管理的内存..._java 堆和 native 堆之间来回复制数据

linux 开启审计服务,Linux审计服务Auditd systemctl重启问题解决-程序员宅基地

文章浏览阅读1.5k次。在RHEL7&&CentOS7时代,默认的服务通过systemd控制,并通过systemctl命令完成启停。但是并不是所有的服务都可以完美的通过systemctl来控制,比如今天要提到的Auditd编辑audit.rules添加规则后,当然要通过restart服务来重启生效,但是通过systemctl restart auditd就会报如下错误:[root@abc]# syste..._failed to restart auditd.service: operation refused, unit auditd.service may

设计模式17 - 中介者模式-程序员宅基地

文章浏览阅读259次。作者:billy版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处中介者模式使用场景优缺点注意事项UML结构图代码实现..._中介者模式

【剑指offer】面试题18:树的子结构_{ *t=(bitree )malloc(sizeof(bitnode)); if(!*t) exi-程序员宅基地

文章浏览阅读552次。题目描述:输入两颗二叉树A,B,判断B是不是A的子结构。题目解析:_{ *t=(bitree )malloc(sizeof(bitnode)); if(!*t) exit(-1); (*t)->data

IIS占用CPU%问题排查方案 _排查iis消耗资源语句-程序员宅基地

文章浏览阅读2.6k次。有时候辛辛苦苦写个网站,挂到服务器上一看,CPU给百分百了,这种问题百分之八九十都是因为代码写有问题,而不是因为系统设置的问题,这种问题也比较难排查。但是结合一些工具也可以找到原因的,关于windbg的使用,好像有本关于.net调试的书,大家有兴趣可以看看,网上也有一些帖子,但关于ANTS Profiler的帖子就比较少了,大家也可以下载试用版来帮助解决问题1 准备日志1.1 _排查iis消耗资源语句

Springboot 项目导出word文档(文档内容包括数据以及服务器图片)_项目实体类批量导出到word-程序员宅基地

文章浏览阅读1.4w次。Springboot 项目freemarker导出word文档(文档内容包括数据以及服务器图片)前些天有需求要完成导出word文档功能,基础数据导出word文档,网上也能搜到很多源代码,但是我这边要求是服务器上的图片(只给出服务器图片路径,从服务器得到图片),前前后后加起来就不好内容了,网上并没有找到处理这种的代码和解决方式,只好自己写了,弄完了来记录下,防止以后再用.首先动手之前整理下思..._项目实体类批量导出到word

随便推点

SparkSql中的repartition 与 coalesce_spark sql repartition-程序员宅基地

文章浏览阅读3.9k次。SparkSql的repartition和coalesceSparkSql 写hive小文件后记repartition(numPartitions:Int)和coalesce(numPartitions:Int,shuffle:Boolean=false)作用:对RDD的分区进行重新划分,repartition内部调用了coalesce,参数shuffle为true例:RDD有N个分区,需要..._spark sql repartition

【Android】帧动画(Drawable Animation)_帧动画 一个drawable-程序员宅基地

文章浏览阅读650次。今天总结下帧动画 原理: 对几张图片按照顺序一张一张进行播放,视觉上感觉是连续播放的动画效果。 一.步骤: 1.在res/drawable放入几张图片 2.在res/drawable下新建一个drawable resource file,比如命名为gril_animation.xml,根节点选择animation-list,点击ok 3.编辑gril_animation.xml文件_帧动画 一个drawable

树莓派python交互界面实例_树莓派综合项目2:智能小车(二)tkinter图形界面控制...-程序员宅基地

文章浏览阅读858次。一、介绍树莓派综合项目2:智能小车(一)四轮驱动中,实现了代码输入对四个电机的简单控制,本章将使用Python 的图形开发界面的库——Tkinter 模块(Tk 接口),编写本地运行的图形界面,控制小车的前进后退、转向和原地转圈。Tkinter是Python的标准GUI库,Python使用Tkinter可以快速的创建 GUI 应用程序。由于 Tkinter 是内置到 python 的安装包中、只要..._树莓派 例子 交互

Yarn install报错 【错误: 找不到或无法加载主类 install】_yarn install error: could not find or load main cl-程序员宅基地

文章浏览阅读6.5k次,点赞4次,收藏12次。今天要运行一个项目,首先在初始配置阶段要执行 yarn install 结果出现了下面的报错: 执行 yarn --version报错如下: 执行 yarn version结果如下: 网上查资料的时候看到一篇相关的文章,可以参考解决问题: 这也是我尝试解决问题的思路,这里给出来的说法是,原始的java安装环境里面已经有yarn了,新安装的yarn的环境变量需要放在它前面。 接下来下载yarn,我是在..._yarn install error: could not find or load main class install

CSS实现div竖向排版_div竖着排列-程序员宅基地

文章浏览阅读2.3k次。1.最多显示四行,自动换列 2.均分成3列_div竖着排列

数学系教材推荐-程序员宅基地

文章浏览阅读323次。 解析几何解析几何有被代数吃掉的趋势,不过就数学系的学生而言,还是应该好好学一下,我大一没有好好学,后来学别的课时总感觉哪里有些不太对劲,后来才发现是自己的数学功底尤其是几何得功底没有打好。1吴光磊《解析几何简明教程》高等教育出版社写的简单明了,我基础没有打好,快速翻了一下这本书收获还是不少的。不过打基础的时候还是从下面三本选一本看,把这本当参考书。2《解析几何》丘维声,北京大...

推荐文章

热门文章

相关标签