Getting a sinatra app to serve from a vm - ruby

I'm running vmware fusion 5 on osx 10.8, my guest OS is Arch Linux, currently I'm able to ssh into the guest os perfectly fine via ssh 172.16.4.191 however when i try a simple sinatra app
require 'sinatra'
get '/hi' do
"Hello world!!!!!!!"
end
ruby hi.rb
2013-04-06 19:45:18] INFO WEBrick 1.3.1
[2013-04-06 19:45:18] INFO ruby 2.0.0 (2013-02-24) [x86_64-linux]
== Sinatra/1.4.2 has taken the stage on 4567 for development with backup from WEBrick
[2013-04-06 19:45:18] INFO WEBrick::HTTPServer#start: pid=426 port=4567
it is not available from my host OS
curl 172.16.4.191:4567
curl: (7) couldn't connect to host
Any suggestions would be great, and of course I will provide more information as needed.
Edit:
Share with my mac is selected, "The virtual machine shares the ip address of the Mac on the external network. The mac provides NAT for network traffic form the virtual machine"
Edit:
I've switched over to bridged mode, and it's now sitting on my lan, i can still ssh into it, still no such luck connecting to my sinatra app.
and the iptables shows no rules
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination

You need this line in your hi.rb:
set :bind, '0.0.0.0'
The Document says '0.0.0.0' is the default value. It's wrong.

Just in case anyone is trying to do this on mac / windows 7 with vmware with NAT/sinatra, make sure IIS manager is installed and configured with (connect to server -> localhost:4567).
from my windows browser , localhost:4567/promo_id/ works
from my browser in mac, http://172.16.178.xxx:4567/promo_id/ where 172.16.178.xxx is the IPv4 Address from ipconfig

Related

How to fix Connection to localhost:5432 refused in postgres installed on CentOS 7?

I have a digitalocean droplet and I'm trying to install my Java web-application, on CentOS 7, which is using postgres database. I've successfully installed Java, tomcat and postgres database. I am able to connect to my droplet's postgres database from my local machine using pgadmin as well as from local eclipse. But when I am deploying the web application on server I'm getting the following error:
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
I've added listen_addresses = '*' to postgresql.conf
This is the code from pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
host all all 0.0.0.0/0 md5
Is there any firewall issue? Do I need to provide any special permission? The port which I am using to connect is 5432. I've not made any changes to the port.
I deleted the droplet and installed ubuntu 18 on it, I was successfully able to connect to the database properly. Again, I installed CentOS 7 and it gives the same problem.
Here's the output of iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
For some reason my tomcat 8 server just did that the same thing this morning, when it was working previously. I looked at the selinux logs in /var/log/audit and found the following got me back working again:
sudo setsebool -P tomcat_can_network_connect_db true
Edited: added -P flag to stick between reboots.

Why can't I connect to 127.0.0.1 HortonWorks Dashboard?

I have installed Virtual Box (Version 5.2.0 r118431 (Qt5.6.2)) on Windows 10 and i imported appliance HDP_2.4_virtualbox_v3 (downloaded from here).
I followed the tutorial from here step by step.
The virtual machine is running on the computer from where I am trying to access the Dashboard. I have set up the Host Only Adapter Option on the sandbox so the computer and the virtual machine can communicate
After the CentOs finished booting I am prompt to enter to the ip 127.0.0.1:8888, which is a different address from the tutorial,
and there is no server listening to that address because i get
"127.0.0.1 refused to connect." in the browser.
image here
Run the ipconfig command in your command prompt and identyfy your virtual box's ip under Ethernet adapter VirtualBox Host-Only Network.
Take that ip address and go to your Virtual Box.
Select your appliance and go to Settings->Network->Adapter 1->Port Forwarding.
Replace the Host IP 127.0.0.1 for the port you need 8080, 8888 and so on with the ip of your virtual box that should be sth like 192.168.x.x.
Now start your sandbox, login on it and try to connect in your browser to the new ip set 192.168.x.x:8888.
Use appliance HDP_2.4_virtualbox because in the most recent some linux commands like netstat are considered deprecated and no longer function, which willmake your life harder when trying to debug or identify a networking problem.
If you still encounter issues eith it, reinstall your operating system, reinstall your virtual box and reimport the sandbox, make the changes needed in the Port Forwarding settings and it should be ok.
try to connect using 127.0.0.1 to connect make sure the VM is running make sure there are no errors if there are debug them and at the last straw uninstall the Vm and retry (make sure to make a backup if there are any files)
you can also try to check all the local host ips on your network and try to connect to them
Make sure you set NAT in your VirtualBox network settings:

Windows 8 VMWare guest under Ubuntu 16.04 host doesn't have access to the internet

