LoginSignup
2
2

More than 5 years have passed since last update.

ポートフォワードしたホストに外から接続したい

Posted at

状況

サーバーwebでhttpdが稼働しており、ここにアクセスできるのはサーバーfirewallからだけであるとする。手元のホストfumidaiからwebにアクセスすることを考える。

fumidaiからfirewallにSSHできる場合、ポートフォワードすればよい。fumidaiの8080をfirewall経由でwebの80に向けてやる。

fumidai:~$ slogin -L 8080:web:80 firewall
fumidai:~$ telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

ここでさらに、fumidaiにアクセスできる別クライアント(mymac)から、webにアクセスさせたくなった。しかし接続できない。

mymac:~$ telnet fumidai 8080
Trying aa.bb.cc.dd...
telnet: connect to address aa.bb.cc.dd: Connection refused
telnet: Unable to connect to remote host

fumidaiを見てみると、127.0.0.1:8080でlistenしている。これでは外からアクセスできない。

fumidai:~$ netstat -an | lv
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
:
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN
:

解決方法

これを解決するのに、8080を外から接続できるようにする。これにはGatewayPorts=yesをつけてポートフォワードしてやるとよい。

fumidai:~$ slogin -o GatewayPorts=yes -L 8080:web:80 firewall
fumidai:~$ netstat -an | lv
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
:
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN     
:
mymac:~$ telnet fumidai 8080
Trying aa.bb.cc.dd...
Connected to fumidai.
Escape character is '^]'.

参考文献

http://tetu1984.hateblo.jp/entry/20111109/1320840582
http://srad.jp/journal/301762/ssh-port-forwarding

2
2
2

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
2
2