So I'm a Mac user. I have pretty much no experience with Linux. So when I wanted to host a temporary web server on my Raspberry Pi (running Debian-derived Raspbian), I was stuck.
I'm using sudo python -m SimpleHTTPServer in the terminal to host a local server on localhost, but I need to map it to mu public IP on port 80. On my MacBook I use Port Map, and that works fine. Is there some software or a command I can do to map this on my 'Pi?
Thanks a bunch!
Alex
I am working on Ubuntu and it will be the same on Debian.
$ python -m SimpleHTTPServer
This will work even without sudo as it serves on non-privileged port 8000
If you want to serve on port 80, you have to use sudo and you shall pass port number on command line:
$ sudo python -m SimpleHTTPServer 80
There is no need to forward this port, it is served already.
Warning: SimpleHTTPServer is not the most secure web server, be careful with exposing your computer to the public this way.
Port forwarding using rinetd
If you want to do real port forwarding, there is a service called rinetd. It is very easy to configure.
Related
I want to do a connection between a computer simulating being a server and another computer being a user, both with Linux.
In the first computer I've created a directory called "server" and in that directory I've done the following command:
python3 -m http.server 8080
Then I can see that directory going to the localhost. But what I want is to see that localhost from the other computer, I tried with wget, and the gnome system of sharing files but none of them worked, and I'm not seeing any solution online.
I'm not sure I fully understand your question but if you want to reach your folder from an other computer with your command python3, you can use the option -b followed by an IP address used on your linux.
All you need to do is get the IP of the server using ifconfig command.
ifconfig | grep 192 make sure not to use the broadcast address part.
Now logon to the other machine and hit the command
http://192.168.71.145:8080
And it should work.
Here I have assumed that your IP is 192.168.71.145 and the port is 8080.
Just change the IP and port as per your values.
If I'm understanding your question correctly you want to connect to the server from another machine on the same network.
If so you can run hostname -I on the server to output to the local IP address of the server, you can then use this on the other machine to connect to it (provided they are on the same network)
I'm trying to make a HTTP/S proxy server work without having to manually port forward.
Machine A has installed a proxy server
Machine A is behind a NAT (or a router with firewall).
Machine B tries to browse internet through Machine A proxy.
Machine B isn't behind a NAT.
Both machines know each other before any connection is made.
In a full scale, there would be multiple Machine A but only one Machine B.
Machine A shouldn't need to configure anything on the router.
I have thought about using uPnP, as per this answer, but as the title of this question, I wanted to know if it would be possible to invert the roles of the machines.
Instead of Machine B initiating a connection, Machine A will do it. So Machine A would be the client and Machine B would be the server. Remember Machine A knows the IP address of Machine B beforehand.
In this scenario, Machine A would still function as a proxy, but having the role of the client in a standard TCP connection.
I understand this would need a custom-made proxy server, which is no problem since the proxy server is implemented in python and I have access to the source, and can modify it.
Will this be compatible with normal HTTP/S proxy? Specifically I will be using python requests on Machine B.
Does this method have a name? Researching for inverse or reverse lands me on reverse proxy which AFAIK doesn't have anything to do with what I'm trying to accomplish.
Is there something I'm missing? Or an alternative solution? (besides uPnP)
a simple solution is OpenSSH port forwarding.
first forward port 20000 on "Machine B" to port 10000 on "Machine A" with remote port forwarding:
[A]$ ssh -N -R 20000:localhost:10000 Machine_B
then setup a tunnel on port 10000 on "Machine A" with dynamic port forwarding:
[A]$ ssh -N -D 10000 localhost
now you can use 127.0.0.1:20000 as a SOCKS5 proxy on "Machine B":
[B]$ curl --socks5 127.0.0.1:20000 example.com
it called "Reverse", you need shootback to reverse TCP tunnel, it work like OpenSSH port forwarding and Socks5 proxy server like pysocks it better than HTTP/S proxy server.
on MachineB (You)
python3 master.py -m 0.0.0.0:10000 -c 0.0.0.0:10800
on MachineA (Remote)
python socks5.py start --port=1080
python slaver.py -m <MachineA_IP>:10000 -t 127.0.0.1:1080
now on MachineB you can set browser or any app to socks5
localhost:10800
I've been hosting a localhost on my Mac with CSS, HTML, and JS. To do this i just navigate to my file with cd Desktop followed by cd filename , and then I do python -m SimpleHTTPServer 8000 to host my server on my localhost. I know that this only works for the person hosting the server, but I'd like to host it on my local network, so anyone that goes to localhost:8000 will see it. (I'm fine with it not being localhost:8000, in fact, I'd love a custom name.)
Thank you
-A
First of all, localhost is a "domain" name if you like. Most of the times it resolves to 127.0.0.1 which is the loopback ip address(e.g. points back to your computer).
I am going to assume you are using python 2.x
So here we go:
#!/usr/bin/env python
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
addr = ("0.0.0.0", 8000) #host to everyone
serv = BaseHTTPServer.HTTPServer(addr, SimpleHTTPRequestHandler)
serv.serve_forever()
Save that to a python script and run with:
python myfile.py
If you are using python 3 then go with :
python3 -m http.server --bind 0.0.0.0 8000
Now for someone else to access your server through your local network, you have to give them your machine's ip.
To do that run:
ifconfig |grep inet
You should get something alone the lines of:
inet 192.168.1.2 netmask 0xffffff00 etc etc
Now anyone on your local network can use your server by typing
192.168.1.2:8000
in their browsers
One easy way to expose localhost to other people is using ngrok, available via brew install ngrok or that link.
In your example above, running ngrok 8000 would allow other people to access the server you've got hosted. It's worth noting, obviously, that this isn't restricted to your local network!
Perhaps a better option (if all you're doing is hosting static HTML, CSS & JS) would be to set up a simple Apache instance. The default config should probably work just fine, and people could then access your page using your computer's local IP e.g 192.168.0.10:8000, or whatever port you set up.
EDIT: As the other answerer pointed out, SimpleHTTPServer will do everything Apache does... You just need to give people your machine's local IP!
I am testing some python functionalities as web server. Typed :
$ python -m SimpleHTTPServer 8080
...and setup port forwarding on router to this 8080. I can access via web with http://my.ip.adr.ess:8080/, whereas my.ip.adr.ess stands for my IP adress.
When I started my xampp server it is accessible with http://my.ip.adr.ess/ and no 8080 port is required for accessing.
What should I have to do to python server responds like that?
It means that xampp is running on port 80 which is default for http://. You need to run SimpleHTTPServer on that port too. More info about running SimpleHTTPServer on port 80.
Specify the port as 80 (default port for HTTP protocol).
python -m SimpleHTTPServer 80
You may need superuser permission in Unix to bind port 80 (under 1024).
sudo python -m SimpleHTTPServer 80
I'm currently trying out the Django framework and I would share/present/show some stuff I've made to my workmate/friends. I work in Ubuntu under Win7 via VMware. So my wish/desire is to send my current pub-IP with port (e.g http://123.123.123.123:8181/django-app/) to my friends so they could test it.
the Problem is - I use django's Dev server (python /path-to-django-app/manage.py runserver $IP:$PORT).
How do I make the devserver public?
EDIT:
Oh, there's something I forgot to mention. As I sad I use VMware with Ubuntu. I have a shellscript that returns me my current int-IP 192.168.xx.xx and saves it in a environment-variable ($CUR_IP)
So, each time I want to run django's devserver I simply execute
python /path-to-django-site/manage.py runserver $CUR_IP:8080
At this way I become an http-adress (e.g.http://192.168.40.145:8080/app-name/) which I CAN USE OUTSIDE my virtual machine. I could test it on my host (win7) machine. That's actually the reason why I asked the question. I thought there's a way to use the ext-IP and make runserver usable outside too
python manage.py runserver 0.0.0.0:8181
This will run development server that should listen on all IP's on port 8181.
Note that as of Jun 17, 2011 Django development server is threaded by default (ticket #1609).
From docs:
Note that the default IP address,
127.0.0.1, is not accessible from other machines on your network. To
make your development server viewable
to other machines on the network, use
its own IP address (e.g. 192.168.2.1)
or 0.0.0.0.
Assuming you have ruby installed, you just have to get localtunnel:
gem install localtunnel
then start your python development server with:
python manage.py runserver 0.0.0.0:8000
in another shell, start localtunnel:
localtunnel -k ~/.ssh/id_rsa.pub 8000
That will output an url to access your local server.
Port 8000 is now publicly accessible from http://xxxx.localtunnel.com
That's it.
192.168.*.* is a LAN-private address -- once you've done the proper VMWare (or other VM manager) and firewall incantations to make it accessible from the LAN, it still won't be accessible from outside the LAN, i.e., from the internet at large (a good thing too, because such development servers are not designed for security and scalability).
To make some port of a machine with a LAN-private IP visible to the internet at large, you need a router with a "virtual servers" ability (many routers, even cheap ones, offer it, but it's impossible to be specific about enabling it since each brand has its own idiosyncratic way). I would also recommend dyndns or other similar service to associate a stable DNS name to your always-varying public IP (unless you're splurging for a static IP from your connectivity provider, of course, but the latter option is becoming costlier all the time).
superuser.com or serverfault.com may provide better answers and details (once you give every single little detail of your configuration in a question) since the question has nothing much to do with software development and everything to do with server administration and configuration.
I had to add this line to settings.py in order to make it work (otherwise it shows an error when accessed from another computer)
ALLOWED_HOSTS = ['*']
then ran the server with:
python manage.py runserver 0.0.0.0:9595
Also, make sure that your firewall allows communication to the chosen port (9595 in this case)
Already answered but adding npm alternate of same localtunnel
sudo npm install -g localtunnel
lt --port 8000 --subdomain yash
If you are using Virtualbox, You need to change the network setting in VB from "NAT" to "Bridged Adaptor". Then restart the linux. Now if you run sudo ifconfig you are able to see your IP address like 192.168.*.* . The last step is runserver
python manage.py runserver 192.168.*.*:8000
Cheers!
You need to configure bridged networking in VMWare and also grant access to the target port in Ubuntu firewall.
Alternatively, you can use cotunnel, Just run cotunnel in your ubuntu (in VMware) change your tunnel port in cotunnel dashboard which port you are using in local side. It gives public url and you can share the url with your friends.
Your Django server can listen to 127.0.0.1 or 0.0.0.0 (I prefer 0.0.0.0) it does not matter for cotunnel.
Might I suggest trying something like pyngrok to programmatically manage an ngrok tunnel for you? Full disclosure, I am the developer of it. Django example here, but it's as easy as installing pyngrok:
pip install pyngrok
and using it:
from pyngrok import ngrok
# <NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:8000">
http_url = ngrok.connect(8000)
No messing with ports or firewalls or IP addresses, and now you can also inspect the traffic (which is useful since what you're doing here is ongoing development, not running a prod-ready server).