Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am running Apache Tomcat on my PC. My PC is connected to a router in my house and the router is connected to my ISP. Now I want to run a server on my pc so that my frined can view my site hosted on my pc. If I go to the site whatismyip.com I know that my IP address is xx.xx.xx.xx. This is the IP of my router I guess. If I type http://xx.xx.xx.xx in my browser the my router asked for a useename and passwd. This means that my friend can connect to my router. How can I allow them to see the site hosted on tomcat runing on my PC?

I dont want to use commercial hosting and I want to use my PC only as a server due to some reasons.

The internal IP of my router is 192.162.1.1 and of my PC is 192.162.1.2.

share|improve this question

migrated from serverfault.com Aug 12 '09 at 19:19

This question came from our site for system and network administrators.

3  
No, not serverfault. This is an enduser question - not a sysadmin one. This should go to superuser.com. –  Mark Brackett Aug 12 '09 at 9:53
    
Perhaps that you are behind a proxy. –  Selinap Aug 12 '09 at 12:09
    
I take it this PC is running Windows? A PC running Linux would require slightly different instructions. –  David Thornley Sep 16 '09 at 20:09

7 Answers 7

You need to forward requests to the webserver (port 80, probably) to your machine (.1.2). You configure this on your router.

share|improve this answer
2  
Note this is usually referred to as "Port Forwarding" on routers. An easier, although less safe, method is to use DMZ on your router to open all ports to your webserver. This sometimes makes it easier when hosting multiple services on your webserver, such as game servers, VoIP servers, etc. –  Will Eddins Sep 16 '09 at 18:46
    
And be very careful about opening up ports for incoming requests. There's a whole lot of people out there knocking at ports at random IP addresses to see who answers. –  David Thornley Sep 16 '09 at 20:07

You are going to need to do a few things:

  • Make sure to change your router password and lock down your router, since you will be making your IP publicly available, the configuration of your router is very important. It probably would be a good idea to download the latest firmware to prevent security exploits.

  • Forward your web requests to your local machine, on your router. Look for a "port forwarding" option, which will force all requests on a certain port your router to be forwarded to your machine's IP address

  • try to ensure that your internal IP address remains the same. Some advanced routers can reserve a certain IP address for your computer's MAC address, so make this configuration to your router. If you router software cannot do this, you probably will have to update your internal IP address in the "port forwarding" mapping whenever your computer reboots (or gets another IP address somehow). You can also confgure your computer to use a hard coded internal IP address, but this could add additional issues too out of scope to discuss here.

  • if you're ISP provides you with a dynamic IP address, it can get to be a hassle sending your friend your new IP address every time it changes, so you could sign up for a dynamic IP service (www.dyndns.org) which will have a program that will update a dns entry for you. Most modern routers have this server built into the firmware, you can look for it then you don't have to run the software on your machine.

  • for security reasons, reduce the number of other requests that are being sent to this machine (e.g. windows file sharing, ftp, bit torrent, etc etc).

  • Port 80 is the default port used by web browsers and servers, so when you access a site http://www.mysite.com, you're requesting it on port 80)

  • Port 8009 is the default port used by tomcat, so if you're using tomcat, you may want to replace port 80 with port 8009 below.

  • You don't have to do any other port configuration for the web server on your local machine, you can have your router do the mapping and leave the web server running on port 80 or 8009 on your machine.

  • Example, say i want to use port 12345, then I can configure my router so that any requests on port 12345 on my router will be sent to port 80 (or 8009) on my local machine. This allows you to be able to access our web server on that machine simply by going to http://localhost/ or http://localhost:8009 . Other internal machines on your network will have to access by Ip address (http://192.168.1.x) or you can edit yoru hosts files and assign a name.

  • It's important to know that most ISP's block port 80 ( and other common ports) from being used as a web server, so even if you have everything configured property on your end, your friend still may not be able to hit port 80 on your machine. This is typically done so that ISP customers will fork out more cash for their "business" offerings. Because of this, you will probably have to open your router on another port if you really want your friend to access your web server. You'll want to stay away from low number ports, and you'll want to avoid using the port your router is configured from as well.

If you do all of the above correctly, you should be able to have a stable URL (such as http://myusername.dyndns.org:12345 ) that your friends can bookmark and use at will

share|improve this answer

You need to port forward HTTP (tcp/80) to your pc (192.162.1.2). Each router is slightly different, so you'll need to find some instructions for your specific model.

If your router supports UPnP, then (They're screen scraping - not using UPnP) you could also do it automagically as needed (better security) for $$.

share|improve this answer

You have to forward your tomcat port on your router. The default tomcat port is 8080. It is better if you change your tomcat port to 80. Follow the following steps to change your tomcat port

  1. Open the folder tomcat\conf on your computer
  2. Now with a text editor you have to open and modify server.xml. Here you have to identify the following line (line 184) and you modify it so that changes from:

to:

<Http10Connector port="80"
secure="false"
maxThreads="100"
maxSpareThreads="50"
minSpareThreads="10" />
  1. Startup the web server

From your router forward port 80 from your router to your pc ip address. Once this is done, tell your friend to access your website by using http://xx.xx.xx.xx/webAppName. Here xx.xx.xx.xx is your IP address and webAppName is your website project.

By default the ISPs will block port 8080 so you have to change the port tomcat uses.

share|improve this answer
    
ISPs does not generally block ports by default. That may be the case in your city/country (I'm guessing USA), but that is certainly not the case in general. In many countries ISPs actually have quite fair terms of service, without any port blocking (or bandwidth capping for that matter). –  Mikael Auno Aug 12 '09 at 10:14
    
Mine blocks port 80 but allows 8080! It is different for each ISP. –  Kevin Panko Aug 19 '09 at 21:55

If you arent interested in port forwarding or if it sounds complicated, most routers have setting called the DMZ. Put your webserver (the machine that hosts the website) in the DMZ to allow it to be seen from the outside world. Then, if you havent registered a domain name, have your friend type in your IP into his browser.

share|improve this answer
    
Given that the OP is apparently not an expert in this sort of thing, I'd suggest not effectively unblocking all ports. There's enough exploits out there, and no end of people scanning ports and IP addresses to try to use those exploits, and somebody who needs help on this level isn't likely to know how to stop them. DMZ is kinda like "PWN ME". –  David Thornley Sep 16 '09 at 21:34

You will need to set up "port forwarding" on the router of port 80 (http) to your PC and also I recommend setting up "static DHCP" so that the router always assigns the same IP to your PC when it boots.

Note that you are exposing your PC to the world of hackers when you do this. Make sure you have a current version of apache/tomcat installed and that you apply updates regularly.

If your router supports it you may want to set up "dynamic DNS" to give your machine a permanent name on the internet (instead of a sometimes changing IP #.) Check out dyndns.com and look at their free dynamic DNS options.

share|improve this answer

Static IP is a must...If u have Dynamic IP, it keeps on changing and u need to intimate to your friend about the new IP

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.