Internet protocol suite |
---|
Application layer |
Transport layer |
Internet layer |
Link layer |
Incomputer networks, atunneling protocol is acommunication protocol which allows for the movement of data from one network to another. They can, for example, allowprivate network communications to be sent across a public network (such as theInternet), or for one network protocol to be carried over an incompatible network, through a process calledencapsulation.
Because tunneling involves repackaging the traffic data into a different form, perhaps withencryption as standard, it can hide the nature of the traffic that is run through a tunnel.
Tunneling protocols work by using the data portion of apacket (thepayload) to carry the packets that actually provide the service. Tunneling uses a layered protocol model such as those of theOSI orTCP/IP protocol suite, but usually violates the layering when using the payload to carry a service not normally provided by the network. Typically, the delivery protocol operates at an equal or higher level in the layered model than the payload protocol.
A tunneling protocol may, for example, allow a foreign protocol to run over a network that does not support that particular protocol, such as runningIPv6 overIPv4.
Another important use is to provide services that are impractical or unsafe to be offered using only the underlying network services, such as providing a corporatenetwork address to a remote user whose physical network address is not part of the corporate network.
Users can also use tunneling to "sneak through" a firewall, using a protocol that the firewall would normally block, but "wrapped" inside a protocol that the firewall does not block, such asHTTP. If the firewall policy does not specifically exclude this kind of "wrapping", this trick can function to get around the intended firewall policy (or any set of interlocked firewall policies).
Another HTTP-based tunneling method uses theHTTP CONNECT method/command. A client issues the HTTP CONNECT command to an HTTP proxy. The proxy then makes a TCP connection to a particular server:port, and relays data between that server:port and the client connection.[1] Because this creates a security hole, CONNECT-capable HTTP proxies commonly restrict access to the CONNECT method. The proxy allows connections only to specific ports, such as 443 for HTTPS.[2]
Other tunneling methods able to bypass network firewalls make use of different protocols such asDNS,[3]MQTT,[4]SMS.[5]
As an example of network layer over network layer,Generic Routing Encapsulation (GRE), a protocol running over IP (IP protocol number 47), often serves to carry IP packets, with RFC 1918 private addresses, over the Internet using delivery packets with public IP addresses. In this case, the delivery and payload protocols are the same, but the payload addresses are incompatible with those of the delivery network.
It is also possible to establish a connection using the data link layer. TheLayer 2 Tunneling Protocol (L2TP) allows the transmission offrames between two nodes. A tunnel is not encrypted by default: theTCP/IP protocol chosen determines the level of security.
SSH uses port 22 to enable data encryption of payloads being transmitted over a public network (such as the Internet) connection, thereby providingVPN functionality.IPsec has an end-to-end Transport Mode, but can also operate in a tunneling mode through a trusted security gateway.
To understand a particular protocol stack imposed by tunneling, network engineers must understand both the payload and delivery protocol sets.
![]() | This sectionneeds expansion. You can help byadding to it.(September 2024) |
Tunneling a TCP-encapsulating payload (such asPPP) over a TCP-based connection (such as SSH's port forwarding) is known as "TCP-over-TCP", and doing so can induce a dramatic loss in transmission performance — known as theTCP meltdown problem[6][7] which is whyvirtual private network (VPN) software may instead use a protocol simpler than TCP for the tunnel connection. TCP meltdown occurs when a TCP connection is stacked on top of another. The underlying layer may detect a problem and attempt to compensate, and the layer above it then overcompensates because of that, and this overcompensation causes said delays and degraded transmission performance.
ASecure Shell (SSH) tunnel consists of an encrypted tunnel created through anSSH protocol connection. Users may set up SSH tunnels to transferunencrypted traffic over a network through anencrypted channel. It is a software-based approach to network security and the result is transparent encryption.[8]
For example, Microsoft Windows machines can share files using theServer Message Block (SMB) protocol, a non-encrypted protocol. If one were to mount a Microsoft Windows file-system remotely through the Internet, someone snooping on the connection could see transferred files. To mount the Windows file-system securely, one can establish a SSH tunnel that routes all SMB traffic to the remote fileserver through an encrypted channel. Even though the SMB protocol itself contains no encryption, the encrypted SSH channel through which it travels offers security.
Once an SSH connection has been established, the tunnel starts with SSH listening to a port on the remote or local host. Any connections to it are forwarded to the specified address and port originating from the opposing (remote or local, as previously) host.
The#TCP meltdown problem is often not a problem when using OpenSSH's port forwarding, because many use cases do not entail TCP-over-TCP tunneling; the meltdown is avoided because the OpenSSH client processes the local, client-side TCP connection in order to get to the actual payload that is being sent, and then sends that payload directly through the tunnel's own TCP connection to the server side, where the OpenSSH server similarly "unwraps" the payload in order to "wrap" it up again for routing to its final destination.[9] Naturally, this wrapping and unwrapping also occurs in the reverse direction of the bidirectional tunnel.
SSH tunnels provide a means to bypassfirewalls that prohibit certain Internet services – so long as a site allows outgoing connections. For example, an organization may prohibit a user from accessing Internet web pages (port 80) directly without passing through the organization'sproxy filter (which provides the organization with a means of monitoring and controlling what the user sees through the web). But users may not wish to have their web traffic monitored or blocked by the organization's proxy filter. If users can connect to an external SSHserver, they can create an SSH tunnel to forward a given port on their local machine to port 80 on a remote web server. To access the remote web server, users would point theirbrowser to the local port at http://localhost/
Some SSH clients support dynamicport forwarding that allows the user to create aSOCKS 4/5 proxy. In this case users can configure their applications to use their local SOCKS proxy server. This gives more flexibility than creating an SSH tunnel to a single port as previously described. SOCKS can free the user from the limitations of connecting only to a predefined remote port and server. If an application does not support SOCKS, a proxifier can be used to redirect the application to the local SOCKS proxy server. Some proxifiers, such as Proxycap, support SSH directly, thus avoiding the need for an SSH client.
In recent versions of OpenSSH it is even allowed to createlayer 2 or layer 3 tunnels if both ends have enabled such tunneling capabilities. This createstun
(layer 3, default) ortap
(layer 2) virtual interfaces on both ends of the connection. This allows normal network management and routing to be used, and when used on routers, the traffic for an entire subnetwork can be tunneled. A pair oftap
virtual interfaces function like an Ethernet cable connecting both ends of the connection and can join kernel bridges.
Over the years, tunneling anddata encapsulation in general have been frequently adopted for malicious reasons, in order to maliciously communicate outside of a protected network.
In this context, known tunnels involve protocols such asHTTP,[10]SSH,[11]DNS,[12][13]MQTT.[14]
the TCP forwarding code is pretty speedy as well. Just to pre-answer a question, ssh decapsulates and re-encapsulates TCP, so you don't have classic TCP-over-TCP issues.