# VirtualBox - Networking problems (solution inside)



## astralfx (Jun 1, 2011)

I've followed every tutorial online slavishly (to the point of fricking up my system), tried every single difference, spent 3 days trying to get VirtualBox - bridged networking to function (installed, reinstalled virtualbox too many times, I can't compile the latest 4.0.8 version I get errors.. However I don't mind not having new version, currently running virtualbox 3.2.12 via pkg_add, with guestaddition installed).

But it refuses, I just don't understand what I'm missing:


```
[FILE][B]kldstat[/B] [/FILE]
Id Refs Address    Size     Name
 1   38 0xc0400000 bd97b4   kernel
 2    1 0xc0fda000 1c260    snd_hda.ko
 3    2 0xc0ff7000 56794    sound.ko
[B] 4    3 0xc104e000 2ec34    vboxdrv.ko[/B]
 5    1 0xc72e4000 8000     linprocfs.ko
 6    2 0xc72f3000 26000    linux.ko
 7    1 0xc739d000 3000     linsysfs.ko
 9    2 0xc73b9000 b000     netgraph.ko
10    1 0xc73cf000 4000     ng_ether.ko
12    1 0xc783d000 68000    radeon.ko
13    1 0xc78a5000 14000    drm.ko[B]
14    2 0xc7fe4000 5000     vboxnetflt.ko
15    1 0xc73b5000 3000     vboxnetadp.ko[/B]
```
I have script which sleep 1s, before running vboxnetadp.ko

On WIN7 which is the guess OS, it says "Connected to Unidentified network", but not connected to internet. However from WIN7 or freeBSD I can't ping each other, also WIN7 can't ping router (192.168.2.1), and in ipconfig it is assigned "Autoconfiguration IPv4: 169.254.36.8, with subnet 255.255.0.0. Which is obviously wrong and not connected to router.

/boot/loader.conf

```
..
vboxdrv_load="YES"
..
```

/etc/rc.conf 

```
..
vboxnet_enable="YES"
..
```

And a script, which loads, vboxnetflt.ko & vboxnetadp.ko
/usr/local/etc/rc.d/vboxbridgeup.sh

```
#!/bin/sh
kldload /boot/modules/vboxnetflt.ko
sleep 1
kldload /boot/modules/vboxnetadp.ko
```

In virtualbox, WIN7 settings, bridged adapter - re0 (which is wired), adapter type: Intel PRO/1000 MT desktop (82540EM)
- I tried changing to different adapters, networking still doesn't work to connect to router.. Also tried NAT, doesn't work either.

What am I doing wrong?


----------



## wblock@ (Jun 1, 2011)

astralfx said:
			
		

> I've followed every tutorial online slavishly (to the point of fricking up my system), tried every single difference, spent 3 days trying to get VirtualBox - bridged networking to function (installed, reinstalled virtualbox too many times, I can't compile the latest 4.0.8 version I get errors..



That's a clue that something isn't right with your system, and the first thing I'd work on fixing.



> On WIN7 which is the guess OS, it says "Connected to Unidentified network", but not connected to internet. However from WIN7 or freeBSD I can't ping each other, also WIN7 can't ping router (192.168.2.1), and in ipconfig it is assigned "Autoconfiguration IPv4: 169.254.36.8, with subnet 255.255.0.0. Which is obviously wrong and not connected to router.



The 169 address is what Windows gives itself when DHCP can't get a lease.  Or maybe when no address is assigned.



> And a script, which loads, vboxnetflt.ko & vboxnetadp.ko
> /usr/local/etc/rc.d/vboxbridgeup.sh
> 
> ```
> ...



These are not needed, just
/etc/rc.conf

```
vboxnet_enable="YES"
```


----------



## astralfx (Jun 1, 2011)

Ok I removed the package, and compiled it, here's the error:


```
kmk[2]: *** No rule to make target `/usr/src/sys/kern/bus_if.m', needed by `/usr/ports/emulators/virtualbox-ose/work/VirtualBox-
3.2.12_OSE/out/freebsd.x86/release/obj/FreeBSDGeneratedKernelHeaders/bus_if.h'.  Stop.
kmk[2]: Leaving directory `/usr/ports/emulators/virtualbox-ose/work/VirtualBox-3.2.12_OSE'
kmk[1]: *** [pass_installs_this] Error 2
kmk[1]: Leaving directory `/usr/ports/emulators/virtualbox-ose/work/VirtualBox-3.2.12_OSE'
kmk: *** [pass_installs_order] Error 2
*** Error code 2

Stop in /usr/ports/emulators/virtualbox-ose.
*** Error code 1

