Question: When outside our company firewall, I use a script to tunnel via SSH and expose our internal wiki to my OSX machine. Is there a command to temporarily tell OSX to resolve to my local port when the tunnel is set up?

The sequence I'm hoping to use is:

1. open the tunnel
`ssh -f external-proxy.example -L 8001:internal-wiki.example:8000 -N`
2. [DO SOMETHING HERE]
3. typing the URL **internal-wiki.example:8000** in my browser causes it to transparently view **localhost:8001**

Other details:

* I could edit **/etc/hosts** but that would be a persistent change. I want to use this only when outside
* We're not using SSL or certs.

Answer: 
My apologies if this is not sufficient for an *answer*, I don't have enough rep to comment here.

I think **/etc/hosts** is possibly the best option. I don't know what your teardown process is, but you could add removing the `/etc/hosts` entry as part of it.  

Also I think the port change won't work with a `/etc/hosts` solution. Can you map `localhost:8000` to `internal-wiki.example:8000`?

Then you could add something like `127.0.1.1 internal-wiki.example` to `/etc/hosts` and remove the line when you stop the tunnel like so: `sed -i '' '/127.0.1.1 internal-wiki.example/d'` (be sure to test that before running live of course).

This should allow you to use `http(s)://internal-wiki.example:8000` in your browser.

It's not a perfect solution, but anything better (such as port mapping) I think would require an http proxy running locally.

For what it's worth, adding and removing host entries is how Parallels makes VMs addressable by hostname. This is added to my `/etc/hosts` while my `xu17` VM is running: `172.20.10.112 xu17.shared xu17 #prl_hostonly shared`

Of course running an [nginx proxy](http://nginx.org/en/docs/http/ngx_http_proxy_module.html) would handle this nicely, but it might be a bit more setup than you're looking for?  

A simpler option with netcat might work depending on the web application. 

```
# make fifo for second nc to transfer response back to first nc
mkfifo /tmp/proxy.pipe
nc -lk 8001 < /tmp/proxy.pipe | nc internal-wiki.example 8000 > /tmp/proxy.pipe

```

Then when you close the tunnel, you can kill the `nc` process and delete `/tmp/proxy.pipe`
Run a load balancing web server on your Mac balancing between the localhost forwarding and the real address of the wiki configured to prefer the localhost forwarding address. 

When the ssh connection is down the load balancer will notice and direct your
connections to the regular wiki address. 

Configure your web browser to proxy connections for the wiki via the load balancer.

Somewhat of a sledgehammer to crack a nut though.