openvpn.is
English
简体中文繁體中文EnglishРусскийفارسی

HomeBlogPorts

The fast gate and the open gate

UDP versus TCP in OpenVPN, why TCP inside TCP is slow, when port 443 helps, and how one server can offer both.

Compiled on

When the portcullis comes down, one gate is still open
When the portcullis comes down, one gate is still open Kevin King from Pensacola, FL, US of A, CC BY 2.0

OpenVPN can use either. The default is UDP 1194; when a network refuses it, TCP 443 is often the only gate left open.

Protocol and port are two things. UDP or TCP is how data travels; 1194 or 443 is only a door number. All four combinations work.

The differences

CompareUDP 1194TCP 443
SpeedFastSlower, much slower with packet loss
LatencyLowHigh
Switching networksRecovers quicklyReconnects
Strict networksOften blockedOften open
Video and gamesSuitableNot suitable
Lane markings: UDP 1194 is the fast lane, but it is easy to block
Lane markings: UDP 1194 is the fast lane, but it is easy to block Guitarbogus, CC BY-SA 4.0

Why TCP is slow

A download inside the tunnel is TCP already and resends what is lost. Wrapped in another TCP, one lost packet is resent by both layers and the jam gets worse. Use it only where UDP fails.

Does 443 pass as the web

The port is the same, but OpenVPN's handshake is not that of a web page and a careful device sees the difference. It works against networks that filter by port, not against those that look at traffic. tls-crypt hides part of the pattern.

A long road: TCP 443 is slower but gets through in more places
A long road: TCP 443 is slower but gets through in more places Jacek Halicki, CC BY-SA 4.0

Both gates

server.conf in 2.7
local 0.0.0.0 1194 udp
local 0.0.0.0 443 tcp-server
The client tries them in order
remote vpn.example.org 1194 udp
remote vpn.example.org 443 tcp-client
connect-timeout 8

With 2.6 and earlier run two services on two networks.

The four combinations

CombinationGoodBad
UDP 1194Default, fastWell known, easily blocked
UDP 443Fast, HTTP/3 uses itSome offices allow only TCP 443
TCP 443Passes almost anywhereSlow, very slow with loss
TCP 1194NothingDo not

So: UDP 1194, then UDP 443, then TCP 443.

What the difference feels like

With 1% loss a single download gets perhaps two thirds of the line through a UDP tunnel and a quarter through TCP; with 3% the TCP tunnel stops for seconds at a time. Without loss the difference is under a tenth. Measure your own:

With the tunnel up
iperf3 -c 10.9.0.1 -t 20
iperf3 -c 10.9.0.1 -t 20 -R

When to switch to TCP

  • No handshake on one Wi-Fi, fine on mobile data.
  • It drops every few minutes.
  • The administrator says only web traffic is allowed.

Otherwise stay with UDP, even if it wobbles now and then.

A website already uses 443

port-share hands anything that is not OpenVPN to the website:

With the site on local port 4443
port 443
proto tcp-server
port-share 127.0.0.1 4443

The site then sees itself as the visitor. A program in front that sorts by SNI, or a second IP, is cleaner. UDP 443 is free unless the site uses HTTP/3.

Let the client choose

Client profile
remote vpn.example.org 1194 udp
remote vpn.example.org 443 udp
remote vpn.example.org 443 tcp-client
connect-timeout 8
resolv-retry infinite

remote-random spreads users. With several remotes leave out a separate proto.

If it has to be TCP

server.conf
tcp-nodelay
sndbuf 0
rcvbuf 0

And bbr in the system. It helps a little; two TCP layers still fight. For video, one step lower resolution does more.

A website already uses 443?

Use another machine, or port-share to pass anything that is not OpenVPN on to the website.

Other ports?

UDP 443 and UDP 53 are used as well. It depends on what the network allows.

Can it look like a real website?

Not OpenVPN itself. It takes another TLS layer such as stunnel on both ends.

Does a new port mean reinstalling clients?

No, change the remote line.

Even TCP 443 fails at work?

The network inspects the handshake. Ports do not matter there.

Walk on

Nearby gates

Signposts: OpenVPN UDP vs TCP, OpenVPN port 443, OpenVPN port 1194