このページでは、Ubuntu搭載のデバイス(amnimo X/G/Rシリーズ)にて、OpenVPNのクライアント側の設定を紹介します。
対象製品
- amnimo G シリーズ エッジゲートウェイ 屋内タイプ
- amnimo G シリーズ エッジゲートウェイ 屋外タイプ
- amnimo R シリーズ IoTルーター 屋内タイプ
- amnimo R シリーズ IoTルーター 屋外タイプ
- amnimo X シリーズ AIエッジゲートウェイ 屋内タイプ
- amnimo X シリーズ AIエッジゲートウェイ 屋外タイプ
- amnimo X シリーズ センサー接続ゲートウェイ 屋内タイプ
設定の流れ
1. OpenVPNパッケージのインストール
$ sudo apt install openvpn
2. 証明書の配置
サーバー側で生成した証明書関連ファイルを解凍し、"/etc/openvpn/client"ディレクトリに展開した下記ファイルをコピーする。
$ sudo cp ca.crt ca.key ta.key user.crt user.key /etc/openvpn/client/
3. OpenVPNの設定
$ sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf /etc/openvpn/client/ $ sudo vi /etc/openvpn/client/client.conf ############################################## # Sample client-side OpenVPN 2.0 config file # # for connecting to multi-client server. # # # # This configuration can be used by multiple # # clients, however each client should have # # its own cert and key files. # # # # On Windows, you might want to ename this # # file so it has a .ovpn extension # ############################################## # Specify that we are a client and that we # will be pulling certain config file directives # from the server. client # Use the same setting as you are using on # the server. # On most systems, the VPN will not function # unless you partially or fully disable # the firewall for the TUN/TAP interface. dev tap 👈用途次第で、tun(リモートアクセスVPN、拠点間VPN)/tap(同一LAN化)でサーバー側設定に従い設定ください。 ;dev tun # Windows needs the TAP-Win32 adapter name # from the Network Connections panel # if you have more than one. On XP SP2, # you may need to disable the firewall # for the TAP adapter. ;dev-node MyTap # Are we connecting to a TCP or # UDP server? Use the same setting as # on the server. proto tcp 👈用途次第で、tcp(接続性優先)/udp(スループット優先)でサーバー側設定に従い設定ください。 ;proto udp # The hostname/IP and port of the server. # You can have multiple remote entries # to load balance between the servers. remote (OpenVPNサーバーのIPアドレス) (OpenVPNサーバーのポート番号) ;remote my-server-2 1194 # Choose a random host from the remote # list for load-balancing. Otherwise # try hosts in the order specified. ;remote-random # Keep trying indefinitely to resolve the # host name of the OpenVPN server. Very useful # on machines which are not permanently connected # to the internet such as laptops. resolv-retry infinite # Most clients don't need to bind to # a specific local port number. nobind # Downgrade privileges after initialization (non-Windows only) ;user nobody ;group nogroup # Try to preserve some state across restarts. persist-key persist-tun # If you are connecting through an # HTTP proxy to reach the actual OpenVPN # server, put the proxy server/IP and # port number here. See the man page # if your proxy server requires # authentication. ;http-proxy-retry # retry on connection failures ;http-proxy [proxy server] [proxy port #] # Wireless networks often produce a lot # of duplicate packets. Set this flag # to silence duplicate packet warnings. ;mute-replay-warnings # SSL/TLS parms. # See the server config file for more # description. It's best to use # a separate .crt/.key file pair # for each client. A single ca # file can be used for all clients. ca ca.crt 👈CA証明書、設定したファイル名と合わせてください。 cert user.crt 👈クライアント証明書、ユーザー・端末ごとに異なります。設定したファイル名と合わせてください。 key user.key 👈クライアント秘密鍵、設定したファイル名と合わせてください。 # Verify server certificate by checking that the # certicate has the correct key usage set. # This is an important precaution to protect against # a potential attack discussed here: # http://openvpn.net/howto.html#mitm # # To use this feature, you will need to generate # your server certificates with the keyUsage set to # digitalSignature, keyEncipherment # and the extendedKeyUsage to # serverAuth # EasyRSA can do this for you. remote-cert-tls server # If a tls-auth key is used on the server # then every client must also have the key. tls-auth ta.key 1 👈 共通鍵ファイル、サーバー側から入手してください。 # Select a cryptographic cipher. # If the cipher option is used on the server # then you must also specify it here. # Note that v2.4 client/server will automatically # negotiate AES-256-GCM in TLS mode. # See also the ncp-cipher option in the manpage cipher AES-256-CBC # Enable compression on the VPN link. # Don't enable this unless it is also # enabled in the server config file. #comp-lzo # Set log file verbosity. verb 3 # Silence repeating messages ;mute 20
※tunで接続したい場合は、dev tapを無効化してdev tunを有効化しておく
4. OpenVPNの接続
再起動後も自動的に接続する場合は下記コマンドを実行し有効化しておく
$ sudo systemctl enable openvpn-client@client
接続処理
$ sudo systemctl start openvpn-client@client
Ex.接続時のインターフェイス(TAP=Terminal Access Point)
20: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 100 link/ether fa:5c:97:5f:95:f4 brd ff:ff:ff:ff:ff:ff inet 172.16.2.18/16 brd 172.16.255.255 scope global tap0 valid_lft forever preferred_lft forever inet6 fe80::f85c:97ff:fe5f:95f4/64 scope link valid_lft forever preferred_lft forever
※ip routeの向きにも注意
トラブルシューティング:tap0がUPにならず、syslogに以下のようなエラーが出ている場合
2025-08-18T03:53:18.604847+00:00 localhost <daemon.warning> systemd-udevd[4739]: Could not generate persistent MAC address for tap0: No such file or directory
<>syslogの上記のログの少し上に
2025-08-18T03:53:18.598606+00:00 localhost <daemon.info> openvpn[4737]: /sbin/ip addr add dev tap0 172.16.XXX.XXX/16 broadcast 172.16.255.255
のようにIPアドレスの設定コマンドが記載されているのでこれを手動実行する。
5. OpenVPNの切断
切断処理
$ sudo systemctl stop openvpn-client@client
6. OpenVPNの再起動・状態確認
$ sudo systemctl restart openvpn-client@client
~$ sudo systemctl status openvpn-client@client
* openvpn-client@client.service - OpenVPN tunnel for client
Loaded: loaded (/usr/lib/systemd/system/openvpn-client@.service; enabled; preset: enabled)
Active: active (running) since Tue 2025-09-10 20:16:58 JST; 3 weeks 2 days ago
Docs: man:openvpn(8)
https://openvpn.net/community-resources/reference-manual-for-openvpn-2-6/
https://community.openvpn.net/openvpn/wiki/HOWTO
Main PID: 663 (openvpn)
Status: "Initialization Sequence Completed"
Tasks: 1 (limit: 2176)
Memory: 1.7M ()
CPU: 16h 49min 8.360s
CGroup: /system.slice/system-openvpn\x2dclient.slice/openvpn-client@client.service
`-663 /usr/sbin/openvpn --suppress-timestamps --nobind --config client.conf
Notice: journal has been rotated since unit was started, output may be incomplete.
コメント
0件のコメント
サインインしてコメントを残してください。