Stop in /usr/ports/emulators/virtualbox-ose.
```

What now :?


----------



## graudeejs (Jun 1, 2011)

What do you use, i386 or amd64? If it's amd64 I could give you the VBox 4 package (and it works perfectly fine here. I've been emulating entire virtual networks).


----------



## wblock@ (Jun 1, 2011)

4.0.8 works fine on i386 here.  Update the ports tree, make sure your kernel source matches the installed operating system, and rebuild emulators/virtualbox-ose and emulators/virtualbox-ose-kmod.


----------



## astralfx (Jun 1, 2011)

Hi thanks for the offer killasmurf86, unfortunately I use i386.

@wblock, how do I check that my kernel source matches the installed operating system.

Should I install emulators/virtualbox-ose-kmod first, or  emulators/virtualbox-ose


P.s. I tried to install with portmaster, and I get:

```
===>>> Launching 'make checksum' for devel/yasm in background
===>>> Gathering dependency list for devel/yasm from ports
===>>> Initial dependency check complete for devel/yasm
	emulators/virtualbox-ose >> yasm-1.1.0 
===>>> Continuing initial dependency check for emulators/virtualbox-ose
===>>> Launching child to install emulators/virtualbox-ose-kmod
	emulators/virtualbox-ose >> emulators/virtualbox-ose-kmod

===>>> Port directory: /usr/ports/emulators/virtualbox-ose-kmod

	===>>> This port is marked IGNORE
	===>>> requires kernel sources

	===>>> If you are sure you can build it, remove the
	       IGNORE line in the Makefile and try again.

===>>> Update for emulators/virtualbox-ose-kmod failed
===>>> Aborting update
```

I don't no where the IGNORE line is in Makefile? All I see that is related is:

```
RUN_DEPENDS=    /boot/modules/vboxdrv.ko:${PORTSDIR}/emulators/virtualbox-ose-kmod
```
Should I remove that line :?


----------



## kpedersen (Jun 1, 2011)

I could never get bridged mode to work in VirtualBox either. (I used the version that was provided in the ports collection on the 8.2-RELEASE cd)

NAT works fine but was tricky to run an XDMCP in the guest with it.

So I will be very interested if you can get this to work astralfx.


----------



## adamk (Jun 1, 2011)

For what it's worth, I haven't had any problems with bridged mode on virtualbox on a FreeBSD host (with an XP guest).  I just load vboxdrv from /boot/loader.conf and run */usr/local/etc/rc.d/vboxnet* on startup.

Adam


----------



## _martin (Jun 2, 2011)

I think this is a question suitable for VirtualBox forums.

Network problems you've described seem to indicate a deeper problem but note that you can't ping within VM running on virtualbox, e.g.:


```
mato@vblx01:(~)$ ping google.com
PING google.com (74.125.77.104) 56(84) bytes of data.
^C
--- google.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

mato@vblx01:(~)$ telnet google.com 80
Trying 74.125.77.99...
Connected to google.com.
Escape character is '^]'.
^C
Connection closed by foreign host.
mato@vblx01:(~)$
```
where vblx01 is my VM running on VirtualBox. 

To start from the scratch identify that VirtualBox kernel modules match vbox-ose version simply by quering installed packages either by pkg_info or ls command:

`# pkg_info |grep -i virtualbox`

```
virtualbox-ose-4.0.8 A general-purpose full virtualizer for x86 hardware
virtualbox-ose-kmod-4.0.8 VirtualBox kernel module for FreeBSD
```

`# ll /var/db/pkg/|grep -i virtualbox`

```
drwxr-xr-x    2 root  wheel      512 Jun  1 14:53 virtualbox-ose-4.0.8
drwxr-xr-x    2 root  wheel      512 May 22 20:39 virtualbox-ose-kmod-4.0.8
```

I don't use portmaster but it seems you don't have kernel sources installed. You can use sysintall or cvsup to get sources you need.
You didn't paste the VM's configuration so it's hard to say what's wrong with the network configuration itself. 

To give you some idea here's some chunks of my configuration. vblx01 is a VM running inside VirtualBox, 192.0.2.1 is my public IP address:

`# VBoxManage showvminfo vblx01 |grep ^NIC`

```
NIC 1:           MAC: 0800273CEB3E, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0
NIC 1 Settings:  MTU: 0, Socket( send: 64, receive: 64), TCP Window( send:64, receive: 64)
NIC 2:           MAC: 080027891E5C, Attachment: Host-only Interface 'vboxnet0', Cable connected: on, 
                       Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0
```

`# VBoxManage list bridgedifs`

```
Name:            em0
GUID:            00306d65-0000-4000-8000-001cc0115078
Dhcp:            Disabled
IPAddress:       192.0.2.1
NetworkMask:     255.255.255.128
IPV6Address:     <snip>
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 00:1c:c0:11:50:78
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-em0
```

NAT interface: 

`# VBoxManage list hostonlyifs`

