Set up a dedicated Node.js ubuntu server that can be accessed by external network

I am working at the TAMK campus network, so it is not easy to set up a  dedicated Node.js ubuntu server that can be accessed by external network both on virtual machine or actual network for previlidge and permission.

At last I choose to use my laptop to install dual windows 7 and ubuntu system and set up a dual boot system. Then set up the node.js ubuntu server.

Problem comes out again. How to transfer the design files made on PC to the laptop server and then access the server though PC and my phone which use the same wifi network with the laptop.

It takes a couple of hours for me to solve this problem, now, both PC and phone can access the server on laptop. But design files can not be transfered from PC to server I afraid.

This is my solution:

1 install a nodejs server listening to port 8080

My server code

var http=require('http');
http.createServer(function(request,response){
response.writeHead(200,{'Content-Type':'text/plain'});
response.end('Im Node.js.!\n');
console.log('Handled request');
}).listen(8080, "0.0.0.0");;
console.log('This is a http running on NODEJS');

server ip is 192.168.x.233

Set the listener to 0.0.0.0 make the internal(LAN) network within the same intranet sharing the same router access the server.

So on the phone which is using the wifi network with laptop can easily access the node.js server by input:192.168.x.233:8080

First, be sure that nodejs is actually listening to such port:

sudo  netstat -tpln

Let’s check iptable:

sudo iptables -nvL

Notice the line in your netstat output …

tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      18843/nodejs 

Specifically the local address of 127.0.0.1:8080. That means that nodejs is only listening on the localhost address and so only will accept connections from the same machine.

From reference:http://serverfault.com/questions/685688/port-8080-remains-closed-even-when-opened-with-iptable-and-nodejs-is-listening-o?lq=1

The following command can open the port 8080:

following command:

iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT

For me, there is no such issue.

Then I try to access the server from the PC whose ip is 192.168.112.x

I suppose to think that TAMK wifi router and LAN router should be in the same intranet, so I try many ways to solve this.

I try to modify httpd.conf

But it seems that there is no such file which is running apache server.

http://stackoverflow.com/questions/10018955/how-to-access-my-localhost-from-another-pc-in-lan

Added inbound Rules.

And I Add a line at the very end of your hosts file  located in /etc/hosts similar to this :

       192.168.X.88 nodejs.com

The IP address (in the example above it is 192.168.x.88) is the address of your localhost; Your computers IP address. The domain name (nodejs.com) is what is mapped to the IP address.

After you save that file, whenever that computer points to nodejs.com, it will be directed to your IP address. Firewalls are still a barrier – however the other answers covered that so I will not repeat their contribution.

The above method do not solve the problem.

At last I think of the solution:

I try to find the IP on the pc:193.167.x0.xxx

And the one on laptop is :193.167.x1.x2

by http://showip.net/

Then I think that these two networks are totally different. So I consider to solve the issue by virtual Hosts.http://www.sitepoint.com/accessing-localhost-from-anywhere/

According the mentioned artical, ngrok can provide this service. So I download one to the ubuntu system and then unzip under GUI. and run

./ngrok http 8080

You’ll see a screen like so:

ngrok running on port 80

Note: mine is different

In the example above, we’ve got traffic to a randomly generated ngrok address of http://3xxxx.ngrok.io being forwarded to our localhost on 127.0.0.1:8080.

Open that URL on any device with an internet connection and you’ll be accessing your localhost from the web!

Then I can assess the url from my browser of my PC!

I guess there is only http severice that ngrok can provide for free, so it is impossible to share the files with PCs and laptop with ngrok without payment. But that’s enough. I can share file by other means like connect laptop with LAN cable to let the two systems run under same intranet. Of course, this way can save a lot of time if do this in the beginning. But the solutions and the process above obviously let me know more about the network knowledge!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s