softether : https://www.softether-download.com/cn.aspx?product=softether
Ubuntu
1、在Softether VPN Server Manager里面关闭禁用“SecureNAT”
2、添加网卡 在“本地网桥”里面添加新的tap设备“soft”
3、输入命令:ifconfig tap_soft,如果可以看到tap_soft网卡信息,那么可以进行下一步,否则看看上面步骤是不是哪里出错了
4、删除bind服务,安装dnsmasq服务
sudo apt-get -y purge bind9-* sudo apt-get install dnsutils dnsmasq
5、配置dnsmasq,编辑/etc/dnsmasq.conf,在其中加入:+
# Listen to interface interface=tap_soft # Let's give the connecting clients an internal IP dhcp-range=tap_soft,192.168.30.2,192.168.30.222,12h # Default route and dns dhcp-option=tap_soft,3,192.168.30.1 # Set IPv4 DNS server for client machines dhcp-option=option:dns-server,192.168.30.1,8.8.8.8 # How many DNS queries should we cache? By defaults this is 150 # Can go up to 10k. cache-size=10000
7、softetherserver配置,编辑/etc/init.d/vpnserver,删除之前的所有配置,改为:
#!/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=/root/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
/etc/init.d/dnsmasq start
;;
stop)
$DAEMON stop
rm $LOCK
/etc/init.d/dnsmasq stop
;;
restart)
$DAEMON stop
sleep 3
$DAEMON start
sleep 1
/sbin/ifconfig tap_soft $TAP_ADDR
/etc/init.d/dnsmasq restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
8、iptables配置,编辑/etc/sysctl.conf,加入:net.ipv4.ip_forward = 1,然后运行sysctl -p,同步保存配置。
使用 iptables 设置VPN的 的traffic forwarding
将POSTROUTING规则添加到 iptables:
iptables -t nat -A POSTROUTING -s 192.168.30.1/24 -j SNAT --to-source [YOUR VPS IP ADDRESS]
为了保证系统重启以后这个 iptables rule 依然能够 survive,需要安装 iptables-persistent:
apt-get install iptables-persistent
注意,持久化的东西放在了:
/etc/iptables/rules.v4 /etc/iptables/rules.v6
这俩文件里边。
如果需要修改规则的话,就需要重新运行 iptables -t nat -A POSTROUTING -s 192.168.30.1/24 -j SNAT --to-source [YOUR VPS IP ADDRESS],
然后运行 iptables-save > /etc/iptables/rules.v4。
当然,也可以删除 /etc/iptables/rules.v4 中的内容。
9、然后重启dnsmasq和vpnserver服务:
sudo /etc/init.d/vpnserver restart sudo /etc/init.d/dnsmasq restart
有可能出问题的地方
53端口被占用
我设置了服务器之后,客户端老是获取不到ip,很明显dnsserver出问题了。运行 /etc/init.d/dnsmasq restart 提示53端口被占用。
Ubuntu默认占用53端口 dnsmasq 可能会启动失败
可以选择修改systemd-resolved的配置来避免这个冲突。具体步骤如下:
- 打开
systemd-resolved的配置文件:
sudo nano /etc/systemd/resolved.conf
-
在这个文件中找到
#DNSStubListener=yes这一行,将其修改为DNSStubListener=no。这将会让systemd-resolved停止监听53端口。 -
保存并关闭文件。
-
重启
systemd-resolved服务:
sudo systemctl restart systemd-resolved
现在,systemd-resolved应该不再占用53端口,可以尝试再次启动dnsmasq。