I have Ubuntu 16.04 host machine with WMWare Player and Windows 8 guest. The problem is that the guest Windows machine doesn't have access to the internet.
Host Ubuntu 16.04 configuration:
>>> grep VERSION= /etc/*-release
/etc/os-release:VERSION="16.04.3 LTS (Xenial Xerus)"
>>> sudo iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
>>> sudo ufw status
Status: inactive
VMWare configuration:
> vmware --version
VMware Workstation 12.1.0 build-3272444
Windows guest machine:
Testing:
Notes:
Note the ping is ok and nslookup hangs. Looks like host machine is stopping the traffic.
I tried ssh into host - ok.
I tried ssh into other machine within the Local lo network of the host - ok
The gateway in the network config is set to 172.16.223.2. I tried to change that to the IP of the host (172.16.223.1) - same results.
My case was really simple. For some reason VMWare hasn't picked up proper DNS's of the host and 8.8.8.8 and 8.8.4.4 are blocked within the internal network. Setting DNS servers manually within Windows to the IPs that are allowed within internal network fixed the issue.
I am marking the question as resolved, but if smb posts a solution to fix the VMWare to pick-up the DNS's of the host, I will switch to his answer.

Can't access Ruby server on VM from host machine

I have a VM set up running Ubuntu server 14.04. In my VM I have created the following Ruby/Sinatra app:
require 'sinatra'
set :environment, :production
set :bind, '0.0.0.0'
get '/' do
"Hello World!"
end
When I execute this using ruby hello.rb I get the following output:
[2015-03-09 16:58:34] INFO WEBrick 1.3.1
[2015-03-09 16:58:34] INFO ruby 2.1.5 (2014-11-13) [x86_64-linux]
== Sinatra/1.4.5 has taken the stage on 4567 for production with backup from WEBrick
[2015-03-09 16:58:34] INFO WEBrick::HTTPServer#start: pid=2258 port=4567
Everything seems to work fine, but when I try to access localhost:4567 from my host machine (Windows 8.1) I get a GET http://localhost:4567/ net::ERR_CONNECTION_REFUSED error (in Chrome).
If I try to access the server from within my VM (ex, by using wget http://localhost:4567) it works fine.
I also have Apache2.4 running in my VM, which works fine, but I disabled it when trying to access my Ruby server by running sudo service apache2 stop.
What could the problem be? I have no problem running regular Ruby files, and I can access my Ruby/Sinatra app if I use Apache2 with Phusion Passenger. But when I simply run ruby hello.rb I can't access it from my host machine.
localhost refers to your local host, which in the case of Windows is not the same as your Ubuntu instance.
You'll need to connect to your Ubuntu instance IP directly, whatever that is. Usually you can find out with ip addr or ifconfig.
If you need a friendly DNS name you can put in your browser, xip.io provides one.
If you're using Vagrant then you can configure port forwarding so you can still use localhost if you want. Without port forwarding you will not be able to connect indirectly.
I have the network adapter for my VM attached to NAT. I was forwarding ports 443, 22 and 80 to my VM, and accessing my server on those ports works fine. Since I was running the Ruby WEBrick server on the default port 4567, I just had to forward port 4567 from my host machine to my VM as well.
After that change, typing http://localhost:4567 into my web browser served up the content from my Ruby file.

Access Docker container running on OS X via boot2docker in Windows virtual machine

Overview:
Host: Mac OS X running boot2docker and Docker
Guest: Windows 7
The Problem:
For my web-development I have set up a docker container via boot2docker on OS X. Within OS X I can access my docker services via boot2docker.
Running boot2docker ip, I get:
The VM's Host only interface IP address is: 192.168.59.103
I am running a Django application on port 1234 (I have mapped the port 5000 on the docker image to port 1234 on my Mac) which I can access within OS X in an web-browser via the address 192.168.59.103:1234. Everything works fine in OS X.
Now I have to test the Web stuff on IE which is why I have downloaded IE8, IE10 and so forth via Microsofts modern.IE website. As a result I have some more VirtualBox images, which are running Windows 7 and come with the propriate IE version.
The question is now how to access the Docker container in those Windows instances to test it under several IE versions.
What I have done so far:
Idea 1
To access the Django application I have looked up my local IP address and tried to access it via NAT in the Windows guests. Given my local IP adress 192.168.178.24, I have tried to access 192.168.178.24:1234 from Windows. Although I can ping 192.168.178.24 from Windows, I do get only a timeout on the port 1234.
Idea 2
Boot2docker runs a VirtualBox machine called boot2docker-vm. It comes with two network adapters, NAT and a host-only adapter called vboxnet0. The latter has the address 192.168.59.3 (which is the one which boot2docker ip returns) with the network mask 255.255.255.0. It runs a DHCP-Server on Server Adress 192.168.59.99 which gives addresses from 192.168.59.103-254.
I have added a second network adapter for my Windows guest systems which can also access via a host-only adapter the network vboxnet0. When being connected to the network the Windows machines do get a valid IP and can ping the IP 192.168.59.103. But I cannot connect to my Django instance on port 1234. If I try to call 192.168.59.103:1234 within Windows, I get a timeout.
Why is it not possible to connect to the Django instance? Can you help me? Thanks in advance.
I have found a solution to my problem here.
To get access to the Django instance I had to open the port on the boot2docker-vm machine.
This can be done by either by boot2docker-vm → settings → Network → Adapter 1 (NAT) → Port Forwarding and add a new rule where Host IPand Guest IP can be left empty and Host Port and Guest Port should be set to 1234.
Another way to do so is executing the following command in the command line
VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port1234,tcp,,1234,,1234";
Of course this needs to be done for all ports, if more than one port is being used.

Resources