rustun – Virtual Not Private Network in 100 Rust lines
While stuck at home I wrote a simple Linux tunnel ("VPN" b 2020-4-1 12:8:22 Author: scriptjunkie.us(查看原文) 阅读量:14 收藏


While stuck at home I wrote a simple Linux tunnel ("VPN" but not encrypted/authenticated) in 100 lines of Rust. This is a PoC, not an OpenVPN replacement; just sending the IP layers and above over UDP. Specifically, it creates a tun device, enables the device, sets the device's IP and netmask, and forwards packets in both directions as client or server depending on command line argument. Setting up routes for the client and enabling forwarding/NAT for the server is currently left as an exercise for the reader. But it might be as simple as:
On the server:

echo "1" | sudo tee /proc/sys/net/ipv4/ip_forward ; sudo iptables -t nat -A POSTROUTING -j MASQUERADE

On the client:

OLDGW=$(route -n | grep '^0\.0\.0\.0' | awk '{print $2}') ; route add -host $SERVERIP gw $OLDGW ; route add default gw 10.8.3.1

It defaults to IPv4 but could be IPv6 if you configure it.

You can find the code here: https://github.com/scriptjunkie/rustun/tree/master Enjoy.

This entry was posted on April 1, 2020, 4:08 am and is filed under Uncategorized. You can follow any responses to this entry through RSS 2.0. Both comments and pings are currently closed.

Comments are closed.


文章来源: https://scriptjunkie.us/2020/04/rustun-virtual-not-private-network-in-100-rust-lines/
如有侵权请联系:admin#unsafe.sh