```
Name:            vboxnet0
GUID:            786f6276-656e-4074-8000-0a0027000000
Dhcp:            Disabled
IPAddress:       192.168.252.254
NetworkMask:     255.255.255.0
IPV6Address:     fe80:0005:0000:0000:0800:27ff:fe00:0000
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 0a:00:27:00:00:00
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0
```


----------



## wblock@ (Jun 2, 2011)

adamk said:
			
		

> For what it's worth, I haven't had any problems with bridged mode on virtualbox on a FreeBSD host (with an XP guest).  I just load vboxdrv from /boot/loader.conf and run /usr/local/etc/rc.d/vboxnet on startup.



Works for me, too.  The network kernel module can be loaded automatically with
/etc/rc.conf

```
vboxnet_enable="YES"
```

I rarely use bridged, so I don't enable vboxnet in /etc/rc.conf.  Instead, I just start the service manually:
`# service vboxnet onestart`


----------



## wblock@ (Jun 2, 2011)

astralfx said:
			
		

> @wblock, how do I check that my kernel source matches the installed operating system.



It works on i386, I use it often.  You don't need to check source against what you have installed, because the problem below shows you don't have any source at all.



> Should I install emulators/virtualbox-ose-kmod first, or  emulators/virtualbox-ose



Doesn't matter, the kmod port will be installed as a dependency.



> ===>>> Port directory: /usr/ports/emulators/virtualbox-ose-kmod
> 
> ===>>> This port is marked IGNORE
> ===>>> requires kernel sources
> ...



Try the first solution suggested: get the kernel source with csup(1).  Or I've heard freebsd-update(8) can do it, but haven't tried that.  Get the version of source that matches what uname(1) shows.


----------



## astralfx (Jun 2, 2011)

Hi NAT works when I run [cmd=]service vboxnet onestart[/cmd] I can connect to the internet, and it auto-assigns the guest OS an IP.

```
IPv4 Addr: 10.0.2.15
Default gateway: 10.0.2.1
```

However the main thing I need is the machine to be assigned an IP via my router (192.168.2.x network) since I don't really care for internet in the virtual machine, I need the WIN7 OS to be in my network with an individual IP.

[cmd=]pkg_info |grep -i virtualbox[/cmd]

```
virtualbox-ose-3.2.12 A general-purpose full virtualizer for x86 hardware
virtualbox-ose-kmod-3.2.12 VirtualBox kernel module for FreeBSD
```

[cmd=]ll /var/db/pkg/|grep -i virtualbox[/cmd]

```
drwxr-xr-x  2 root  wheel       512 Jun  2 01:38 virtualbox-ose-3.2.12
drwxr-xr-x  2 root  wheel       512 Jun  2 01:38 virtualbox-ose-kmod-3.2.12
```

[cmd=]VBoxManage list bridgedifs[/cmd]

```
GUID:            00306572-0000-4000-8000-00238b9ec90e
Dhcp:            Disabled
IPAddress:       192.168.2.2
NetworkMask:     255.255.255.0
IPV6Address:     
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 00:23:8b:9e:c9:0e
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-re0
```

[cmd=]VBoxManage showvminfo "Windows 7" |grep ^NIC[/cmd]
... shows nothing (the name of machine is Windows 7)


----------



## carlton_draught (Jun 2, 2011)

The only time I have not been able to get virtualbox to work with bridged network was when I was trying to use VLANs and the network card on the machine I was using had a problem with them (or maybe it was in conjunction with virtualbox). Other than that, it's working fine.


----------



## wblock@ (Jun 2, 2011)

astralfx said:
			
		

