カテゴリー
Network

Sophos XG Firewall Home Editionを導入した。

我が家のデフォルトゲートウェイは長らくEdgeRouter-Xに任せていたんですが、最近パケットロストかスループット低下が目に余るようになりリプレースしようかなの機運が。

いきなり信頼と実績の国産ルータYAMAHA RTXとかNEC IXとかに手を出そうかとも思いましたが、まずはEdgeRouter-X自体の性能不足なのかどうかを見極めるためにパワフルな物理マシンの上で仮想アプライアンスを使って切り分けしてみようと。それでもダメなら足回りのフレッツ回線の問題だし、改善したらEdgeRouter-Xのパワー不足だとはっきりするしね。

で、Sophos様はすごくて個人利用(ホームユース)であればSophos UTM/Sophos XG Firewallを無償提供してくれます。ネットワークエンジには自宅環境で思う存分使い倒して、ビジネス利用の時には是非FortigateやCheckPointでは無く、Sophosを選んでね!っていう心意気だと思います。すごい。

Sophos XG FirewallとSophos UTMの違い

UTM Firewall を Sophos XG Series または UTM 9 へアップグレード| Sophos UTM ソリューション
https://www.sophos.com/ja-jp/lp/utm-upgrades.aspx

ざっくりいうと、前からあったSophos SGシリーズのUTMと、買収してきた新しめのSophos XGシリーズのFirewallという感じ。

うちの環境では最初にSophos UTMを試してみたんですが、IPv4 over IPv6な構成を作れなくて、Sophos XG Firewallに早々に乗りかえました。

  • Sophos UTM = IPIP6トンネルに非対応?メニュー上は設定出来そうにない。Transix(DS-Lite)が利用出来ないのでNG。
  • Sophos XG Firewall = IPIP6トンネルに対応。WebUI上でぽちぽちすれば設定出来た。複数のトンネルを設定しておいてロードバランスするといったことは出来ない感じ。

Sophos UTMとSophos XG Firewallの動作環境

Sophos UTMのほうが動作環境としてはゆるめですが別なページを見てると保護対象のIPアドレスが50個までという制約があります。

Sophos XG Firewallは保護対象のIPアドレスの制約や機能制限は特になく、ただCPUが4コア、メモリが6GBまでしか利用出来ないという制限が付いてます。実際にはここに抵触するほどの多数のクライアントが接続してきたり、コンテンツフィルタリングを利用することは「一般のご家庭」では無いと思います。

Sophos XG Firewall Home Edition
Software appliance can be installed on a dedicated Intel™ – compatible PC.
Intel compatible computer with dual network interfaces. (Any previous OS or files on the computer will be overwritten when installing the XG Firewall Home Edition)
Home Edition is limited to 4 cores and 6 GB of RAM. The computer can have more than this, but XG Firewall Home Edition will not be able to utilize it.

Sophos UTM Home Edition
Software appliance can be either installed on a dedicated Intel™-compatible PC or within a virtual machine.
Virtual appliance can be run directly in any VMware vSphere Edition.

https://support.sophos.com/support/s/article/KB-000034600?language=en_US

Sophos XG Firewall Home Editionの入手

Sophos XG Firewall Home Edition
https://www.sophos.com/ja-jp/products/free-tools/sophos-xg-firewall-home-edition.aspx

Sophos XG Firewall用の仮想マシンの作成

Windows Admin Centerで仮想マシンを作ったときの設定をぺたり。

仮想マシンの世代は必ず「第1世代」にする。
CPUコア数は4以上を設定しても利用してくれない。
メモリは6GB上限であるが、実際には8GBくらいまでは物理割り当ての要求をしてきたので多めに。
ネットワークの1個目は必ずLAN側にする。
内蔵ハードディスクの量はお好みで。ログとかたくさんとっても128GBは使い切れない気がする。
ダウンロードしてきたISOファイルをマウントしておく。

ネットワークアダプタの設定は、1個目がLAN側、2個目がWAN側となるようにする。(そしてWindows Admin Centerだとそれが分かりにくいw)

