How to configure ips for multiple servers linux/windows hosting

This is for discussing general topics about how to use VirtualBox.
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

Hello,

My Mission: setup 3 websites from 1 desktop

My Setup:

1 Desktop(ubuntu) + virtualbox installed
---virtual machine1 (centos) website1
---virtual machine2 (centos) website2
---virtual machine3 (windows server) website3


So i have everything installed, and all my websites are on the servers, but what i can't figure out is, how to setup the IP's and PortForwarding,
If i type in localhost from the virtual machine, i can see my website, but from outside, i am not able to see my websites,

I'm not sure what i have done wrong, is it the ips, port-forwarding, or port-listen,

can someone tell me if i am wrong, this is how i currently have it setup




Outside IP 12.123.123.123

Router 192.168.1.1

Desktop IP 192.168.1.100

VM1 10.0.2.15
http listen 80

VM2 10.0.2.15
http listen 80

VM3 10.0.2.15
http listen 80



Port forward router
-Port 80 open 192.168.1.100


Port forward virtualbox settings
vm1 host-ip 192.168.1.100 port 80 guest port 10.0.2.15 port 80
vm2 host-ip 192.168.1.100 port 80 guest port 10.0.2.15 port 80
vm3 host-ip 192.168.1.100 port 80 guest port 10.0.2.15 port 80




these are my settings, im not sure where exactly i am going wrong, am i supposed to change the listen port on each vm, 80,81,82 or can they all listen on port 80
are all my vm supposed to have the same ip? for some reason the dhcp gives the vm's the same ip


when i try to access my website from outside the network, the browser seems like its going to work, but it just says connecting at the bottom, i can't figure out where i am going wrong
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

In fact,

forget all 3 machines, and just concentrate on 1,


I'm not even able to get 1 vm online, i'm sure it's something to do with network adapter settings on the virtual machine
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

i installed xampp on a windows 7 virtual machine, and i was able to access the website

i port forwarded 8000 on router,
port forwarded 8000 on vm
changed listen port on xmapp to 8000

using the ip example: 12.123.123.123:8000 from an outside computer i was able to see my website,


why does xampp easily work,

but not linux or windows server, which are actually servers
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

on xampp the windows 7 vm, if i change the vm from port 8000 to port 80, it won't work, through the vm

so i installed xampp on my desktop, (not the vm) and port 80 works fine with xampp
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

well well well! it seems the only way to get it working is to run virtualbox as root, thats the only way to get port 80 working,


im getting somewhere! next up, i will test linux and windows server,
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

i got all the operating systems working!!


i love virtual box!! its going to save me time and help me learn alot,


as long as i run virtual box on root, it opens port 80 and i can access all my websites from outside


thanks everyone for the help!
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: How to configure ips for multiple servers linux/windows hosting

Post by scottgus1 »

Hope you're still tuned in there, vm-guy, because I think there's some problems in your setup. You may have been able to get things working but I'm not so sure you're safe.

A story to illustrate my point: A fellow severely suffered from obsessive-compulsive disorder. OCD totally ruined this man's life so he decided to commint suicide. He used a pistol and shot himself in the head. He survived, recovered, and lives a normal life without OCD. How? The bullet destroyed only the part of the brain that was causing the OCD. His method solved his problem. But it is hardly anywhere near the recommended method for curing OCD. tremendous amounts of things could have gone wrong....

You are running Virtualbox on you host as root. I am no Linux guy, but I seem to recall that root is the super-administrator account and nothing should run as root for security reasons on a Linux machine. Other Linux gurus here may have further and perhaps firmer information on the subject. I believe you should not be running VB as root.

I also see that your guests all have a 10.0.2.15 IP address, strongly indicating you are running them all with Virtualbox's NAT network system. Your router has to port forward to the 10.0.2.15 IP address to send traffic into the guests. Which guest will receive the traffic? They all have the same address. If several buildings have the same street number, how will the mailman know which building to deliver the mail to? You need different IP addresses in the guests.

If I were you, I would use Virtualbox's Bridged networking rather than NAT. Bridged puts the guest in the same network as the host, before the host's firewall or port blocker can get in the way. The guests look to the router as if they are just different PC's on the LAN. You can then set different static IP addresses for the guests in the LAN IP address range (in your case 192.168.1.###), then set the port forwarding to each unique guest IP address. Then you will be able to contact each server uniquely from the internet. Of course you will need different incoming port numbers to differentiate which server you are trying to contact from your public IP, then in the port forward rules switch the port back to port 80 on the unique guest IP addresses.
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

yes you are correct, i was using the nat network system,

i also heard i shouldn't run anything as root,

i will try the bridged network and see if that works,


i will report back here eventually and tell if it worked or not
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

the bridged network doesn't work,


i got rid of the router, its not needed,

so i have a true ip. and the bridged network doesn't work

maybe it has someone to do with my operating system

because if i run as root, it works fine, i don't know how to open port 80,

i'll just run it as root for now
BillG
Volunteer
Posts: 5105
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 configure ips for multiple servers linux/windows hosting

Post by BillG »

This really does not have much to do with VirtualBox. The methods for redirecting requests to different web servers is well understood and well documented. Whether they are physical on virtual machines makes no difference to this.You can use different private IP addresses for each server and map IP addresses from the public space to the private space. If they all use the same public address, the normal method is to use different ports and use port forwarding. For both of these you need a router to do the mapping. VirtualBox NAT supports it. Bridged networking is not the answer.

