はじめに
端末にインストールしたWSLを使用して、VirtualBoxの踏み台サーバー経由で、VirtualBoxのwebサーバーにssh接続を試しました。
以下のサイトで学びました。
infracollege
https://infracollege.vamdemicsystem.black/linux/
動作条件
VirtualBox仮想サーバー2台 ※2台ともCentOS7
VirtualBox仮想サーバー2台とも、パスワード認証の設定をしました。
以下を参考にしてください
https://qiita.com/gama1234/items/3ad5f698784af3fd39d1
WSLをWindows11端末にインストールした
以下のサイトを参考にしてください
https://qiita.com/gama1234/items/5828b2b2e4e9e1365711
構成図
手順
WSLにブリッチ接続設定をした
ブリッチ設定の方法は、以下のサイトを参考にしました。
https://qiita.com/shigeokamoto/items/d45d0a86aed7338a9dc9
/home/test
test@DESKTOP-0S2U0NI:~$
test@DESKTOP-0S2U0NI:~$ cat .wslconfig
[wsl2]
networkingMode=bridged
vmSwitch=my-switch
WSLのパッケージをアップデートをした
以下のサイトを参考にしました。
https://qiita.com/rubytomato@github/items/fdfc0a76e848442f374e
test@DESKTOP-0S2U0NI:~$ sudo apt update
test@DESKTOP-0S2U0NI:~$ sudo apt upgrade -y
WSLのSSHサービスを再起動しました
test@DESKTOP-0S2U0NI:~$ sudo service ssh restart
* Restarting OpenBSD Secure Shell server sshd [ OK ]
test@DESKTOP-0S2U0NI:~$
test@DESKTOP-0S2U0NI:~$ sudo service ssh status
* sshd is running
VirtualBox 踏み台サーバーのネットワーク設定した
アダプター1は、WSLと通信するため、ブリッジアダプターとしました
アダプター2 WEBサーバーへと通信するため、内部ネットワークとしました
VirtualBox 踏み台サーバーのipアドレスを設定した
アダプター1のipアドレス設定
設定値
ipアドレス
ホストOSのipアドレス「192.168.0.14」だったため、同じネットワークの任意なIPアドレス「192.168.0.2」にした。
Gateway
Windos端末のコマンドプロンプトを開き、以下のコマンドを実行した
ipconfig
DNSはGoogleのDNS「8.8.8.8」を設定した
アダプター2のipアドレス設定
ipアドレスは、ホストOSのipアドレス「192.168.0.xx」とは異なる任意なネットワーク「10.0.1.x」にした
ipアドレス設定後、networkサービスを再起動した
# systemctl restart network
VirtualBox WEBサーバーのネットワーク設定した
VirtualBox WEBサーバーのipアドレスを設定した
踏み台サーバーのIPアドレスが「10.0.1.2」だったため、同じネットワークの任意のIPアドレス「10.0.1.1」にした
ipアドレス設定後、networkサービスを再起動した
# systemctl restart network
WSLからVirtualBoxの踏み台サーバーへSSH接続した
パスワード認証でSSH接続した
test@DESKTOP-0S2U0NI:~$ ssh root@192.168.0.2
root@192.168.0.2's password:
Last login: Sun Jun 26 09:40:50 2022 from 192.168.0.14
WSLからVirtualBoxの踏み台サーバー経由して、WEBサーバーへSSH接続した
[root@localhost ~]# ssh root@10.0.1.1
root@10.0.1.1's password:
Last login: Sun Jun 26 09:33:13 2022 from 10.0.1.2