I used vagrant ubuntu server(16.04): 127.0.0.1, and port is 2222 for developing web application, the test code (app.py)as following:
import logging; logging.basicConfig(level=logging.INFO)
import asyncio, os, json, time
from datetime import datetime
from aiohttp import web
def index(request):
return web.Response(body=b'<h1>Awesome</h1>')
#asyncio.coroutine
def init(loop):
app = web.Application(loop=loop)
app.router.add_route('GET', '/', index)
srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 2222)
logging.info('server started at http://127.0.0.1:9000...')
return srv
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
loop.run_forever()
After I run the code in the ubuntu server as following:
and then I want to test the app in browser, but there is no response! and error:
The issue is that the server is listening on IP 127.0.0.1 on the VM so you will not be able to access from your host.
If you want to access it from your host browser, you'd need to run your server on a dedicated IP or on the 0.0.0.0 IP so change to
srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000)
then make sure to forward this port from your Vagrantfile:
config.vm.network "forwarded_port", guest: 9000, host: 9000
and you'll be able to access it on http://localhost:9000 from your host
the default 2222 port is from forwarded 22 from host machine ssh.. are you sure you port_forwarded setting in your Vagrantfile is correct..?also check in you host machine if the port that you want to open is really open using sudo netstat -ntlp usually vagrant port will have a PID of VBOXHeadless
Related
I have MongoDB running on a Raspberry Pi at my house, and I'm trying to edit the config file so that other computers at my house can connect to it. Here's some numbers:
Device
IP
Raspberry Pi
192.168.1.5
Laptop
192.168.1.7
When I edit /etc/mongod.conf to look like this, I can connect from my laptop:
net:
port: 27017
bindIp: 0.0.0.0
But, what I want to do is this, which should allow my laptop to connect:
net:
port: 27017
bindIp: 127.0.0.1,192.168.1.7
But this doesn't work. When I run sudo service mongod restart it errors and says it exited with status code 48. I looked up error code 48, which is supposed to indicate that the port is already in use, but if I change the bindIp property to either 0.0.0.0 or 127.0.0.1 it restarts without errors.
How can I bind MongoDB to IPs on my local network?
Solved:
User R2D2 in the comments was correct; I needed to use the IP of the host machine, not the IP of the connecting machine. This makes sense, now that I know. Below is the working config - notice the IP listed is the IP of the Raspberry Pi, which is the same IP my dev machines will be pointing to in order to connect.
net:
port: 27017
bindIp: 127.0.0.1,192.168.1.5
User R2D2 in the comments was correct; I needed to use the IP of the host machine, not the IP of the connecting machine. This makes sense, now that I know. Below is the working config - notice the IP listed is the IP of the Raspberry Pi, which is the same IP my dev machines will be pointing to in order to connect.
net:
port: 27017
bindIp: 127.0.0.1,192.168.1.5
I am trying to use my raspberry pi as a server, I have a java app using tcp port 1777 and mysql on 3306, however neither one or the other is accessible from lan (both works fine from the pi itself). When I scan the ports open on the pi from my laptop I only see the ssh and vnc ports, but when running the netstat on the pi both ports appear to be in listening state. I am running the latest version of raspbian (image had a ssh and vnc disabled by default, I enabled it in pi configuration (raspi-config)). Any ideas?
In my opinion, check which interface these services are listening on because the services listening on localhost are not 'binded' to the external network so try to make them listening on 192.**** ip address.
Example : Edit MySQL configuration
By default, MySQL is not configured to accept remote connections. You can enable remote connections by modifying the configuration file:
sudo nano /etc/mysql/my.cnf
and set bind-address = 192.** or bind-address = 0.0.0.0 then restart mysql servic:
sudo service mysql restart
There are similar questions but nothing worked for me. I have already added this line to my pg_hba.conf:
host all all all trust
And this one to my postgresql.conf:
listen_addresses = '*'
My networking settings in the Vagrantfile are:
config.vm.network "private_network", ip: "10.0.0.0"
config.vm.network :forwarded_port, guest: 3000, host: 3000, auto_correct: true
When I try to connect from the host, I get:
$ psql -h 10.0.0.0 -U <username> -d <database>
psql: could not connect to server: Permission denied
Is the server running on host "10.0.0.0" and accepting
TCP/IP connections on port 5432?
The same command from the guest works with no problems. What am I missing??
[UPDATE]
I changed the private network ip to "192.168.1.77" (got it from a working example) and it worked. Still don't know why 10.0.0.0 wasn't good though, since it is in the reserved private address space, so I'll leave the question unanswered.
You need to forward the postgres port, you're only forwarding 3000, not 5432.
I believe the reason you could not connect is that technically 10.0.0.0 is the network address of the range 10.0.0.0/8 (and 10.255.255.255 is the broadcast address and should also not work). The first address of each range is the network address and is not allowed to be a routable host (similarly 192.168.0.0 should fail in the same way since it's a 16-bit block).
In addition to forwarding port 5432 to another port on my host machine in my Vagrantfile, I added the following to my pg_hba.conf file in my vagrant machine, restarted postgresql, and it finally allowed me to connect from the host:
host all all 0.0.0.0/0 md5
I found the suggestion here: https://github.com/laravel/framework/issues/11339
I've a Centos 6.5 - Apache server. This server is in a private LAN (it has a private IP 10.x.x.x) and is linked to a domain name. If I test port 443 from webtools with the domain name, it seems that it's blocked, but I want to understand if it's blocked from a firewall outside the server or if it depends from the server configuration. Is there anyway I can check if the port is open for the server?
iptables firewall is empty.
You could simply try to telnet from the server to itself.
So if you'd want to check if port 443 is responding, run:
telnet localhost 443
if the response is
telnet: Unable to connect to remote host: Connection refused
then there's probably nothing listening on that port.
I am trying to connect to Postgresql using the PGAdmin III client in Windows 8.1. Postgresql is installed in a local copy of Vagrant (Ubuntu 14.04) on my Windows machine. It's up and running on Vagrant:
LISTENING
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 814/postgres
VERIFIED USER/PASS/LOCAL CONNECTION
I can access Postgresql locally in Vagrant via SSH in Windows:
vagrant#precise32:/etc/postgresql/9.1/main$ psql -h localhost testdb myuser
Password for user myuser:
psql (9.1.15)
SSL connection (<removed)
Type "help" for help.
testdb=> \quit
PG_HBA.CONF
I added this to my pg_hba.conf file:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all <my IP> md5
VAGRANT CONFIG
My Vagrant config is set to port forward to 5432:
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 5432, host: 15432
POSTGRESQL.CONF
And my postgresql.conf file is set to listen on all IP's:
#listen_addresses = '*' # what IP address(es) to listen on;
PGADMIN ERROR
So, what am I missing here when I try to connect as a guest via PGAdmin to the host and I get the following message, which indicates it sees it but something is not letting me through?:
An error has occurred:
Error connecting to the server: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.
PGADMIN CONNECTION INFO
Host: localhost
Port: 15432
Service: <blank>
Maintenance DB: postgres
Username: Myuser (verified)
Password: ****** (verified)
Store password:
Colour: <blank>
Group: Servers
In your Vagrant config add a IP (if not set) eg:
config.vm.network :forwarded_port, host: 15432, guest: 5432
config.vm.network :private_network, ip: "192.168.111.222"
Now from PGAdmin in Windows connect to host 192.168.111.222, port 5432.
Worked for me although I'm not know why.. :P
I dont know what you mean with in pg_hba.conf but in vagrant enviroment you should use ip like 10.0.2.2/24 instead your machine network address.
I had the same problem in linux, and i think in windows this can happen too. In my postgresql.conf the port variable was defined in two places. First with 5432 value, and second with 5435 value.
Running telnet vm_ip 5435, i was able to connect to the server running in the vm.
In my case my vm was running with public_network option, so i have a external ip. In this case, you don't need to forward a port, once you will access the vm,for example, with 192.168.60.15:5435 address.