If you only have one public IP, you have to use the port forwarding method to send requests to different servers on the private side. For example you would forward port 81 to server1, port 82 to server 2 etc.The other solution is to use one server and use host headers for the different websites. But if you want to host them on different devices, you need to use port forwarding.

Whether you use root or not is a permissions matter in your host OS, not a VirtualBox matter.
Bill
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: How to configure ips for multiple servers linux/windows hosting

Post by Perryg »

Linux does not allow forwarding ports <1024 except by root, so that answers your question of why it did not work, but running as root except for brief periods needed for administration is very dangerous. It opens the host and all other things run by the host including the LAN to attack where the attacker does not need a password and has full control of the machine. SOP is to instead use ports above 1024.
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

i will use it as root for now and don't tell anyone the ips, since it's just for learning anyways

i don't think its even possible to have 2 web servers with 2 domains on virtualbox, even WITH root , its not working
i thought it was because im not good with linux, so i stopped using linux, and tried it on 2 windows server vm's


heres what happened, with root


i installed linux mint(with virtualbox) ip address 89.123.123.123
-- vm1, windows server 2012, website 1, static ip - 10.0.2.16, mydomain1.com, port forward 80 on vm
-- vm2, windows server 2012, website 2, static ip - 10.0.2.17, mydomain2.com, port forward 80 on vm


i went on my domain register and pointed BOTH domains to ip 89.123.123.123


The problem is only 1 domain works, the other domain i get a http error 404, requested resource not found


i have turn to off 1 of the servers in order for the other domain to work, both can't work at the same time


i think it's because both of the domains are pointing to the same IP


isnt there a way for the domains to find their way to the correct server? even if they have the same ip


in windows server there is a box called "Edit Bindings"


i entered,

vm1
type - http
10.0.2.16
port 80
hostname - mydomain1.com

vm2
type - http
10.0.2.17
port 80
hostname - mydomain2.com




i thought when i entered my server's ip in the cloudfalre settings of both my domains, and even if both domains have the same ip
that both the domains would be smart enough to travel through port 80, and ask the server if he is allowed to enter the server
the server would check his binding and depending on which domain name it was, it would allow it to enter,

why arent the domains smart enough to know which server to go to

i don't see any options anywhere in the domain settings,

i thought that was the whole point of the binding settings in windows,


how can i tell the domain 1 that after he enters 89.123.123.123 to go to 10.0.2.16
how can i tell the domain 2 that after he enters 89.123.123.123 to go to 10.0.2.17



help!
vm_guy
Posts: 49
Joined: 16. Apr 2017, 18:42

Re: How to configure ips for multiple servers linux/windows hosting

Post by vm_guy »

i figured out why bridged adapter doesn't work
it's because my isp only gives me 3 ips, and i was using all 3 ips,
once i disconnected 1 of my real servers, it freed up an ip, then the bridged network picked up the free ip,
so the bridged network works fine, but i dont have enough ips from my isp,
so the bridged network is not useful at all

i can't use the nat network and since it doesn't allow me to use internet, and the other nat cant route to the correct server


its too bad i can't run multiple vm servers from 1 ip, im surprised the ip's arent smart enough to go to the correct vm server,
if so, i could run 10 vm servers from 1 computer!

with my real server that has centos installed, i have multiple hosts on that 1 server, and all my domains have the same ip, they all point to my real server,
my server is smart enough that when all the domains come to the server, it re-directs the domains to the correct host inside my 1 server,


im surprised virtualbox isn't capable of doing this

i've come to the conclusion that it can't be done, and it's a problem with virtuabox
BillG
Volunteer
Posts: 5105
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 configure ips for multiple servers linux/windows hosting

Post by BillG »

Do you read any of the posts apart from your own? I am beginning to doubt it.

You really need to stop making random changes and hoping. How about you think through the problem and decide on how you might get the result you want?

Using bridged mode would only work for you if you had at least four NICs in the host and four public IPs. You have already been told that bridged mode was not the way to go. Do you think that people who run 20 or more vms as web servers have a NIC and a public IP for each server?

If you really don't want to run a router, physical or virtual, look at the possibilities of using VirtualBox NAT and port forwarding. Each vm would use the default NAT setting so it would have Internet access by default. All traffic coming to your servers would use the same public IP but a different port number. If you use port numbers higher that 1024 you will not need to run as root. How about 8080, 8081 etc? There is nothing magical about port 80.

You do not need to sort out exactly how to get packets to each server. Just forward the port numbers and the server listening on that port will receive it.
Port 8080 is an alternative to the port 80 used by http and web services.
History: The Internet was largely born on UNIX-based systems and servers.
UNIX enforces the notion of the first 1023 "privileged ports" which can
only be opened by services running with so-called "root", or administrative,
privileges.
For more info on how to configure the port forwarding see this discussion. You do not need the host or guest IP addresses.

viewtopic.php?f=2&t=82854
Last edited by socratis on 6. May 2017, 10:18, edited 1 time in total.
Reason: Replaced attachment with actual text.
Bill
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: How to configure ips for multiple servers linux/windows hosting

Post by Perryg »

i've come to the conclusion that it can't be done, and it's a problem with virtuabox
That would be a wrong conclusion. VirtualBox deals with hardware and not configuration issues. AFAIK no virtualizer does what you want the way you think it should in this case. You can work around this but that is not within the scope of this forum, and Bill has given you a solution that should work if you listen to him.
Post Reply