SOFTETHER使用本地网桥

SecureNAT上的问题

SecureNAT是一种设置Softether的简单方法。

您不需要很多系统管理员技能和网络理解就可以让Softether启动并运行。

问题是SecureNAT有点慢。使用本地网桥可以降低CPU压力。

并且,如果是用来进行校园网免流,

使用SecureNAT会导致无法访问自己服务器上的资源,

然而使用本地网桥将不会有这个问题。

一丶开启TUN/TAP

在VPS提供商后台控制面板中开启TUN/TAP选项

二丶开启Local Bridge支持

在softether server配置的时候勾选server or bridge支持

三丶禁用“SecureNAT”

Softether VPN Server Manager>>管理虚拟HUB(A)>>虚拟NAT和虚拟DHCP服务器(V)>>禁用SecureNAT(D)

四丶添加网卡

Softether VPN Server Manager>>本地网桥设置(B)>>虚拟HUB(H) 选中VPN>>选中 新的tap设备的桥接(T)>>新tap设备名称(D) 处输入”soft”>>创建本低网桥(A)

输入命令:ifconfig tap_soft,如果可以看到tap_soft网卡信息,那么可以进行下一步,否则看看上面步骤是不是哪里出错了

五丶安装dnsmasq

因为我们不打算使用SecureNAT和SecureDHCP。我们需要在我们的VPS上安装DHCP服务器。我们将使用dnsmasq作为我们的DHCP服务器。

1
apt-get install dnsmasq

六丶在tap_soft接口上启用dhcp

现在编辑/etc/dnsmasq.conf文件。最后添加这5行。

1
2
3
4
5
interface=tap_soft
dhcp-range=tap_soft,192.168.30.50,192.168.30.200,12h
dhcp-option=tap_soft,3,192.168.30.1
port=0
dhcp-option=option:dns-server,8.8.8.8

七丶Softether Server配置

编辑/etc/init.d/vpnserver,删除之前的所有配置,改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
###BEGIN INIT INFO
#Provides: vpnserver
#Required-Start: $remote_fs $syslog
#Required-Stop: $remote_fs $syslog
#Default-Start: 2 3 4 5
#Default-Stop: 0 1 6
#Short-Description: Start daemon at boot time
#Description: Enable Softether by daemon.
###END INIT INFO
DAEMON=/usr/local/vpnserver/vpnserver
LOCK=/var/lock/subsys/vpnserver
TAP_ADDR=192.168.30.1

test -x $DAEMON || exit 0
case "$1" in
start)
$DAEMON start
touch $LOCK
sleep 1
/sbin/ifconfig tap_soft $TAP_ADDR
;;
stop)
$DAEMON stop
rm $LOCK
;;
restart)
$DAEMON stop
sleep 3
$DAEMON start
sleep 1
/sbin/ifconfig tap_soft $TAP_ADDR
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

八丶内核和iptables配置

编辑/etc/sysctl.conf,加入:

1
net.ipv4.ip_forward = 1

然后运行以下命令同步保存配置。

1
sysctl -p

OVZ设置方式如下

1
iptables -t nat -A POSTROUTING -s 192.168.30.0/24 -j SNAT --to-source [YOUR VPS IP ADDRESS]

iptables-save > /root/iptables.conf

KVM设置如下:

1
iptables -t nat -A POSTROUTING -s 192.168.30.0/24 -o eth0 -j MASQUERADE

iptables-save > /root/iptables.conf

九丶重启dnsmasq和vpnserver服务

1
2
sudo /etc/init.d/vpnserver restart
sudo /etc/init.d/dnsmasq restart

十丶解决重启失效

1
apt-get install iptables-persistent

在/etc/iptables/rules.v4文件的*nat的最后加入

1
-A POSTROUTING -s 192.168.30.0/24 -j SNAT --to-source [YOUR VPS IP ADDRESS]

或者

在/etc/rc.local的exit 0之前加入

iptables-restore < /root/iptables.conf

重启VPS

1
reboot


发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.5.2 Zero

Copyright Your WebSite.Some Rights Reserved.

. theme by Plat together