> NAT works when I run [cmd=]service vboxnet onestart[/cmd] I can connect to the internet, and it auto-assigns the guest OS an IP.
> 
> ```
> IPv4 Addr: 10.0.2.15
> ...



Yes, but vboxnet is not needed for NAT.  It is needed for bridged mode.



> However the main thing I need is the machine to be assigned an IP via my router (192.168.2.x network) since I don't really care for internet in the virtual machine, I need the WIN7 OS to be in my network with an individual IP.
> 
> [cmd=]pkg_info |grep -i virtualbox[/cmd]
> 
> ...



No idea why you're sticking with 3.2.12 when 4.0.8 is out.  Oh well.

I use the Qt interface, but you should be able to set the VM to bridged from the command line:
`% VBoxManage modifyvm "Windows 7" -nic1 bridged`

(Untested.)  That space in the VM name provides zero extra readability and will make your life more difficult, but some people like that.

Of course the VM has to do a DHCP request or use a static IP.


----------



## astralfx (Jun 2, 2011)

Hi wblock, I can't install virtualbox 4.0.8 because I get errors (pointed out in above posts). And I don't know exactly what I need to do, I don't get what it means by get kernel source, for what (my OS, or virtual box.. I don't understand)?

P.s. I tried your command, alas it didn't work. And I also renamed the virtual machine to "Windows7"
- Also tried setting static IP, in WIN7 and default gateway. However it doesn't connect to router


----------



## wblock@ (Jun 2, 2011)

astralfx said:
			
		

> Hi wblock, I can't install virtualbox 4.0.8 because I get errors (pointed out in above posts). And I don't know exactly what I need to do, I don't get what it means by get kernel source, for what (my OS, or virtual box.. I don't understand)?



The errors you show are for 3.2.12, meaning it's an old ports tree.

Please read Upgrading FreeBSD Ports before continuing.  It shows how to update your ports tree.

As far as the rest, a vaguely-worded answer like "get kernel source" is a clue to do some searching and reading.  "FreeBSD get kernel source" typed into a search engine goes straight to the Handbook section on doing that.

The example command was missing a dash:
`% VBoxManage modifyvm Windows7 --nic1 bridged`
(Tested.)


----------



## astralfx (Jun 2, 2011)

Hi, I noticed it was --nic1

Anyway, I updated virtualbox-ose/additions/kmod to 4.0.8.

I also didn't have a /usr/src/sys - so I installed the src files

For anyone, who has *kernel sources* missing, just do

```
sysinstall
- choose Configure, Distribution, src, ALL
- EXIT [from top]
- Installation media: FTP
```
(Then all kernel sources installed), also just in case symlink didn't create:
`ln -s /usr/src/sys/ /sys/`

Now I am compiling virtualbox-ose and it got past the error, however it's taking very long, been compiling for over 2 hours now. And it's added about 10 dependencies (or maybe upgrading them, not sure), and compiling them all. The heck (this is the second longest port I've had to ever compile, the first being xorg which took the whole night -___- Didn't think VirtualBox was this big)


----------



## astralfx (Jun 2, 2011)

*HUZZZZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHH*

It works, I'm connected to my router with an individually assigned IP & both FreeBSD (hsot) can ping WIN7 (guest) .. And it has internet access 

Here's what I did, if any newcomer has problems in the future (p.s. make sure you have kernel sources, details in previous post):


```
# [b]make deinstall [file]virtualbox-ose virtualbox-ose-additions virtualbox-ose-kmod[/file][/b]
# [b]rm -rf[/b] [file]/files/[/file] (from the 3 above virtualbox directories, to remove old downloaded files)
# portdowngrade [file]virtualbox-ose[/file] -s pserver:anoncvs@anoncvs.tw.FreeBSD.org:/home/ncvs
(using portdowngrade to upgrade ports :P repeat command for all 3)
# (Then chose option [b][1][/b] for latest port)
# (After they download/updated, I did [b]make config[/b], on each of the 3 directories to confirm there 4.0.8) 
- added [b]Guest additions[/b] to [file]virtalbox-ose - make config[/file])
# [b]portmaster /usr/ports/emulators/virtualbox-ose[/b] (starts the compiling)
```

- It will update some dependencies, and may add new ones. Just accept them all.
It took me 3 hours to compile, though my laptop isn't the fastest in the world
(2.3 Ghz AMD Turion X2, Dual-Core)

- Once it's done, restart machine, make sure "Bridged networking", is enabled with your ethernet adapter

*- Then you'll yell "HUZZZAAAAHHHHH" once your connected to your network*







p.s. make sure you have

```
[file]/boot/loader.conf[/file]
vboxdrv_load="YES"
```


```
[file]/etc/rc.conf[/file]
vboxnet_enable="YES"
```

P.s.s. I may as well add how to set shared folders since I've pretty much explained the rest of installing VirtualBox, this is relatively simple.
- Assuming everything installed correctly in the previous parts, and you *CHOSE* "Install Guest Additions" in your virtualbox-ose make config
- First create your shared folder in freeBSD (I created mine in ~/.VirtualBox/
- In the settings of the your machine, add the shared folder
- Load up guest OS, then go to Device > CD/DVD device > Choose a device..
(Browse to /usr/local/lib/virtualbox/additions - and choose VboxGuestAdditions_4.0.8.iso since this is the version were using)
- Then it will load CD in guest OS, install it
- Reboot when asked
- Then when you come back, for windoze - it's under "Network" the shared folder


----------



## wblock@ (Jun 3, 2011)

astralfx said:
			
		

> ```
> # [b]make deinstall [file]virtualbox-ose virtualbox-ose-additions virtualbox-ose-kmod[/file][/b]
> # [b]rm -rf[/b] [file]/files/[/file] (from the 3 above virtualbox directories, to remove old downloaded files)
> # portdowngrade [file]virtualbox-ose[/file] -s pserver:anoncvs@anoncvs.tw.FreeBSD.org:/home/ncvs
> ...



That is the most creative way to update the ports tree I've seen in a while, but it does a partial job that will break things if the rest of the ports are old.  It's a lot more work than
`# portsnap fetch update`


----------

