Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions.You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site.... 

Always Active

Necessary cookies are required to enable the basic features of this site,such as providing secure log-in or adjusting your consent preferences.These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms,collecting feedback,and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website.These cookies help provide information on metrics such as the number of visitors,bounce rate,traffic source,etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

MacでSSHポートフォワーディングして踏み台サーバ経由でブラウザからWebアクセスする。

この記事は約2分で読めます。

スポンサーリンク

はじめに

IP制限のあるサーバにアクセスしたいときに、踏み台サーバを経由してアクセスすることがあります。
今回は、SSHポートフォワーディング(SSHトンネル)のダイナミックポートフォワードを利用してブラウザを利用したWebアクセスを踏み台経由にします。

環境

  • クライアントPC (本記事ではMac)
  • AllowTcpForwardingがyesに設定されているリモートサーバ
  • SSHの接続方式は、公開鍵認証
スポンサーリンク

Macから踏み台サーバ経由でブラウザからWebアクセスする

Macのプロキシを設定する

今回は、システムのプロキシ設定を参照するブラウザ(ChromeやEdge)を利用します。

ネットワーク設定から、接続しているネットワークの詳細設定を開きます。
プロキシの項目から、SOCKSプロキシを有効にして以下のように設定します。

  • サーバ:127.0.0.1
  • ポート:任意の空きポート

コマンドを実行する

以下のコマンドをターミナルにて実行します。

ssh -i ~/.ssh/秘密鍵 -D SOCKSプロキシのポート  ユーザ名@ホスト -p ポート

接続が成功したら、対象のブラウザからWebアクセスをしてみます。
今回のリモートサーバは、さくらVPSであったため、以下の画像の通り、
さくらVPSを経由してHTTP/S通信できていることが確認できます。

 

補足

SSHポートフォワーディングするとき、以下のオプションを付けて実行もできます。

-fN

-f

オプションを使用すると、SSHコマンドをバックグラウンドで実行できます。
-Nオプションは、リモートコマンドを実行せずにSSH接続を確立するために使用されます。

おわりに

一般には、アクセス制限のあるサーバに踏み台としてSSHポートフォアーディングを利用しますが、
アクセス制限のあるネットワークから解放できる方法でもありますね。。sshの制限や監視次第ですが。

また、海外リージョンのサービスを利用して海外を経由でネットサーフィン等もできますね。

参考文献

https://qiita.com/fkshom/items/844a1be031ae3eb4bcea

コメント

スポンサーリンク
スポンサーリンク
タイトルとURLをコピーしました