How to use a VPN with Virtualbox

This is for discussing general topics about how to use VirtualBox.
Post Reply
andrieuserge
Posts: 5
Joined: 15. Apr 2021, 17:28

How to use a VPN with Virtualbox

Post by andrieuserge »

Hello, I would like to know if anyone knows how to make a vpn work with virtualbox, first of all what configuration in the network settings of my virtual machine I have to use (bridge access, NAT, Allow all, etc.) then I also want there to be the same local ip address on the 2 pc's (mine and the vm) because it is not the case.

On another forum a person said to me "put a static ip address in the virtual machine", first of all is this going to solve my problem of local ip addresses that are not the same if it is the case someone could developp what he meant by that

sorry if my questions may seem stupid, cordially
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: IMPORTANT - How to use a VPN with Virtualbox

Post by scottgus1 »

Good questions, but it may be that you'll have to experiment.

BTW, duplicate posts is a big no-no here. I whacked the other one.

Lest we go down a rabbit hole on an "XY problem", why do you need the same IP address in host and VM? This requirement can lead to lots of trouble if the two OS's attach to the same network.

The requirement for the same ip address in host and VM makes it appear you want to run two VPN's, one on the host and one in the VM. A VPN running in the host will likely take in the VM's network connection if using Bridged or NAT, thus interfering with the VM's VPN.

