Routing traffic from Windows host machine to OpenWrt on Virtualbox

I have Openwrt up and running on Virtualbox on a Windows machine, connected to the modem by ethernet. This means that I do not have a physical router, only a virtual one on Virtualbox. Is there a step by step guide I could follow to route my internet traffic on that Windows machine through the virtual router?

You simply set the network card connected/attached to LAN as a Bridged Interface in VirtualBox (:spiral_notepad: LAN is usually the first interface defined in OpenWrt, WAN is second). The Windows machine should get an IP automatically, as usual.

If you don't wanna use or don't have a second PHY, you can use the Host-Only Adapter (it can be added to a br-lan, but that gets more complex).

It's really out of the scope of OpenWrt on how you connect to the PHYs - but I hope that give you 2 simple methods.

By that you mean i go to network setting for openwrt vm on virtualbox and set Adapter 1 to "bridge adapter" like this?


I immediately lost access to luci and cannot ssh to openwrt at 192.168.56.2 anymore.

I cannot guess:

  1. You have to explain how you're physically connected
  2. I also mentioned host-only
  • Not enough information

  • How did you have access before? (I understood that was the issue you wanted to resolve)

  • Why do you wish to change it?

  • If you had access, then it was setup correctly.

  • Did you bridge LAN in OpenWrtto the other new interface - as I noted?

Adapter 1 was originally Host-only adapter. I changed it following your advice, hopping it would route my windows machine traffic through openwrt.

You didn't follow my advise it seems, then.

So you would bridge a new adapter and the host-only. This is done in OpenWrt.

:spiral_notepad: It may also help if you actually answer - how many PHYs you really have.

1 - the windows machine. I don't have a dedicated router.

I'm really trying to follow but honestly I am new and some of what you say really doesn't make sense to me.

Understood.

:+1:

So it was already working, then?

(You failed to mention Windows already had LAN access and IP from the OpenWrt on a host-only adapter.)

Can you provide the results of:

  • tracert 8.8.8.8 - from the Windows machine
  • Traceroute results to 8.8.8.8 from the the LuCI web GUI

Thanks.

:spiral_notepad: To be clear - you setup Adapter 2 as bridged to the Ethernet/ISP, correct?

Screenshot_20230206-063822_Samsung Internet

Currently it is NAT

Disregard. This was before you provided accurate information.

  1. Do not touch Adapter 1
  2. Fix Adapter 2 to connect to Internet

Simple.

Again:

We're on Step 2.

  • Does it work???
  • Traceroute results??

(I don't understand why you told me it's NAT.)

:warning: If you mean you set VirtualBox's Adapter 2 "Attached To" setting as NAT instead of Bridged Adapter, fix this.

currently as NAT it is working. here are the result.

I will try again as bridged

Wait!

It's working?!?!

Then it's OK, correct?

What are you trying to fix, then?

:spiral_notepad: Please provide both traceroute/tracert results for NAT.
(It's difficult when you don't provide all requested information in a single post.)

With adapter 2 as bridged, luci's traceroute returns "traceroute: can't connect to remote host (8.8.8.8): Network unreachable"

I can't upload 2 imgs as new user

If NAT is working - then it should be OK.

(Please follow posts.)

Again:

You don't have to take pictures. You can copy/paste. In any case, you still haven't provided the needed information.

host:

over a maximum of 30 hops:

1 13 ms 19 ms 14 ms 10.61.242.195
2 9 ms 8 ms 8 ms po-316-316-rur402.bellevue.wa.seattle.comcast.net [24.153.84.165]
3 9 ms 10 ms 9 ms 96.216.61.61
4 11 ms 10 ms 12 ms be-300-arsc1.seattle.wa.seattle.comcast.net [24.124.128.89]
5 12 ms 13 ms 11 ms 50.222.176.214
6 14 ms 12 ms 12 ms 142.251.50.41
7 11 ms 14 ms 13 ms 142.251.55.201
8 11 ms 10 ms 11 ms dns.google [8.8.8.8]

luci:
traceroute to 8.8.8.8 (8.8.8.8), 20 hops max, 46 byte packets
1 10.0.3.2 0.432 ms
2 *
3 *
4 *
5 *
6 *
7 *
8 *
9 *
10 *
11 *
12 *
13 *
14 *
15 *
16 *
17 *
18 *
19 *
20 *

1 Like

Somehow I think your LAN and WAN interfaces are reversed on VirtualBox.


  • In OpenWrt with default settings
  • Adapter 1 should be LAN - connected to a host-only adapter. Windows should get it's IP from the OpenWrt
  • Adapter 2 should be WAN - Bridged to the ISP thru your real PHY

This works in default OpenWrt.

:warning: If you loose connection, make sure both Adapter 1 and Adapter 2 are reset; and you get the correct IP from OpenWrt's LAN on the Windows machine. It is expected you will briefly loose connectivity while fixing this setting.

Is this what you want?


Even after restarting the openwrt vm with that setting and going to luci again, my traceroute is still "Network unreachable"

I also believe we need to clarify, are you by any chance thinking that I am asking how to get openwrt on virtualbox to connect to the Internet? If that's the case then it is not what I am asking. I follow the wiki's guide and have it working already. What I want to ask is how I can pass traffic on the host machine through openwrt on vm first (to apply vpn, QoS, etc.), instead of host machine going directly to internet regardless of openwrt.

I was thinking that indeed, my sincere apologies. Perhaps then, you should clarify the inquiry in your first post (because at least to me, that's exactly what you seem to be asking).

This requires connecting the OpenWrt router on VirtualBox to the Internet. :wink:

  • What does this mean?
  • How do you intend to go "through Openwrt" instead of the host machine going directly to the Internet - but also "regardless" of OpenWrt? :man_shrugging:

If the first boot of an x86 install only finds one eth adapter, it will not create a wan network interface. In that case you would need to create one manually and attach it to the second adapter. The name should be exactly 'wan' (lower case) -- that name is already in the default firewall--, the protocol DHCP Client, and the Device eth1 or whichever virtual port is bridged to the cable modem.

2 Likes