-3

I've registered a domain name from godaddy and I want to host the website in my personal computer. My PC already installed LAMP(linux+apache+mysql+php) and connect to the router which connect to internet.
The WAN ip address of the router is something like 24.170.225.222,
The PC ip address in the LAN is 192.168.0.22 and access internet through the router.

I tried to map the domain name to the router IP address in the WAN, then I input the url in browser, it opens the login webpage of the router management system.

How could my domain name be linked to the apache server in my personal PC?
I need to open the default html in the apache server when input the url.

macyou
  • 7
  • 2
  • what is your router make and model? most modern router have port mapping function that will allow you to map the port 80 to the LAN IP address of your web server. read its documentation or find a copy in your router maker website – Sharuzzaman Ahmat Raslan Jan 23 '21 at 16:20

2 Answers2

1

You need to create a port forwarding on your router and forward TCP port 80 for HTTP and TCP port 443 for HTTPS to the internal IP of your PC (192.168.0.22).

Then you need to create an A record on your domain DNS to point www to your public IP (24.170.225.222), you can do this in GoDaddy.

Keep in mind these IPs may not be static so it will stop working if/when they change. For your PC you can create a reservation in your router and for your public IP you may want to ask your ISP for an static IP address, some ofer this as an add-on service. If not possible or too expensive you could use a DDNS service but that would be a subject for another question...

MrLumute
  • 334
  • 1
  • 7
  • Very appreciate for your help! It's almost done except a new problem occured when I'm trying to configure the port forwarding. My linux is actually running in a Virtual Machine, and my COX router can't detect the linux VM. In the GUI of the port forwarding, there is no options to add port forwarding for a non-connected Device. Do you know how to set up a connection between VM and the router? – macyou Jan 23 '21 at 21:59
  • Sorry, I have never seen or used a COX router. – MrLumute Jan 24 '21 at 02:42
  • You need to setup second port forwarding on your VM host to forward port to the VM. Or, use bridged networking mode in the guest VM so that it is visible in the main LAN. – Tero Kilkanen Jan 24 '21 at 08:34
  • My VM is bridge mode, it can be accessed in the LAN, but it's not visible in COX router. So I can't forward port from router to VM directly. – macyou Jan 26 '21 at 04:56
0

Thanks to instructions from @MrLumute and @Tero Kilkanen, the issue is finally fixed after several days experiment.
Summarize as below:
Environment:

  • webserver: Ubuntu 20.04 LTS + apache2 running in oracle VM virtual box
  • oracle VM virtual box running in a windows10 PC
  • windows10 PC connect to cox router which connect to internet

Purpose: host a public website in oracle VM virtual box which can be accessed from internet

Solutions:
1. register a domain name from an internet domain registar(eg,godaddy,bluehost)
2. create an A record to link your domain name to the router's public IP.
This needs to be done in the registar's domain management system after you registered.
3. enable router's http/https port and set port forwarding from router's public IP to PC's LAN IP
In my cox router, I have to firstly enable the http and https port of the router,
then forward the 2 ports to the LAN IP of the PC through the router's "port forwarding" configurations.
4. add a rule in windows firewall to allow inbound access for http port 8080
5. port forwarding http/https ports from PC LAN IP to VM IP
In windows 10, the following command can be run to do the port forwarding:

netsh interface portproxy add v4tov4 listenaddress=192.168.0.133 listenport=8080 connectaddress=192.168.0.122 connectport=80      
listenaddress is the PC IP    
connectaddress is the VM IP
macyou
  • 7
  • 2