Search This Blog

Sunday 14 December 2014

How to connect to a LAN machine from the Internet

Our gate to the Internet is a router, a networking device, to which our local machines connect, either through the Ethernet (cable) or WiFi (wireless). Router is connected to a modem that is plugged into the Ethernet port in the wall. After registering with an ISP/Internet Service Provider, we get a public/visible from the Internet, IP address, which will identify us when we make requests  to the Internet and through which responses/requests from outside our LAN/Local Area Network reach us. There are two types of router IP addresses: static and dynamic. Dynamic IP addresses, most common, change each time the router is restarted. Any configuration we make using the router IP address, needs to be updated after a router restart.

Our local machines, connected to the router, form our Local Area Network/LAN. Each  machine is identified by a LAN IP address, which other local devices are aware of and use to communicate with each other. These IP addresses are usually something like 193.168.x.y or 10.x.y.z .

Linux:

tamara@fuego:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr  xxxxxxxxxxxxxxxx
......

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
......

wlan0     Link encap:Ethernet  HWaddr xxxxxxxxxxxxxxxx 
          inet addr:192.168.x.y  Bcast:192.168.x.z  Mask:255.255.z.w
          inet6 addr: yyyyyyyyyyyyyyyy Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1453501 errors:0 dropped:0 overruns:0 frame:0
          TX packets:913979 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1266612092 (1.2 GB)  TX bytes:186022548 (186.0 MB)


LAN devices are hidden behind the router and cannot be reached through their LAN IP addresses from the outside. Firewall is generally in action for protection. Sometimes, however, we need to reach a LAN server to allow access to a locally running  a, eg. TCP/HTTP, application. This is achieved through Port Forwarding, making a particular port on a particular LAN machine (associated with a particular local application) reachable from the outside.

Port Forwarding configuration can be done through the Router web admin page. Mine is 192.168.1.254. For BT Home Hub 2 router, the breadcrumb to the Port Forwarding configuration is:

          Settings -> Advanced settings -> Port Forwarding

On the Port Forwarding page, there are several sections:
Selecting one of the supported applications will open a port, which is a default for that application. Default ports are 80 for an HTTP server, 443 for an HTTPS server, 22 for ssh etc. Configuration involves choosing an application and associating it with the hostname, attached to the machine we want to set up the Port Forwarding for.

To set up Port Forwarding for a local application running on a particular (non-default) port,  it is necessary to turn the UPnP to off. Doing that will add a new option under the Supported Applications tab. Through this option it is possible to add a local application, running on a specific port, to the Supported applications. Then one can set the Port Forwarding (under the Configuration tab) for the application. To access a Mojolicious application running under a development server on port 3000:

      http://router_IP_address:3000/mojo_test/

No comments:

Post a Comment

Note: only a member of this blog may post a comment.