Forum Moderators: phranque
I have a small lan with 2 computers. The gatway computer is running windows xp pro and connects through a dial up. The second computer is linux running apache web server. Is it possible to direct any used why tries to access the lan ip to the localhost of apache. I thought it might have been as simple as altering the host file to...
[lan ip of linux] localhost
I then refreshed the dns, went to localhost and got a 404.
Any ideas.
Thanks in advance.
Mack.
I'm not a 100% sure on this one, but here goes.
The hosts file can be used to force requests for certain hostnames to a specific IP address. So if you has a website running on apache called hostwidget.domainwidget then in the hosts file you would have
[apache ip] hostwidget.domainwidget
However, in order for the site to be returned, the apache server must be accepting requests for hostwidget.domainwidget, otherwise there is no site to return.
So unless you have a site 'localhost' running on apache, it won't know what to return when you request it from the IP. Does this make sense?
Also, you might run into problems redirecting requests for localhost, since it is often used by software for local requests.
As I say, i'm not completely sure :)
If I go to the windows machine and go to [[linux...] ip] it also shows the apache index page.
What would I put in host file for this?
[linux ip] localhost localhost?
im confused ;-)
Mack.
Hmm, me too ;)
I think we need to try and isolate the problem. Try changing the hosts file to point at a website with a host header and domain name on your apache server, if you have one. At least then we'll know if the hosts file on the XP machine is working OK.
If the hosts file does work, maybe it's something to do with the way apache handles 'htpp://localhost'.
The hosts file basically specifies the IP of a given hostname, so you don't look it up with DNS as normally happens. So if I entered 127.0.0.1 www.webmasterworld.com, I would never lookup the IP of webmasterworld when I went to the site. Instead, my browser would talk to 127.0.0.1 and ask for www.webmasterworld.com. 127.0.0.1 is my local computer. However, since my PC isn't running a server that accepts requests for webmasterworld.com, I will get a 404 page.
So, unless your apache server accepts outside requests for localhost at the IP you specified, then you will see a 404.
However, there are other reasons why it might not be working, for instance a proxy might affect the way the hosts file works.
As I mentioned, I don't know much about apache, so I don't know if the stuff you see when you type in http;//localhost is available to outside PCs. Maybe someone who knows apache could help us out?
I just assumed that this would tell the xp machine that anything that accessed it's internet ip and was looking for content would be sent to 192.168.0.1 (the lan ip of linux) Turns out localhost can't be used to access other machine. I made another line
foo 192.168.0.1
Now if I type [foo...] in the address bar I get to view index of apache ;-)
Appears to have worked. The mistake I was making was trying to forward localhost to another localhost... Sill fool that I am.
[added] still cant get access from outside network, tried [[web...] ip]/foo
Any ideas...
Thanks for your great help.
Mack.
Your hosts file won't route external requests, only requests made by the xp machine itself.
What you need is port forwarding, so any requests sent to port 80 are forwarded to the apache box. If memory serves me correctly, ICS (Internet Connection Sharing) in XP allows port forwarding.
Be warned though, enabling ICS will force the XP box to use the IP 192.168.0.1, so before you do this change the Linux box IP to something else (i.e 192.168.0.2).
I'm using a 2000 box but it should be the same so if you go to the properties of your internet connection there should be a sharing tab. If you enable sharing then choose settings and then the services tab you should be able to add a service using the name 'web' (or whatever), port 80, leave TCP enabled and then enter the IP for you Apache box (192.168.0.2). Re-establish the connection and it should work from outside the LAN.
I don't know of any stand alone routing software that will do this but I'd be surprised if it didn't exist.
If Apache doesn't have a virtual host or domain specified for a request it will respond with the first host specified in the httpd.conf file. I.E, if it gets a request for [example.com,...] but [example.com...] doesn't exist, it will display the page of the first domain it is set up with instead. Likewise, if it receives a request just by IP it will display the default page.
Cheers
Stretch
still confused lol
Thanks again.
Mack.
Your best bet would be asking a friend to try and connect at an agreed time when you will be online.
Of course, for this to work, you need to know your IP before calling. Bearing in mind you are probably assigned a dynamic IP (i.e one that changes everytime you connect) this could be tricky to orchestrate.
Perhaps looking at using the services of a company like www.dyndns.com to assign a static name to your dynamic IP would help.