LoginSignup
2
1

More than 5 years have passed since last update.

Conoha CentOS VPSをL2TP VPNサーバーにする

Posted at

Conohaで使用しているCentOS7のVPSにL2TP/IPSecでVPN接続できるようにした時のメモです。Conoha標準の(コントロールパネルから設定できる)ファイアウォールではL2TPに必要なポート開放ができないのでこちらを無効(全て許可)にしてCentOS側でfirewalldにて設定します(人生初firewalld)。

L2TPサーバー

Conohaのコントロールパネルでプライベートネットワークを追加

必須かどうかわからないですが、L2TP周りの設定にLAN側インターフェイスが必要だろうということでコントロールパネルから追加し。IPアドレス範囲が自宅などのセグメントとかぶらないように192.168.123.0/24などとします。すると192.168.123.1〜192.168.123.254のLANが構築されます。
サーバーにログインし、インターフェイスをeth1として固定IPアドレスを設定するには、/etc/sysconfig/network-scripts/ifcfg-eth1を作成します。

/etc/sysconfig/network-scripts/ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.12.1
NETMASK=255.255.255.0
DEVICE=eth1
ONBOOT=yes

xl2tpdを使用

OpenVPNやSoftEtherを使う方法もあるみたいですが、xl2tpdが機能的に過不足なさそうだったのでチョイス。
こちらのエントリを参考に、サーバー設定周りをすっとばして未設定分のみ実行。
https://qiita.com/yume_yu/items/09f57a8923341c5b2316
ただし、xl2tpd.confとl2tp-ipsec.confのとこで「サーバーのローカルIP」と書いてあるところは実際にはグローバルIPアドレスを指定する必要がありました。

firewalld

こちらのエントリが非常に参考になりました。ありがとうございます。
インストール済みでしたが起動はしてないので起動。

firewalld起動(2行目で毎回自動起動指定)
# systemctl start firewalld
# systemctl enable firewalld

初期状態ではeth0,eth1ともにpubicグループに登録されていたので、eth1は除外するためにinternalへ割当変更。

eth1をinternalグループに逃がす
firewall-cmd --zone=internal --change-interface=eth1

以下、暗黙的にpublicに対する設定になります。sshとdhcp6-clientは標準で有効化されていたので、WebとL2TP/IPSecに必要なもの(下3つ)を追加。

ルール追加
firewall-cmd --zone=public --add-service=http
firewall-cmd --zone=public --add-service=httpd
firewall-cmd --zone=public --add-service=ipsec
firewall-cmd --zone=public --add-port=1701/udp
firewall-cmd --zone=public --add-port=4500/udp
firewall-cmd --add-masquerade

あえて一旦--publicをつけないことでオンメモリの一時ルールになるので、動作確認後にまとめて永続化します。

設定確認(public)
firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh http https ipsec
  ports: 1701/udp 4500/udp
  protocols: 
  masquerade: yes
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

追加前はWebにアクセスできなかったのができるようになりました。保存(永続化)します。

永続化
firewall-cmd --runtime-to-permanent

ログの確認

firewalldの拒否ログの有効化と無効化
firewall-cmd --set-log-denied all
firewall-cmd --set-log-denied off
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1