上側の1個目がLAN側、下の2個目がWAN側である。

あとは仮想マシンの電源を入れてISOからインストールを行っていく。

Sophos XG Firewallのインストール

インストールを継続するか聞かれるので y で続行。
特に何かを指定することもなく1個目のハードディスクに問答無用でインストールされる。
インストール中は特に何も入れることはない。
(Installing Firmwareと出てるが実際はLinuxベースのOS起動環境がまるごと作られて書き込まれている=ファームウェアのバージョンアップやダウングレードも同じプロセス)
インストール完了の図。ビープ音が鳴る実機だとここで”エリーゼのために”が最大音量で流れてる。
https://twitter.com/imksoo/status/1358745149765918720
初回起動時のパスワードは admin である。
Port1 (LAN側) はデフォルトだとStatic IP指定。勝手にDHCPサーバになったりしない安心感。
Port 2 (WAN側)はデフォルトでDHCP Clientで動的にIPアドレスを拾ってくる。
LAN側のIPアドレスを変更するなら y を押す
お好みに応じてLAN側のIPアドレスを設定していく。※管理用WebUIのログインIPにもなる

後は管理用WebUIにログインして進めていく。

デフォルトのサーバ証明書は当然ながらオレオレ詐欺なので出てくる警告。
右上にちらっと言語選択がある。
日本語を選択。
クリックして続行。
管理者パスワードの設定。結構パスワードポリシーは厳しめ。
タイムゾーンの設定。ファイアウォールルールの中で時間帯に応じた設定が出来るので間違えないようにする。(平日日中帯は禁止、みたいなルールがかける)
メールで送られてきているシリアル番号を入力。
この辺はそのままで良い。
LAN側のIPアドレスがあってるか一応確認。
この辺は後で設定すれば良いので次へ。
メール通知先のアドレスを入力。
次へ。
青いこの画面でだいたい10分くらいかかる。
起動してきた(≧▽≦)

続きの初期セットアップは別ページで。

カテゴリー
Network Ubuntu

UbuntuでSoftEther VPNサーバを立てる

前提

今回のサーバにはVPN接続を受け付けるNICと、実際に内部でアクセスするためのNICの2つが接続されています。そのため、他のブログなどで書かれているようなブリッジ接続は実施していません。

SoftEtherの導入

$ wget https://www.softether-download.com/files/softether/v4.34-9745-rtm-2020.04.05-tree/Linux/SoftEther_VPN_Server/64bit_-_Intel_x64_or_AMD64/softether-vpnserver-v4.34-9745-rtm-2020.04.05-linux-x64-64bit.tar.gz
$ tar zxvf softether-vpnserver-v4.34-9745-rtm-2020.04.05-linux-x64-64bit.tar.gz
$ cd vpnserver/
$ make
$ sudo cp -r vpnserver /usr/local/
$ sudo chown -R root:root /usr/local/vpnserver/

SoftEtherの自動起動設定

softetherをubuntu18.04にインストールするhttps://qiita.com/rimksky/items/e169f9af83ce472b4ce3
のページを参考にさせて頂きました。

$ vim /etc/systemd/system/vpnserver.service
 [Unit]
 Description=SoftEther VPN Server
 After=network.target auditd.service
 ConditionPathExists=!/usr/local/vpnserver/do_not_run

 [Service]
 Type=forking
 EnvironmentFile=-/usr/local/vpnserver
 ExecStart=/usr/local/vpnserver/vpnserver start
 ExecStop=/usr/local/vpnserver/vpnserver stop
 KillMode=process
 Restart=on-failure
 Hardening
 PrivateTmp=yes
 ProtectHome=yes
 ProtectSystem=full
 ReadOnlyDirectories=/
 ReadWriteDirectories=-/usr/local/vpnserver
 CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_ADMIN CAP_SETUID

 [Install]
 WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable vpnserver.service
$ sudo systemctl start vpnserver.service

SoftEtherのVPNサービスのセットアップ

