![OpenWrt 上のサーバーを WAN に公開するべきでしょうか、それとも WAN からのポート転送を使用して LAN のみに公開するべきでしょうか?](https://rvso.com/image/1654783/OpenWrt%20%E4%B8%8A%E3%81%AE%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%82%92%20WAN%20%E3%81%AB%E5%85%AC%E9%96%8B%E3%81%99%E3%82%8B%E3%81%B9%E3%81%8D%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%81%8B%E3%80%81%E3%81%9D%E3%82%8C%E3%81%A8%E3%82%82%20WAN%20%E3%81%8B%E3%82%89%E3%81%AE%E3%83%9D%E3%83%BC%E3%83%88%E8%BB%A2%E9%80%81%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%20LAN%20%E3%81%AE%E3%81%BF%E3%81%AB%E5%85%AC%E9%96%8B%E3%81%99%E3%82%8B%E3%81%B9%E3%81%8D%E3%81%A7%E3%81%97%E3%82%87%E3%81%86%E3%81%8B%3F.png)
ルーターの背後にあるコンピューターにサーバーをインストールし、インターネットからの接続を許可したい場合は、次の 2 つのことを行う必要があります。1 つは、サーバー マシンのファイアウォールを開いて着信接続を許可すること、もう 1 つは、ルーターでポート転送ルールを設定して、接続が WAN から LAN (具体的にはサーバー マシン) に行われるようにすることです。
しかし、問題のサーバーマシンが OpenWrt 上で実行されているルーター自体である場合はどうすればよいでしょうか?
2つの選択肢が考えられます。
オプション A。ルーターを LAN 内の他のコンピューターと同じように扱います。ルーターにサーバーをインストールした後、ファイアウォールを開いて、LAN 内からサーバーへの着信接続を許可します。(これは、LuCI > ネットワーク > ファイアウォール > トラフィック ルールで実行できると思います。) 次に、WAN から LAN (具体的にはサーバー) へのポート転送ルールを設定します。(LuCI > ネットワーク > ファイアウォール > ポート転送。)
オプション B。LuCI のトラフィック ルール タブを使用して、WAN からサーバーに直接接続するためのファイアウォールを開きます。
質問は次のとおりです:
これらが私が検討できる 2 つの選択肢であると考えるのは正しいでしょうか?
それぞれの側の長所と短所は何でしょうか?
標準的な方法は何ですか?
問題のサーバーは、VPN サーバー (例: Wireguard) または OpenSSH である可能性があり、Dropbear の代わりにインストールする可能性があります。ただし、OpenWrt に A/V ストリーム サーバーをインストールした場合 (可能と仮定した場合)、同じ質問が発生します。言い換えると、この質問は、特定のソフトウェア (Wireguard など) に限定されるのではなく、上記の 2 つのオプションに関する一般的な質問のままにしておきたいということです。
私は OpenWrt も Linux も初心者です。OpenWrt の存在を知ったのはほんの数日前でした。オプション A は突飛な (誰もやらない) もので、私の脳が OpenWrt のようなものを見たことがなく、「通常のルーター」という観点でしか考えられないためにそれを思いついただけなのかもしれません。
実際、オプション A の方が有利かもしれないと思います。実際にポート転送はやったことがありますが、Linux ファイアウォールは初めてです。そのため、トラフィック ルールを大量に使用して、問題が LAN 内でのみ発生するようにするとよいでしょう。
アドバイスをお願いします。ありがとうございます。
付録
これらはオプション A (左) とオプション B (右) を示す LuCI スクリーンショットです。左側のパネルは、ポート 12000 が LAN に開かれていることを前提としています (デフォルト ポリシーまたは特定のトラフィック ルールにより)。192.168.1.1 はルーターの LAN IP アドレスです。
答え1
(一部のブラウザでは表示されませんが、各ファイルパスはリンクです)
SSHの場合、標準的な方法は、DNATルール [ポート転送] は、それが存在する内部ネットワークに適用されます。一方、VPN サーバーの場合は、サーバー ポートへの WAN アクセスを許可するルールを作成します。
- ワイヤーガードウィキ
- パスワード:
/etc/config/firewall
:# ##::[[--- OpenWrt WAN Firewall Config ---]]::## #=========================================================== ##----- NAT Redirects -----## #=========================================================== # SSH # #----------------------------------------------------------- config redirect option target 'DNAT' option proto 'tcp' option src 'wan' option src_dport 60501 option dest 'lan' option dest_ip 192.168.1.1 option dest_port 22 option name 'Allow Redirect WAN → LAN (SSH)' config redirect option target 'DNAT' option proto 'tcp' option src 'vpn' option src_dport 60502 option dest 'lan' option dest_ip 192.168.1.1 option dest_port 22 option name 'Allow Redirect Wireguard → LAN (SSH)' #=========================================================== ##----- VPN Zones -----## #=========================================================== # Wireguard # #----------------------------------------------------------- config zone option name 'vpn' option network 'vpn' option input 'ACCEPT' option forward 'ACCEPT' option output 'ACCEPT' option log 1 # Rules: #----------------------------------------------------------- config rule option target 'ACCEPT' option proto 'tcp udp' option src 'wan' option dest '*' option dest_port 51820 option name 'Allow Forwarded Wireguard → Router' config rule option target 'ACCEPT' option proto 'tcp' option src 'vpn' option dest '*' option dest_port 60502 option name 'Allow Wireguard → Router (SSH)'
/etc/config/dropbear
:# ##::[[--- OpenWrt DropBear Config ---]]::## #=========================================================== ##----- Default -----## #=========================================================== # Server # #----------------------------------------------------------- config dropbear option enable 1 option Interface 'lan' option PasswordAuth 'off' option RootPasswordAuth 'off' option IdleTimeout 0 option Port 22 option RootLogin 1 option SSHKeepAlive 300 option verbose 1
/etc/ssh/sshd_config
: (カスタマイズ)# ##::[[--- OpenWrt OpenSSH SSHd Config ---]]::## #=========================================================== ##----- Global Options -----## #=========================================================== # Please verify, as all algorithms may not supported: # Ciphers: # HostKey & KeyTypes ## ssh -Q cipher ## ssh -Q key # Kex [Key Exchange] # MAC [Message Authentication Code] ## ssh -Q kex ## ssh -Q mac # Connection # #----------------------------------------------------------- AddressFamily = inet ListenAddress = 192.168.1.1:22 # Encryption # #----------------------------------------------------------- AuthorizedKeysFile = /root/.ssh/authorized_keys HostKey = /etc/ssh/ssh_host_ed25519_key HostKey = /etc/ssh/ssh_host_rsa_key # Authentication # #----------------------------------------------------------- AllowUsers = root AllowGroups = root ChallengeResponseAuthentication = no PasswordAuthentication = no PermitEmptyPasswords = no StrictModes = yes PubkeyAuthentication = yes LoginGraceTime = 30 MaxAuthTries = 3 MaxSessions = 10 MaxStartups = 3:30:10 PermitRootLogin = prohibit-password # Reliability # #----------------------------------------------------------- ClientAliveCountMax = 3 ClientAliveInterval = 600 TCPKeepAlive = yes UseDNS = yes # Security # #----------------------------------------------------------- AllowAgentForwarding = yes AllowTcpForwarding = yes GatewayPorts = clientspecified PermitTunnel = yes Subsystem sftp = /usr/lib/sftp-server RekeyLimit = 500M 60m # Logging # #----------------------------------------------------------- SyslogFacility = AUTH LogLevel = VERBOSE PidFile = /tmp/run/sshd.pid # Ciphers and ReKeying # #----------------------------------------------------------- FingerprintHash = sha256 Ciphers = [email protected],[email protected],aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,[email protected] HostKeyAlgorithms = ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 HostbasedAcceptedKeyTypes = ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 KexAlgorithms = [email protected],curve25519-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256 MACs = [email protected],[email protected],hmac-sha2-256,hmac-sha2-512 PubkeyAcceptedKeyTypes = ssh-ed25519,ssh-rsa,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
- ルシ:
https://<router IP>
→通信網 (左側のメニュー)→ファイアウォール- 交通規則
- 追加:
名前:Allow Forwarded Wireguard → Router
プロトコル:TCP UDP
ソースゾーン:wan
目的地ゾーン:Any zone (forward)
宛先ポート:51820
アクション:accept
保存 - 追加:
名前:Allow Wireguard → Router (SSH)
プロトコル:TCP
ソースゾーン:vpn
目的地ゾーン:Any zone (forward)
宛先ポート:60502
アクション:accept
保存
- 追加:
- ポート転送
- 追加:
名前:Allow Redirect WAN → LAN (SSH)
プロトコル:TCP
ソースゾーン:wan
外部ポート:60501
目的地ゾーン:lan
内部 IP アドレス:192.168.1.1
内部ポート:22
アクション:accept
保存 - 追加:
名前:Allow Redirect VPN → LAN (SSH)
プロトコル:TCP
ソースゾーン:vpn
外部ポート:60502
目的地ゾーン:lan
内部 IP アドレス:192.168.1.1
内部ポート:22
アクション:accept
保存
- 追加:
- 保存して適用