Azure上のVM→自宅PCの接続をSoftether VPNで検証しており、以下の2点でつまづいております。
VPN Client: Azure VM(Ubuntu)
VPN Server: 自宅 laptop PC(Windows)
- VPN Clientの仮想NICにdhclientを実行してもプライベートIPが割当たらない。
- VPN ClientからVPN Serverへ接続できない。
(確認のため、自宅PCにVPN ClientをインストールしてVPN Serverに接続したのですが失敗しました。)
以下に実装に使用したファイルをまとめてあります。
Dockerfile: VPN Server構築用
FROM ubuntu:20.04
ENV VERSION v4.43-9799-beta-2023.08.31
ENV HUBNAME HUB
ENV HUBPASS password
ENV USERNAME user001
ENV USERPASS password
WORKDIR /usr/local/vpnserver
RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y install wget gcc make dos2unix
ADD entrypoint.sh /usr/local/vpnserver/entrypoint.sh
RUN dos2unix /usr/local/vpnserver/entrypoint.sh && \
chmod 755 /usr/local/vpnserver/entrypoint.sh
RUN wget https://jp.softether-download.com/files/softether/${VERSION}-tree/Linux/SoftEther_VPN_Server/64bit_-_Intel_x64_or_AMD64/softether-vpnserver-${VERSION}-linux-x64-64bit.tar.gz -O /tmp/softether-vpnserver.tar.gz && \
tar -xvf /tmp/softether-vpnserver.tar.gz -C /usr/local/ && \
rm /tmp/softether-vpnserver.tar.gz && \
make && \
apt-get purge -y -q --auto-remove gcc make wget dos2unix
ENTRYPOINT ["/usr/local/vpnserver/entrypoint.sh"]
entrypoint.sh
#!/bin/bash
/usr/local/vpnserver/vpnserver start
sleep 3s
/usr/local/vpnserver/vpncmd /SERVER localhost /CMD DynamicDnsSetHostname $HOSTNAME
/usr/local/vpnserver/vpncmd /SERVER localhost /CMD HubCreate $HUBNAME /PASSWORD:$HUBPASS
/usr/local/vpnserver/vpncmd /SERVER localhost /HUB:$HUBNAME /PASSWORD:$HUBPASS /CMD UserCreate $USERNAME /GROUP:none /REALNAME:none /NOTE:none
/usr/local/vpnserver/vpncmd /SERVER localhost /HUB:$HUBNAME /PASSWORD:$HUBPASS /CMD UserPasswordSet $USERNAME /PASSWORD:$USERPASS
/usr/local/vpnserver/vpncmd /SERVER localhost /HUB:$HUBNAME /PASSWORD:$HUBPASS /CMD SecureNatEnable
/usr/local/vpnserver/vpncmd /SERVER localhost /HUB:$HUBNAME /PASSWORD:$HUBPASS /CMD DhcpGet
/usr/local/vpnserver/vpncmd /SERVER localhost /HUB:$HUBNAME /PASSWORD:$HUBPASS /CMD DhcpEnable
tail -f /dev/null
setup-vpn-server.sh: VPN Server設定用
#!/bin/bash
docker build -t vpn-server:latest .
docker run -d --name vpn-server --hostname vpnserver --cap-add NET_ADMIN -p 500:500/udp -p 4500:4500/udp -p 1701:1701/tcp -p 1194:1194/udp -p 5555:5555/tcp vpn-server:latest
connect-vpn.sh: VPN Client用
#!/bin/bash
# NIC NAME
NIC="nic01"
# Account name
ACCOUNT="account01"
# Server name
SERVER="vpnserver.softether.net:5555"
# Hub name
HUB="HUB"
# User name
USERNAME="user001"
# Password
PASSWORD="password"
# type (standard or radius)
TYPE="standard"
SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR"/vpnclient
sudo cat <<EOF > $SCRIPT_DIR/setup.txt
NicCreate $NIC
NicList
AccountCreate $ACCOUNT /SERVER:$SERVER /HUB:$HUB /USERNAME:$USERNAME /NICNAME:$NIC
AccountPasswordSet $ACCOUNT /PASSWORD:$PASSWORD /TYPE:$TYPE
AccountConnect $ACCOUNT
AccountList
EOF
sudo $SCRIPT_DIR/vpncmd /client localhost /in:$SCRIPT_DIR/setup.txt
rm $SCRIPT_DIR/setup.txt
sudo dhclient vpn_$NIC