Windows機にSoftEtherの管理ツールを導入して、そこからGUIで設定しています。

初回ログイン時は管理者パスワードの設定を求められる以外は、後は初期セットアップウィザードで設定して回ればOK。

Let’s EncryptのCertbot導入

$ sudo apt install certbot

Certbotの設定

今回は簡単にHTTP 80番ポートが空いていたのでstandaloneモードでCertbot自身が一時的にHTTPアクセスを受け付けてホスト名を検証する方式で設定します。(80番ポートを他のApacheやNginx等が使っている場合は適合するプラグインを使ってください)

$ sudo certbot --standalone
imksoo@lainhv01:~$ sudo certbot certonly --standalone
 Saving debug log to /var/log/letsencrypt/letsencrypt.log
 Plugins selected: Authenticator standalone, Installer None
 Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
 to cancel): hostname.example.com,vpn.example.com
 Obtaining a new certificate
 IMPORTANT NOTES:
 Congratulations! Your certificate and chain have been saved at:
 /etc/letsencrypt/live/hostname.example.com/fullchain.pem
 Your key file has been saved at:
 /etc/letsencrypt/live/hostname.example.com/privkey.pem
 Your cert will expire on 2021-04-08. To obtain a new or tweaked
 version of this certificate in the future, simply run certbot
 again. To non-interactively renew all of your certificates, run
 "certbot renew"
 If you like Certbot, please consider supporting our work by:
 Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 Donating to EFF:                    https://eff.org/donate-le 
 imksoo@lainhv01:~$

上記でサーバ証明書には複数のドメイン名を持たせるため、certbotコマンドの中でカンマ区切りで複数指定しています。

SoftEtherが利用するサーバ証明書の更新を定期的に実施する

UbuntuのCertbotが定期的にSSL証明書の更新をするやり方をパクりました。SystemdでTimer実行します。

$ vim /lib/systemd/system/renew_vpnserver.timer
 [Unit]
 Description=Renew VPN Server certificate file.
 [Timer]
 OnCalendar=--* 04,16:00:00
 RandomizedDelaySec=43200
 Persistent=true
 [Install]
 WantedBy=renew_vpnserver.target
$ vim /lib/systemd/system/renew_vpnserver.service
 [Unit]
 Description=Renew VPN Server certificate file.
 [Service]
 Type=oneshot
 ExecStart=/usr/local/vpnserver/vpncmd localhost:5555 /server /password:P@ssw0rd /CMD ServerCertSet /LOADCERT:/etc/letsencrypt/live/hostname.example.com/fullchain.pem /LOADKEY:/etc/letsencrypt/live/hostname.example.com/privkey.pem
 PrivateTmp=true

後はTimerとServiceを有効化して実行しておきます。

$ sudo systemctl daemon-reload
$ sudo systemctl enable renew_vpnserver.timer
$ sudo systemctl start renew_vpnserver.timer
$ sudo systemctl start renew_vpnserver.service
$ sudo systemctl status renew_vpnserver.service
 ● renew_vpnserver.service - Renew VPN Server certificate file.
      Loaded: loaded (/lib/systemd/system/renew_vpnserver.service; static; vendor preset: enabled)
      Active: inactive (dead) since Fri 2021-01-08 22:39:20 JST; 6s ago
 TriggeredBy: ● renew_vpnserver.timer
     Process: 695134 ExecStart=/usr/local/vpnserver/vpncmd localhost:5555 /server /password:P@ssw0rd /CMD ServerCertSet >
    Main PID: 695134 (code=exited, status=0/SUCCESS)
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: Version 4.34 Build 9745   (English)
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: Compiled 2020/04/05 23:39:56 by buildsan at crosswin
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: Copyright (c) SoftEther VPN Project. All Rights Reserved.
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: Connection has been established with VPN Server "localhost" (port 5555).
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: You have administrator privileges for the entire VPN Server.
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: VPN Server>ServerCertSet /LOADCERT:/etc/letsencrypt/live/hostname.example.com/fullc>
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: ServerCertSet command - Set SSL Certificate and Private Key of VPN Server
 Jan 08 22:39:20 lainhv01 vpncmd[695134]: The command completed successfully.
 Jan 08 22:39:20 lainhv01 systemd[1]: renew_vpnserver.service: Succeeded.
 Jan 08 22:39:20 lainhv01 systemd[1]: Finished Renew VPN Server certificate file..
