2015年5月14日 星期四

[Softether VPN] 連接VPN網絡後不能訪問VPN服務器的各種問題與解決方法


最近我在給自家新架設的Linux服務器 上安裝Softether VPN時,發現以下的一個問題。

我在外面連接自家的Softether VPN 服務器時,在連接到自己的VPN網絡後,我發覺不能SSH去自己的VPN服務器;而VPN網絡中的其他機器,則能夠連接。

例如:
在我家的電腦裡面, 內聯網(VPN網絡)的架構是這樣的:

VPN服務器: 192.168.1.100
電腦1: 192.168.1.101
電腦2: 192.168.1.102
外部IP: 123.123.123.123

當我在外面的網絡,透過外部IP(123.123.123.123) 連接進自家的VPN網絡後, 發覺不能ping 或者 SSH去自己的VPN服務器 (192.168.1.100),反之,連接其他電腦,例如192.168.1.101 , 192.168.1.102 則沒有問題。



結果我上網去查了一些資料,例如參考了以下的網站:
https://www.softether.org/4-docs/1-manual/3._SoftEther_VPN_Server_Manual/3.6_Local_Bridges
http://www.vpnusers.com/viewtopic.php?f=7&t=1662&sid=c8425047118646c9f59f6d8e24943298

這個問題的主要原因,是因為我把Softether VPN Server安裝在Linux上(Ubuntu 14.04),而且是用預設的Local Bridge; 而當橋接本地網絡卡時,Linux內部的Code則有限制不能訪問回自己的IP。

Limitations within the Linux or UNIX operating system prevent communication with IP addresses assigned to the network adapter locally bridged from the VPN side (Virtual Hub side). The cause of this restriction lies with OS's internal kernel codes rather than with the SoftEther VPN. When wishing to communicate in any form with a UNIX computer used for local bridging from the VPN side (Virtual Hub side), (for instance, when running both the VPN Server / VPN Bridge service & the HTTP Server service and wishing to grant access to the server service from the VPN side as well), prepare and connect a local bridge network adapter and physically connect both it and the existing network adapter to the same segment (as explained in 3.6 Local Bridges, it is recommended to prepare a network adapter for exclusive use in local bridging for this and other situations).

以下為我的解決方法:

1. 在安裝Softether VPN Server 後, 我用 Softether VPN Server Manager (Tools)  連接回自己的VPN服務器, 然後選擇 "Local Bridge Setting"


 2. 選擇"Bridge with New Tap Device", 然後輸入新的Tab Device的名字, 在我的例子裡面,我輸入 "vpn", 在linux裡面, tap的名字則會變成 tap_vpn



3. 安裝 Bridge Utility
sudo apt-get update
sudo apt-get install bridge-utils
4. 設定 /etc/network/interfaces 
sudo nano /etc/network/interfaces 
 以我的/etc/network/interfaces 作例子 (請因應自己的情況去修改IP / network adapter):


 
# The loopback network interface
 auto lo
 iface lo inet loopback
 
 # The primary network interface
 auto br0
 allow-hotplug br0
 
 iface br0 inet static
     address 192.168.1.100
     netmask 255.255.255.0
     gateway 192.168.1.1
     network 192.168.1.0
     broadcast 192.168.1.255
  bridge_ports eth0


5. 在運行VPN Server後,需要執行以下指令來橋接 tap_vpnbr0
brctl addif br0 tap_vpn
6. 例如,我是透過 service sevpnserver start 來啟動VPN 服務器的, 我的 /etc/init.d/sevpnserver 文件則修改為 (請因應自己的情況去修改Lock 以及安裝的位置 ):

 
    #!/bin/sh
    # chkconfig: 2345 99 01
    # description: SoftEther VPN Server
    DAEMON=/usr/local/sevpnserver/vpnserver
    LOCK=/var/lock/subsys/sevpnserver
    test -x $DAEMON || exit 0
    case "$1" in
    start)
    $DAEMON start
    sleep 5
    brctl addif br0 tap_vpn
    touch $LOCK
    ;;
    stop)
    $DAEMON stop
    rm $LOCK
    ;;
    restart)
    $DAEMON stop
    sleep 3
    $DAEMON start
    sleep 5
    brctl addif br0 tap_vpn
    ;;
    *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    esac
    exit 0

按上面例子去做的話,每次啟動VPN server 則會自動去橋接vpn server建立的tap_vpnbr0

在完成以上設定,以及重啟VPN服務器後, 在VPN的網絡裡面,能夠訪問192.168.1.100了~


不過....在我安裝完br0 和修改完 /etc/network/interfaces後,多了個問題.
例如我去 ping www.google.com 會失敗.
看來安裝完br0以後,連接dhcp服務器會出問題,取不了外部網路(例如google.com)的IP Address.

這個時候,需要執行以下指令:
sudo dhclient -v br0

由於我需要啟動機器時就運行以上的指令,所以我把這句加到 /etc/rc.local 裡面.


題外話:
由於我自己的VPN 服務器,主要是給我自己用。
例如我在外面時,需要透過VPN, SSH到自家的機器,所以我才需要進行以上設定。

如果是基於安全的考慮, 例如VPN服務器是公開給公眾用 或者是 給其他用家用的話,不建議像我這樣進行以上設定,否則的話,就很容易給外部的人入侵自己的VPN服務器。

1 則留言:

  1. 我在vps 上执行 brctl addif br0 tap_vpn ,mac地址会变成tap_vpn的,vps一般都会绑定mac地址,有什么好的解决方法吗?
    而且Softether有个怪现象,windows的机器都能ping 通也能连接,linux的机器和路由不能ping也不能连接,连telnet 都不行。请问您有遇到过吗?版本号是目前最新的

    回覆刪除