Even if you don't want to run two VPN's, the same IP address in both host and VM will interfere with network delivery (It's like two houses on the same street with the same house number: where does the mail carrier deliver the mail?)

If you must have the same IP address on the host and the VM, you'll probably need two separate network connections. Use the host's network connection for the host OS, and a USB network adapter with a Virtualbox USB filter on the VM. USB basics and troubleshooting Don't use Bridged or NAT, use only the USB device.

With two network connections, each OS can be set up separately.
andrieuserge
Posts: 5
Joined: 15. Apr 2021, 17:28

Re: How to use a VPN with Virtualbox

Post by andrieuserge »

Thank you for answering me, sorry for the duplication and if I want to have the same ip is because according to what I understood it was mandatory to do this to use a vpn with a PBX, the PBX is located in the virtualbox .
Does it change things that it is a PBX?
Last edited by scottgus1 on 15. Apr 2021, 18:16, edited 2 times in total.
Reason: removed quote of entire previous post, please use "Post Reply"
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to use a VPN with Virtualbox

Post by scottgus1 »

I am not certain why a PBX requires a special IP address, but I haven't played with PBX's much.

Are you planning two VPN's, one on the host and one in the VM?

Can you explain or post a link where you read this mandatory part? Put the link in a text file and post the text file using the forum's Upload Attachment tab.
andrieuserge
Posts: 5
Joined: 15. Apr 2021, 17:28

Re: How to use a VPN with Virtualbox

Post by andrieuserge »

No, I just have a vpn on the host, I don’t have the link but I have a picture (sorry for the link bu I can’t upload a picture here)

ht tp s:/ /ib b .c o / vVs7 8fT
Last edited by scottgus1 on 15. Apr 2021, 19:01, edited 2 times in total.
Reason: removed quote of entire previous post - again, please use "Post Reply"
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to use a VPN with Virtualbox

Post by mpack »

andrieuserge wrote:I can’t upload a picture here
Sure you can. Just upload the picture, not a link to a picture. See the "Upload attachment" tab when composing a post.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to use a VPN with Virtualbox

Post by scottgus1 »

Please use "Post Reply" instead of "Quote".

You can post pictures from first day first post, using the forum's Upload Attachment tab.

Pictures of text are better copied directly as text, so I don't have to do what I am about to do:

Your picture contains only these text instructions:
I assume that the VirtualBox host is the same
Windows 10 machine that is running Linphone. If not,
please explain.

Confirm that the VirtualBox VM is using Bridged
Networking. If you type
ifconfig
from a shell prompt on the PBX, you should see for
your (virtual) Ethernet interface, something like
inet addr:192.168.123.7
This is the local IP address of your PBX.

And if you type
ipconfig
at a command prompt in Windows,
you should see for your (real) Ethernet interface or
bridge, something like
IPv4 Address . . . . : 192.168.123.4
This is the local IP address of your Windows
machine. Both should be in the same subnet.

Now, in Linphone, set up something like

Adresse SIP* ”yoannB"
<sip:4840©192.168.123.7:5061>
Adresse du serveur SIP*
<sip:192.168.123.7:5061;transport=udp>

Replace 4840 with the extension you set up in
FreePBX.

Replace 192.168.123.7 with the actual local IP
address of the PBX.
I have added markup to emphasize important parts.

Though this does not mention use of a VPN, it does mention the IP address question. Note:
Both should be in the same subnet.
not:
Both should be in the same ip address.

Subnet != IP address. It is important to read carefully. As you can see, the instructions say IP address will and should be different, but subnet should be the same.

"Subnet" is the subnet mask that tells the network what is a local ip address and what is considered outside local ip addresses, or on the internet. 192.168.x.y ip addresses often use a 255.255.255.0 subnet mask.

Your VM and host can and should have different ip addresses, but they must have the same subnet mask.

If you set your VM to use Bridged, it will get an IP address and correct subnet from your router. Or you can manually set a suitable static IP address for the VM, and the same subnet mask as the host is using.

Then set up the VPN inside the VM so folks can VPN into the VM's PBX. Do not make the host and VM IP address the same. They should be different. Use the same subnet mask on the VM as the host receives from the network router.
andrieuserge
Posts: 5
Joined: 15. Apr 2021, 17:28

Re: How to use a VPN with Virtualbox

Post by andrieuserge »

sorry I had not seen this function, indeed I misunderstood the sentence of this person and that changes everything.

So if I summarize what I need to do:

Put my VPN in my VM so that my ip in my vm is not the same as the host's

Put me in bridge access and manually add a static ip address (which I would search with ipconfig on Windows)

Check that my public ip addresses are not the same in the vm and in the host, check that the subnets are the same and normally it's ok if I understood well

I must be in bridge access mode or I can be in NAT and put a static ip address manually?

Sincerely
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to use a VPN with Virtualbox

Post by scottgus1 »

I miss stuff too. :lol: But it looks like you're getting it now!

The instructions imply using Bridged, since their demonstrated ip address of the VM is in the host's LAN. This is probably because local devices might want to access the PBX easily. If you use NAT, you'd have to port-forward through the NAT connection, same as if the PBX is behind a router. See Virtualbox Networks: In Pictures

If you have no local devices to access the PBX, you might be able to use NAT. Then the VM would get a 10.0.2.15 ip address. The PBX would run same as if it was behind a router and you wanted the internet to access it. However, ports would have to be opened in NAT and perhaps in the host's firewall too.

I would recommend using Bridged, so you don't have to open ports in Virtualbox or the host firewall. Set a static IP address in the VM in the same ip range and subnet as the host PC gets from the network. If you install a VPN server in the VM to let internet devices VPN into the PBX, you'll probably have to open ports in your network router. See the PBX's instructions on setting up the network router.
BillG
Volunteer
Posts: 5100
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: How to use a VPN with Virtualbox

Post by BillG »

I doubt that you will ever see a suggestion that two devices on the same network have the same IP number. The whole point of the IP number is to give the device a unique identifier. If two devices have the same IP address (or the same MAC address) there is no way to tell which is which and the system breaks down. The reply to a request from one device might be received by the other for instance.
Bill
andrieuserge
Posts: 5
Joined: 15. Apr 2021, 17:28

Re: How to use a VPN with Virtualbox

Post by andrieuserge »

Hi, I juste have 2 last questions

Can I use bridge access with a laptop without using an ethernet cable?

can i put a vpn in my vm and out of my vm with different ip addresses of course and do the 2 local ip addresses have to look the same? It may sound like a strange question but in the example of the person above the ip addresses look very similar
Last edited by scottgus1 on 16. Apr 2021, 19:15, edited 1 time in total.
Reason: removed quote of almost entire previous post, please use "Post Reply"
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to use a VPN with Virtualbox

Post by scottgus1 »

Andre, Please, please, please, use "Quote" judiciously. It is OK to Quote, but use small snips. Quoting almost the entire post is just as bad as quoting the whole post. Last time this will be said, Please use Post Reply. In the future, posts with large swaths of the previous posts quoted will be deleted undiscussed.

Bridged does not always work with Wi-Fi, see Virtualbox Networks: In Pictures: Bridged Adapter. You will have to try it. Bridged should always work with wired Ethernet. This would apply to laptops as well as PCs.
andrieuserge wrote:do the 2 local ip addresses have to look the same?
We covered this above. IP addresses should not be the same. They should be in the same IP range: This often means the first two or three sets of numbers should be the same, and the last set of numbers should be different. For 192.168.x.y address, 192.168.x should be the same, and y should be different. Subnet masks should be the same.
andrieuserge wrote:can i put a vpn in my vm and out of my vm
I can't answer this one, it depends on the VPN's capabilities. Generally, a VM is same as a regular PC. Anything data-wise you can do on a PC you can do in a VM.
BillG
Volunteer
Posts: 5100
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: How to use a VPN with Virtualbox

Post by BillG »

scottgus1 wrote:
andrieuserge wrote:can i put a vpn in my vm and out of my vm
I can't answer this one, it depends on the VPN's capabilities. Generally, a VM is same as a regular PC. Anything data-wise you can do on a PC you can do in a VM.
I can't work out what he is trying to say! Why would you want to VPN into a vm (unless it was a VPN server test)? Where would you do it from?
Bill
fth0
Volunteer
Posts: 5661
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to use a VPN with Virtualbox

Post by fth0 »

The OP possibly wants a VPN connection that can be simultaneously used from the host and the guest, which is something that VPN software tries to prevent you from doing ...
BillG
Volunteer
Posts: 5100
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: How to use a VPN with Virtualbox

Post by BillG »

Yes, it is certainly not what a VPN is designed to do. Having said that, you should be able to access the host's VPN connection from the guest using the default network setting of NAT. NAT simply lets the guest use the host's Internet connection, whatever that is. It depends on whether the VPN connection looks like a network connection to VirtualBox. If it does, it will share it to the guest.
Bill
Post Reply