カテゴリー
Home Network

EdgeRouter-Xでポリシーベースルーティング(PBR)を使ってリモートデスクトップやSSHだけ経路を変更する

透過型プロキシの設定方法とほとんど一緒ですが、、、
AzureやAWS等のクラウド上のVMにリモートデスクトップ(RDP)接続したりSSH接続するときだけ、静的IPアドレスを持っているPPPoEセッション経由で通信させるように設定してみました。

前提として、通常のインターネット接続は動的NATになるDS-Lite接続側に流しておいて、RDP/SSHだけ固定IPアドレスを持っているPPPoE接続に流したいものとします。
# DS-LiteはIIJmio、PPPoEはi-revoを使ってます。

Fig.1 今回設定するネットワークの概念図

PPPoE接続の追加

set interfaces ethernet eth0 pppoe 0 default-route none
set interfaces ethernet eth0 pppoe 0 mtu 1492
set interfaces ethernet eth0 pppoe 0 name-server auto
set interfaces ethernet eth0 pppoe 0 password PASSWORD
set interfaces ethernet eth0 pppoe 0 user-id USER@i-revonet.jp

ここで重要なのは、default-route noneの記述。
これを書いていないとPPPoE接続がデフォルトルートとしてルートテーブルに載ってしまって、DS-Lite側にトラフィックを流せなくなります。

あとは適当にIPマスカレード(NAPT)の設定とか。

set service nat rule 5003 description 'masquerade for WAN'
set service nat rule 5003 log disable
set service nat rule 5003 outbound-interface pppoe0
set service nat rule 5003 protocol all
set service nat rule 5003 type masquerade

PBR用にルートテーブルを用意する

set protocols static table 10 interface-route 0.0.0.0/0 next-hop-interface pppoe0

後述するPBRで利用するルートテーブル10番を作成して、ネクストホップをPPPoE接続にしたデフォルトルートを持つようにします。

PBRで引っかける通信のフィルタ条件を用意する

set firewall modify PBR1 description 'PBR route for RDP/SSH'
set firewall modify PBR1 rule 100 action modify
set firewall modify PBR1 rule 100 destination address '!192.168.0.0/16'
set firewall modify PBR1 rule 100 destination port 22,3389
set firewall modify PBR1 rule 100 modify table 10
set firewall modify PBR1 rule 100 protocol tcp
set firewall modify PBR1 rule 101 action modify
set firewall modify PBR1 rule 101 destination address '!192.168.0.0/16'
set firewall modify PBR1 rule 101 destination port 3389
set firewall modify PBR1 rule 101 modify table 10
set firewall modify PBR1 rule 101 protocol udp

ルール100番は、自宅で使っているアドレス空間(192.168.0.0/16)以外の宛先に対する、TCP 22 (SSH)とTCP 3389 (RDP)の通信を引っかけて、ルートテーブル10番を利用するようにしています。

ルール110番は、同じくUDP 3389 (RDP)の通信を引っかけています。
# リモートデスクトップ接続はTCP/UDP 3389を両方セットで通信出来るようにしておくと、最初の認証系の通信以外はほぼUDPのみで通信してくれるようになって、応答性やロバスト性が向上することが多い。

PBRをインターフェースに適用する

set interfaces switch switch0 firewall in modify PBR1

リモートデスクトップ接続やSSH接続を利用するクライアントが所属するインターフェースに対して、PBRを設定する

実際に動いているか確認する

設定先のインターフェースを間違えると全然動かない!みたいなことになるので、そのときは統計ログを見てみると良い。

show firewall modify PBR1 statistics