Task 1: Network Setup
Host U can communicate with VPN Server.
启动docker,进入host U,ping VPN Server 10.9.0.11
V*N Server can communicate with Host V.
进入server-router,ping Host V,都成功ping通
Host U should not be able to communicate with Host V.
试一下ping 192.168.60网段的host V。,发现都无法ping通
Run tcpdump on the router, and sniff the traffic on each of the network. Show that you can capture packets.
在Host U ping V*N Server:
在Host V ping V*N Server:
Task 2: Create and Configure TUN Interface
Task 2.a: Name of the Interface
成功修改Interface name的前缀为Huang
Task 2.b: Set up the TUN Interface
在Host U中执行以下指令/也可将其添加到tun.py中
输入ip address发现已成功配置接口
Task 2.c: Read from the TUN Interface
将tun.py中的while循环改为如下:
在Host U ping 192.168.53.1,tun.py输出捕获到的ICMP回显请求
- 尝试在Host U上ping 192.168.60.5、192.168.60.6,发现无法ping通且tun.py程序并不输出任何东西,,说明此时ICMP报文并未传送到tunnel上,原因应该是Host并不知道要把目标地址转发到tunnel上
- Task 2.d: Write to the TUN Interface
- 往程序添加以下代码
在Host U 中运行tun.py并ping 192.168.53.1
结果成功接收到icmp回显应答
- 修改tun.py,往tun中写入乱码
在Host U ping 192.168.53.1
可以发现ICMP回显请求,但输入的乱码并未被接收
Task 3: Send the IP Packet to V*N Server Through a Tunnel
tun_server.py 代码
tun_client.py代码
分别在客户端和服务器运行tun_client.py和tun_server.py,并在客户端ping 192.168.53.1
客户端输出:
服务器输出:
尝试ping 192.168.60.0/24网段的主机,发现client端和server端均无输出,我们在client端添加如下静态路由
此时再尝试ping 192.168.60.0/24网段的主机Host V,发现ICMP回显请求被server端成功接收
Task 4: Set Up the V*N Server
只需要在tun_server.py最后将接收到的IP报文写入tun中即可,因此在server端配置tun,并在最后写入tun,完整代码:
- 在Host V 192.168.60.6中执行tcpdump -i eth0 -n,并在Host U ping 192.168.60.6,各个地方的输出如下:
Client:
Server:
Host V 192.168.60.6:
可知从Host U发出的ICMP回显请求已成功到达Host V
Task 5: Handling Traffic in Both Directions
- 在server端利用select修改两端的while循环,使其同时监听两个文件描述符,并配置其他零碎的配置,client端的配置同理
在Host U ping 192.168.60.6,收到ICMP回显应答!
Client端和Server端的输出:
在Wireshark中捕获的报文:
Host U 尝试telnet Host V,成功登录
Task 6: Tunnel-Breaking Experiment
按照要求在Host U telnet 远程连接 Host V,并在连接时关闭tun_server.py,此时在telnet控制台上输入,发现并无任何响应
重启tun_server.py服务,过了一会儿发现之前的所有输入都显示到telnet的控制台上了
通过WireShrak捕获的报文我们可以得知,此时TCP连接应该是被Host V发送FIN ACK报文关闭了,
在服务恢复后,Host U再使用RST报文尝试重置TCP连接
最终的连接并没有中断,在TCP连接建立起来之后,之前没发送的UDP包也都被发送过去
Task 7: Routing Experiment on Host V
修改默认路由,使特殊网段的地址才使用V*N服务器
在Host U重新telnet Host V 192.168.60.6,可以正常连接,说明修改正确
Task 8: V*N Between Private Networks
用docker-compose2.yml文件构建docker
修改VPN Client和V*N Server运行的程序
核心代码如下:
从Host U 192.168.50.5 ping Host V 192.168.60.5,成功收到icmp echo-reply
WireShark捕获其中一对ICMP报文,可知连接已顺利建立
尝试在Host U telnet远程连接 Host V,成功!