Total Pageviews

Monday 9 September 2019

‘IP over TCP’ VPN(客户端仅能运行在linux桌面系统)

In a previous post, I wrote about how to create virtual network interfaces on Linux by using TUN interface facility. We created a simple use program which opened the file descriptors of the TUN interface from the back-end so that any packet directed to the TUN interface will be read by the back-end program through the file descriptor. Similarly, we can write to the file descriptor from the back-end program so that any application listening to the TUN network interface will receive it.
In this article, I'm demonstrating a simple setup based on TUN network interfaces which we can use to deliver our IP packets from one host to another inside a TCP socket connection. This is a simple but an interesting system to demonstrate that we can capture IP packets and then deliver them through any medium we want including TCP sockets. In this particular example, since we are using TCP sockets, we need two programs; a TCP server and a TCP client to run on the two hosts. As IP packets what we are actually sending are ICMP payloads so we should have named this post as ICMP over TCP to be more precise. Let's start the description.
High-level overview of the setup
1. First of all, obtain the required source files from the following git repository.
git clone https://github.com/asanka-code/tun-tcp-socket.git
2. In the first computer, run following commands to setup a TUN interface called asa0,
sudo ip tuntap add dev asa0 mode tun
sudo ip addr add 10.0.1.1/24 dev asa0
sudo ip link set dev asa0 up
sudo ip addr show
3. In the second computer, run following commands to setup a TUN interface called asa0,
sudo ip tuntap add dev asa0 mode tun
sudo ip addr add 10.0.1.2/24 dev asa0
sudo ip link set dev asa0 up
sudo ip addr show
4. Compile and run TUN controller program which is also a TCP server on host 2,
gcc tun-server.c -o tun-server
./tun-server
5. Compile and run TUN controller program which is also a TCP client on host 1,
gcc tun-client.c -o tun-client
./tun-client
6. Ping from host 1 to host 2 where our ping packets will be delivered through the TCP client and TCP server in the TCP socket connection (connection x),
ping -I 10.0.1.1 10.0.1.2
If everything is properly setup. We should be able to see the ping responses from the remote host.
from http://recolog.blogspot.com/2016/07/ip-over-tcp.html
项目地址:https://github.com/asanka-code/tun-tcp-socket

相关帖子:https://briteming.blogspot.com/2012/02/ping-tunnel.html


No comments:

Post a Comment