Skip to content

Commit 515f36d

Browse files
committed
Added files
1 parent dde6e8d commit 515f36d

File tree

7 files changed

+83
-1
lines changed

7 files changed

+83
-1
lines changed

README.md

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
1-
# ssh-vpn
21
VPN over SSH
2+
============
3+
4+
### How It Works
5+
6+
```
7+
8+
///
9+
+----------------------+ /// +----------------------+
10+
| RPI | /// | VPS |
11+
|----------------------|----SSH--->|----------------------|
12+
| eth0: 192.168.31.222 | /// | eth0: 1.2.3.4 |
13+
| tun0: 10.0.0.200 | /// | tun0: 10.0.0.100 |
14+
+----------------------+ /// +----------------------+
15+
///
16+
17+
```
18+
19+
- RPI (树莓派-客户端)
20+
- 使用境外DNS服务器
21+
- 使用eth0, 禁用wlan0
22+
- 配置ssh无密码root登录
23+
24+
- VPS (云主机-服务端)
25+
- 使用境外[VPS服务器][1]
26+
- 启用内核IP数据包转发
27+
- 配置防火墙NAT地址转换
28+
29+
30+
### References
31+
32+
- <http://man.openbsd.org/ssh>
33+
- <https://help.ubuntu.com/community/SSH_VPN>
34+
- <http://bodhizazen.net/Tutorials/VPN-Over-SSH>
35+
36+
[1]: <http://www.vultr.com/?ref=6821947>

rpi/dhcpcd.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#option domain_name_servers, domain_name, domain_search, host_name
2+
interface eth0
3+
static domain_name_servers=208.67.222.222 208.67.220.220

rpi/interfaces

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
iface tun0 inet static
2+
pre-up ssh -i /home/pi/.ssh/id_rsa \
3+
-o ServerAliveInterval=30 \
4+
-o ServerAliveCountMax=5 \
5+
-o TCPKeepAlive=yes \
6+
-o StrictHostKeyChecking=no \
7+
-o UserKnownHostsFile=/dev/null \
8+
-S /var/run/ssh-vpn-tunnel-control \
9+
-M -f -w 0:0 1.2.3.4 'ifdown tun0; ifup tun0'
10+
pre-up sleep 5
11+
12+
address 10.0.0.200
13+
pointopoint 10.0.0.100
14+
netmask 255.255.255.255
15+
16+
up ip route add 10.0.0.0/24 via 10.0.0.200
17+
up ip route add 1.2.3.4/32 via 192.168.31.1
18+
#up ip route replace default via 10.0.0.100
19+
up ip route add 0.0.0.0/1 dev tun0
20+
up ip route add 128.0.0.0/1 dev tun0
21+
#down ip route replace default via 192.168.31.1
22+
down ip route del 10.0.0.0/24 via 10.0.0.200
23+
down ip route del 1.2.3.4/32 via 192.168.31.1
24+
25+
post-down ssh -i /home/pi/.ssh/id_rsa \
26+
-S /var/run/ssh-vpn-tunnel-control \
27+
-O exit 1.2.3.4

vps/ferm.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@def $DEV_PRIVATE = tun0;
2+
@def $DEV_PUBLIC = eth0;
3+
@def $NET_PRIVATE = 10.0.0.0/24;
4+
5+
table nat {
6+
chain POSTROUTING {
7+
saddr $NET_PRIVATE outerface $DEV_PUBLIC MASQUERADE;
8+
}
9+
}

vps/interfaces

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
iface tun0 inet static
2+
pre-up sleep 5
3+
address 10.0.0.100
4+
pointopoint 10.0.0.200
5+
netmask 255.255.255.0
6+
up arp -sD 10.0.0.200 eth0 pub

vps/sshd_config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PermitRootLogin yes
2+
PermitTunnel yes

vps/sysctl.conf

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
net.ipv4.ip_forward=1

0 commit comments

Comments
 (0)