0

I noticed that when I create a tunnel locally from my PC to the remote one, for some devices (generally routers), the connection via http or https does not take place. I get a pop-up that says:

The 'Host' field contained in Http header is invalid

If setting the following in the file hosts file:

127.0.0.1 modemtim

and I connect using modemtim and not only 127.0.0.1, everything works correctly.

SSH command:

ssh -L 8080:<IP_REMOTE_ROUTER>:80 <USER>@<REMOTE_TUNNEL>

Why?

1 Answer 1

1

A typical http request looks like this if you connect to http://google.com/?q=icarus

GET /?q=icarus HTTP/1.1
Host: google.com
User-Agent: mozilla/123
Accept: */*

Low cost web service providers host many many domains such as www.yourdomain.name and www.mydomain.us on a single machine. The web server on that machine looks at the Host: header to see which set of files to use. If you connect to http://127.0.0.1/index.html and this is forwarded to www.yourdomain.name the remote webserver will have a Host: 127.0.0.1 header which doesn't help it decide which set of files is wanted. Adding an entry to /etc/hosts and making the request to http://www.yourdomain.name/index.html fixes this issue.

2
  • but shouldn't ssh think about setting the correct ip? that ip 127.0.0.0.1 is about my pc ... why doesn't ssh change that ip in the ip of the remote server? Commented Feb 17, 2020 at 18:03
  • This is nothing to do with ssh. You are telling your browser to go to 127.0.0.1/whatever, so you browser sets the Host: header in the request to 127.0.0.1. Your browser then goes to your pc. ssh is just used to tunnel the bytes between the endpoints, it doesn't alter them. The closest ssh comes to fixing things is the X forwarding. Commented Feb 17, 2020 at 20:01

You must log in to answer this question.