Article View: pl.comp.os.linux.sieci
Article #244032Re: [ssh] połączenie po ssh przez podówny NAT
From: ein
Date: Fri, 15 Nov 2013 15:13
Date: Fri, 15 Nov 2013 15:13
112 lines
6142 bytes
6142 bytes
A wrote:
> W dniu 15.11.2013 12:34, ein pisze:
>> A wrote:
>>> Hej,
>>> wprawdzie trafiam na porady w internecie jak coś takiego wykonać ale
>>> jakoś nie mogę je przełożyć na mój przypadek. Mam tak:
>>>
>>>
>>> mójIP -- NAT -- Internet -- NAT -- zdalnyIP
>>> |
>>> router
>>> |
>>> serwer
>>>
>>> czyli chcę się przebić przez podwójny NAT, gdzie nie mam możliwości
>>> przekierowania portów na routerach to realizujących.
>>>
>>> Za to w sieci mam dostęp do serwera za routerem ale tam już mogę
>>> wystawić jego porty na zewnątrz, czyli wprawdzie serwer ma IP z klasy
>>> prywatnej ale router ma już statyczne IP z klasy publicznej.
>>>
>>> Do ZdalnyIP mam teraz dostęp przez TeamViewer ale to mało wygodne bo mi
>>> się bardzo wlecze interfejs a mnie wystarczy sama konsola.
>>>
>>> kombinowałem z parametrami -L i -R ale jakoś tak nieudolnie, że nie działa.
>>>
>>> Stąd moje pytanie: jak to poprawnie zestawić?
>>
>> Co chcesz osiągnąć?
>>
>
> Chcę się połączyć do konsoli na zdalnyIP siedząc przy mójIP. Nie mogę
> wykonać po prostu:
>
> ssh konto@zdalnyIP
>
> bo IP komputera zdalnyIP jest prywatne i za firewallem.
>
> A.
>
1. root@zdalnyIP:~# ssh root@serwer -R 22222:127.0.0.1:22 -v
Znaczy to przekieruj port 22 słuchający na interfejsie o adresie
127.0.0.1 na serwer
Przyjmując, że demon OpenSSH słucha na interfejsie pętli zwrotnej na
porcie 22, domyślna konfiguracja.
2. root@mojIP:~# ssh root@serwer -L 22222:127.0.0.1:22222 -v
Przyjmując, że port 22222/TCP jest wolny na: mojIP i serwer.
Znaczy przekieruj port 22222 z serwera na interfejs o adresie 127.0.0.1
i port 22222.
3. root@mojIP:~# ssh root@127.0.0.1 -p 22222 -v
Szczegóły w man ssh:
-L [bind_address:]port:host:hostport
Specifies that the given port on the local (client) host is
to be forwarded to the given host and port on the remote side. This
works by allocating a socket to listen to port on the local side,
optionally bound to the specified bind_address. Whenever a con‐
nection is made to this port, the connection is forwarded
over the secure channel, and a connection is made to host port hostport
from the remote machine. Port forwardings can also be specified in the
configuration file. IPv6 addresses can be specified by
enclosing the address in square brackets. Only the
superuser can forward privileged ports. By default, the local port is
bound in accordance with the GatewayPorts setting. However, an explicit
bind_address may be used to bind the connection to a specific
address. The bind_address of “localhost” indicates that
the listening port be bound for local use only, while an empty address
or ‘*’ indicates that the port should be available from all interfaces.
-R [bind_address:]port:host:hostport
Specifies that the given port on the remote (server) host
is to be forwarded to the given host and port on the local side. This
works by allocating a socket to listen to port on the remote side, and
whenever a connection is made to this port, the connection
is forwarded over the secure channel, and a connection is
made to host port hostport from the local machine.
Port forwardings can also be specified in the configuration
file. Privileged ports can be forwarded only when logging in as root on
the remote machine. IPv6 addresses can be specified by enclosing the
address in square braces.
By default, the listening socket on the server will be
bound to the loopback interface only. This may be overridden by
specifying a bind_address. An empty bind_address, or the address ‘*’,
indicates that the remote socket should listen on all interfaces.
Specifying a remote bind_address will only succeed if the
server's GatewayPorts option is enabled (see sshd_config(5)).
If the port argument is ‘0’, the listen port will be
dynamically allocated on the server and reported to the client at run
time. When used together with -O forward the allocated port will be
printed to the standard output.
-N Do not execute a remote command. This is useful for just
forwarding ports (protocol version 2 only).
-f Requests ssh to go to background just before command execution.
This is useful if ssh is going to ask for passwords or passphrases, but
the user wants it in the background. This implies -n. The recommended
way to start X11 programs at a remote site is with
something like ssh -f host xterm.
If the ExitOnForwardFailure configuration option is set to
“yes”, then a client started with -f will wait for all remote port
forwards to be successfully established before placing itself in the
background.
Poprawnie to zestawić można konfigurując VPNa np. OpenVPN, gdzie punktem
centralnym tzw. koncentratorem będzie serwer, a mojIP i zdalnyIP klientami.
Technical Details
Message-ID:
<l65dmf$11h$1@node1.news.atman.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mailReferences:
<l64m6r$i5c$1@portraits.wsisiz.edu.pl> <l650ru$q11$1@node2.news.atman.pl> <l652eb$sup$1@portraits.wsisiz.edu.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: ein <ein@no.spam> Newsgroups: pl.comp.os.linux.sieci Subject: Re: [ssh] połączenie po ssh przez podówny NAT Date: Fri, 15 Nov 2013 16:13:19 +0100 Organization: ATMAN - ATM S.A. Lines: 112 Message-ID: <l65dmf$11h$1@node1.news.atman.pl> References: <l64m6r$i5c$1@portraits.wsisiz.edu.pl> <l650ru$q11$1@node2.news.atman.pl> <l652eb$sup$1@portraits.wsisiz.edu.pl> NNTP-Posting-Host: 89-65-113-147.dynamic.chello.pl Mime-Version: 1.0 X-Trace: node1.news.atman.pl 1384528399 1073 89.65.113.147 (15 Nov 2013 15:13:19 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Fri, 15 Nov 2013 15:13:19 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130922 Icedove/17.0.9 In-Reply-To: <l652eb$sup$1@portraits.wsisiz.edu.pl> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit