# Local port forwarding

### Command explanation
To forward port of remote host use the following command
```sh
ssh -L <LOCAL_PORT>:<TUNNEL_IP>:<DESTINATION_PORT> <user>@<server_ip>
```
-L stands for local adress
because we are tunneling connection on local machine, TUNNEL_IP is 127.0.0.1

```sh
ssh -L <LOCAL_PORT>:127.0.0.1:<DESTINATION_PORT> <user>@<server_ip>
```

### Real life example
- I have a server with ip *69.69.69.69*
- I have user on a server called *gnumik*
- My public key is recognized by this server and I can establish ssh connection like this:
```ssh
ssh gnumik@69.69.69.69
```
- I have postgresql data base running on the server on port *5432*
- I want to have access to this postgre instance from my local machine using local port *5433*
- I need to execute the following command on my local machine:
```ssh
ssh -L 5433:127.0.0.1:5432 gnumik@69.69.69.69
```

***P.S.*** I use arch btw