4
3
I was a bit confused whether there is a difference between port forwarding and tunneling. What I have concluded is that a port forwarder forwards application data to another port perhaps potentially on a remote host. A tunnel on the other hand, doesn't carry application data directly, but rather carries the PDUs of another IP protocol. So can it be said that a tunnel is a special type of forwarder wherein unlike a normal forwarder where the mediator server makes a direct connection to the ultimate destination and forwards the data to the destination, a tunnel, rather injects the protocol data into its operating system networking stack to be routed to the ultimate destination?
But this doesn't always appear to hold true. For example, SSH tunnels are often referred to as secured tunnels. But are they really tunnels? The data that is being carried in these secure channels are application data and not IP protocol data.
Maybe I am over-analyzing this and they both refer to the same thing.
So for the following scenario where I have an Application A, B, C. A is a client application that connects to B. B simply forwards the data to Application C. Would B be considered to be port forwarding because there is no additional "value" being added to the data stream? If so, what about the same scenario but assume that the connection between A and B is unencrypted and the connection between B and C is encrypted. Would B now be tunneling data in this case as opposed to port forwarding since there is now a "value add" of encryption?
the main difference (and they are very different in manifestation), is that port forwarding generally happens inside a single device (a NAT wall of some kind) so its essentially just routing, with some TCP redirection and session state mapping. On a packet level Tunneling is like putting armor around your packet (the packet is placed inside another packet that is its tunnel). on a stream level its like the tube your data is in, is itself inside another tube (the tunnel). – Frank Thomas – 2014-05-05T14:34:38.227
It make help to have a concrete example. lets say I have a L4 tunnel over SSH, and I want to connect to a remote server at port 80 through the tunnel. My system will create an IP packet for the remote tunnel endpoint, with an ssh segment at TCP/22. I also create an IP packet for the webserver, with a http (tcp/80) segment. I then put the packet containing the http segment INSIDE the SSH segment, and send it into the tunnel. The remote endpoint recieves the ssh packet, and pulls the inner packet out of it. then it sends the http packet on to the webserver, which will respond back the same way. – Frank Thomas – 2014-05-05T14:39:20.267