0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

社内セキュリティ都合でHyper-VのDefaultSwitch に接続したVMに接続できない仕様を回避する

Posted at

CML2を利用したいが仮想基盤のリソースの利用はスタンプラリーをしなくてはいけない、許可が出るかわからない点を相談したらHyper-Vなら利用OKとのことで、Hyper-Vの有効化とインストールをしたらアクセスできなかったのでどうにかする話。

構成
・Windows 11(貸与PC)
・Hyper-V
・WSL2

社内セキュリティのためか、VPN経由社内のアドレスかローカルホストのアドレスしか接続できない仕様となっており、Hyper-VのDefaultSwitchに接続したVMは通常DHCPでアドレスを払い出されるが、IPの払い出しはされない状態。
固定IPアドレスを設定すれば、DefaultSwitch の内部から外にはアクセスできる。
WSL用のSwitchに接続しても同様。
Hyper-V SwitchManagerの外部接続を利用すると、ローカル(192.168.x.x/24 の自宅セグメント)のIPが割り当てられるが、Windows 11 からはアクセス不可。

WSL2でにはlocalhost:<ポート番号> でアクセス可能。

アクセスするためにはWSLg のfirefox からアクセスすれば、利用可能。→利用がめんどくさいのと、ローカル(自宅サーバ)にアクセスできる状態のため、利用したくない。
Hyper-V WSL間のフォワーディングについて:https://zenn.dev/gekal/articles/connect-wsl-and-hyperv-network-forwarding

そのため、WLS2でnginx をリバースプロキシ(パススルー)を実施することで、Windows 11のブラウザからアクセスできるようにした。

実施内容
nginxディレクトリ(docker のbind mount用)を作成し、その中にnginx.conf ファイルを作成。

nginx/nginx.conf
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}

stream {
    # HTTP (ポート80) passthrough
    server {
        listen 80;
        proxy_pass 172.19.68.183:80;
    }

    # HTTPS (ポート443) passthrough
    server {
        listen 443;
        proxy_pass 172.19.68.183:443;
    }

    # Cockpit (ポート9090) passthrough
     server {
        listen 9090;
        proxy_pass 172.19.68.183:9090;
    }   
}

docker でポートフォワーディング用のコンテナを作成する

sudo docker run -d -p 80:80 -p 443:443 -p 9090:9090 -v ./nginx:/etc/nginx nginx
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?