Sunday, October 23, 2016

create udp tunnel using socat

*** setup information

client ip: 192.168.202.242
server ip: 192.168.202.243
target network: 192.168.182.0/24

client tunnel ip: 10.0.0.2
server tunnel ip: 10.0.0.1

*** on server
1- the the following command, it will listen on port 22222
$ socat -d -d TCP-LISTEN:22222,reuseaddr TUN:10.0.0.1/24,up

2- enable ip_forward and the interface out to network 192.168.182.0/24
$ sudo sysctl -w net.ipv4.ip_forward=1
$ sudo iptables -t nat -A POSTROUTING -o ens39 -j MASQUERADE

*** on client
1- establish the udp tunnel to server
$ socat TCP:192.168.202.243:22222 TUN:10.0.0.2/24,up

2- route the target network via the new created tun device
$ sudo ip route add 192.168.182.0/24 dev tun0

- snapshot of ip address of tun0 and successfully ping the target network




No comments:

Post a Comment