A Tunnel which turns UDP Traffic into Encrypted FakeTCP/UDP/ICMP Traffic by using Raw Socket, helps you Bypass UDP FireWalls(or Unstable UDP Environment). It can defend Replay-Attack and supports Multiplexing. It also acts as a Connection Stabilizer.
When used alone,udp2raw tunnels only UDP traffic. Nevertheless,if you used udp2raw + any UDP-based VPN together,you can tunnel any traffic(include TCP/UDP/ICMP),currently OpenVPN/L2TP/ShadowVPN and tinyfecVPN are confirmed to be supported.
Linux host (including desktop Linux,Android phone/tablet,OpenWRT router,or Raspberry PI) with root access.
For Windows and MacOS users, use the udp2raw in this repo.
Send/Receive UDP Packets with ICMP/FakeTCP/UDP headers
For Windows and MacOS You can run udp2raw inside this 7.5mb virtual machine image(make sure network adapter runs at bridged mode).
ICMP/FakeTCP headers help you bypass UDP blocking, UDP QOS or improper UDP NAT behavior on some ISPs. In ICMP header mode,udp2raw works like an ICMP tunnel.
UDP headers are also supported. In UDP header mode, it behaves just like a normal UDP tunnel, and you can just make use of the other features (such as encrytion, anti-replay, or connection stalization).
Simulated TCP with Real-time/Out-of-Order Delivery
In FakeTCP header mode,udp2raw simulates 3-way handshake while establishing a connection,simulates seq and ack_seq while data transferring. It also simulates following TCP options:
wscale.Firewalls will regard FakeTCP as a TCP connection, but its essentially UDP: it supports real-time/out-of-order delivery(just as normal UDP does), no congestion control or re-transmission. So there wont be any TCP over TCP problem when using OpenVPN.
Failure Dectection & Stablization (Connection Recovery)
- Encrypt your traffic with AES-128-CBC.
- Protect data integrity by HMAC-SHA1 (or weaker MD5/CRC32).
- Defense replay attack with an anti-replay window, smiliar to IPSec and OpenVPN.
Conection failures are detected by heartbeats. If timed-out, client will automatically change port number and reconnect. If reconnection is successful, the previous connection will be recovered, and all existing UDP conversations will stay vaild.
For example, if you use udp2raw + OpenVPN, OpenVPN won’t lose connection after any reconnect, even if network cable is re-plugged or WiFi access point is changed.
- Multiplexing One client can handle multiple UDP connections, all of which share the same raw connection.
- Multiple Clients One server can have multiple clients.
- NAT Support All of the 3 modes work in NAT environments.
- OpenVZ Support Tested on BandwagonHost VPS.
- Easy to Build No dependencies.To cross-compile udp2raw,all you need to do is just to download a toolchain,modify makefile to point at the toolchain,run
make cross then everything is done.(Note:Pre-compiled binaries for Desktop,RaspberryPi,Android,some Openwrt Routers are already included in Releases)
Bypass UDP QoS
Bypass UDP Blocking
Bypass OpenVPN TCP over TCP problem
OpenVPN over ICMP
UDP to ICMP tunnel
UDP to TCP tunnel
UDP over ICMP
UDP over TCP
Download binary release from https://github.com/wangyu-/udp2raw-tunnel/releases
Assume your UDP is blocked or being QOS-ed or just poorly supported. Assume your server ip is 18.104.22.168, you have a service listening on udp port 7777.
./udp2raw_amd64 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -k "passwd" --raw-mode faketcp -a
./udp2raw_amd64 -c -l0.0.0.0:3333 -r22.214.171.124:4096 -k "passwd" --raw-mode faketcp -a
(The above commands need to be run as root. For better security, with some extra steps, you can run udp2raw as non-root. Check this link for more info )
Now,an encrypted raw tunnel has been established between client and server through TCP port 4096. Connecting to UDP port 3333 at the client side is equivalent to connecting to port 7777 at the server side. No UDP traffic will be exposed.
To run on Android, check Android_Guide
-a option automatically adds an iptables rule (or a few iptables rules) for you, udp2raw relys on this iptables rule to work stably. Be aware you dont forget
-a (its a common mistake). If you dont want udp2raw to add iptables rule automatically, you can add it manually(take a look at
-g option) and omit
git version:6e1df4b39f build date:Oct 24 2017 09:21:15
run as client : ./this_program -c -l local_listen_ip:local_port -r server_address:server_port [options]
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_address:remote_port [options]
common options,these options must be same on both side:
add it manually.overrides -a
this option disables port changing while re-connecting
check example.conf in repo for format
check readme.md in repository for supported commands.
4:info (default) 5:debug 6:trace
unless you suspect there is a bug
0:static header,do not increase seq and ack_seq
1:increase seq for every packet,simply ack last seq
2:increase seq randomly, about every 3 packets,simply ack last seq
3:simulate an almost real seq/ack procedure(default)
4:similiar to 3,but do not consider TCP Option Window_Scale,
maybe useful when firewall doesnt support TCP Option
ie:'eth0#00:23:45:67:89:b9'.or try '--lower-level auto' to obtain
the parameter automatically,specify it manually if 'auto' failed
This program sends packets via raw socket. In FakeTCP mode, Linux kernel TCP packet processing has to be blocked by a iptables rule on both sides, otherwise the kernel will automatically send RST for an unrecongized TCP packet and you will sustain from stability / peformance problems. You can use
-aoption to let the program automatically add / delete iptables rule on start / exit. You can also use the
-goption to generate iptables rule and add it manually.
It is suggested to use
hmac_sha1 to obtain maximum security. If you want to run the program on a router, you can try
simple, which can fool packet inspection by firewalls the most of time, but it cannot protect you from serious attacks. Mode none is only for debugging purpose. It is not recommended to set the cipher-mode or auth-mode to none.
The FakeTCP mode does not behave 100% like a real tcp connection. ISPs may be able to distinguish the simulated tcp traffic from the real TCP traffic (though it’s costly). seq-mode can help you change the seq increase behavior slightly. If you experience connection problems, try to change the value.
--lower-level allows you to send packet at OSI level 2(link level),so that you can bypass any local iptables rules. If you have a complicated iptables rules which conflicts with udp2raw and you cant(or too lazy to) edit the iptables rules,
--lower-level can be very useful. Try
--lower-level auto to auto detect the parameters,you can specify it manually if
Monitor iptables and auto re-add iptables rules(for blocking kernel tcp processing) if necessary.Especially useful when iptables rules may be cleared by other programs(for example,if you are using openwrt,everytime you changed and commited a setting,iptables rule may be cleared and re-constructed).
You can also load options from a configuration file in order to keep secrets away from
For example, rewrite the options for the above
server example (in Getting Started section) into configuration file:
Pay attention to the
-k parameter: In command line mode the quotes around the password will be removed by shell. In configuration files we do not remove quotes.
Then start the server with
Use a fifo(named pipe) for sending commands to the running program. For example
At client side,you can use
echo reconnect >fifo.file to force client to reconnect.Currently no command has been implemented for server.
iperf3 TCP via OpenVPN + udp2raw (iperf3 UDP mode is not used because of a bug mentioned in this issue: https://github.com/esnet/iperf/issues/296 . Instead, we package the TCP traffic into UDP by OpenVPN to test the performance. Read Application for details.
iperf3 -c 10.222.2.1 -P40
iperf3 -c 10.222.2.1 -P40 -R
- Client Vultr $2.5/monthly plan (single core 2.4GHz cpu, 512MB RAM, Tokyo, Japan)
- Server BandwagonHost $3.99/annually plan (single core 2.0GHz cpu, 128MB RAM, Los Angeles, USA)
raw_mode: faketcp cipher_mode: xor auth_mode: simple
(reverse speed was simliar and not uploaded)
raw_mode: faketcp cipher_mode: aes128cbc auth_mode: md5
(reverse speed was simliar and not uploaded)
Tunneling any traffic via raw traffic by using udp2raw +openvpn
- Bypasses UDP block/UDP QOS
- No TCP over TCP problem (TCP over TCP problem http://sites.inka.de/bigred/devel/tcp-tcp.html,https://community.openvpn.net/openvpn/ticket/2 )
- OpenVpn over ICMP also becomes a choice
- Supports almost any UDP-based VPN
More details at openvpn+udp2raw_guide
Speed-up tcp connection via raw traffic by using udp2raw+kcptun
kcptun is a tcp connection speed-up program,it speeds-up tcp connection by using kcp protocol on-top of udp.by using udp2raw,you can use kcptun while udp is QoSed or blocked. (kcptun, https://github.com/xtaci/kcptun)
Speed-up tcp connection via raw traffic by using udp2raw+finalspeed
finalspeed is a tcp connection speed-up program similiar to kcptun,it speeds-up tcp connection by using kcp protocol on-top of udp or tcp.but its tcp mode doesnt support openvz,you can bypass this problem if you use udp2raw+finalspeed together,and icmp mode also becomes avaliable.
How to build
Easier installation on ArchLinux
yaourt -S udp2raw-tunnel
pacaur -S udp2raw-tunnel
udp2raw was inspired by kcptun-raw,which modified kcptun to support tcp mode.
kcptun-raw was inspired by relayRawSocket. A simple udp to raw tunnel,wrote in python
another project of kcptun with tcp mode
Transparently tunnel your IP traffic through ICMP echo and reply packets.
Tcp Minion is a project which modifid the code of tcp stack in kernel,and implemented real-time out-order udp packet delivery through this modified tcp stack.I failed to find the implementation,but there are some papers avaliable:
Check wiki for more info: