# ノードの疎通確認

### Block Producer Nodeの疎通確認

クライアント（Relay Node）からBlock Producer Nodeの6000番ポートへ疎通が取れる状態か確認します。（以下、ポート番号は適宜変更）主にファイアウォールのポート確認になります。

正常な場合の表示

```
$ curl -v telnet://<BP_NODE_IP>:6000
*   Trying <BP_NODE_IP>:6000...
* TCP_NODELAY set
* Connected to <BP_NODE_IP> (<BP_NODE_IP>) port 6000 (#0)
```

NGの場合の表示（この場合Block Producer Nodeのファイアウォールを確認してください）

```
$ curl -v telnet://<BP_NODE_IP>:6000
*   Trying <BP_NODE_IP>:6000...
* TCP_NODELAY set　
```

Block Producer Nodeでcardano-nodeのサービス(サービス名は任意)が確認対象のポート(6000)でLISTENしてるか確認します。（`cardano-node run` コマンドで指定しているポートになります）

```
$ ss -lnpt
State        Recv-Q       Send-Q             Local Address:Port               Peer Address:Port       Process                                       
LISTEN       0            150                    127.0.0.1:12788                   0.0.0.0:*           users:(("cardano-node",pid=760,fd=17))       
LISTEN       0            4096               127.0.0.53%lo:53                      0.0.0.0:*                                                        
LISTEN       0            128                      0.0.0.0:22                      0.0.0.0:*                                                        
LISTEN       0            8                        0.0.0.0:6000                    0.0.0.0:*           users:(("cardano-node",pid=760,fd=27))      
LISTEN       0            150                      0.0.0.0:12798                   0.0.0.0:*           users:(("cardano-node",pid=760,fd=18))       
LISTEN       0            128                         [::]:22                         [::]:*                                                        
LISTEN       0            4096                           *:9100                          *:*              
~~~~~ 略 ~~~~~
```

Block Producer NodeでESTAB（TCPコネクションが確立した状態）か確認します。\
下記では、\<BP\_NODE\_IP>の6000ポートが\<RelayNode\_IP>の44545ポートとセッションを確立している事がわかります。反対にPeer Address列の\<RelayNode\_IP>の6000ポートが40969とセッションを確立しています（Relay Node側から同じ事が確認できます）。

ここで相手のRelay Nodeが表示されない場合はtopologyファイルの確認が必要です。

```
$ ss -tp
State     Recv-Q     Send-Q                 Local Address:Port                    Peer Address:Port     Process                                     
ESTAB     0          0                       <BP_NODE_IP>:40969                 <RelayNode_IP>:6000      users:(("cardano-node",pid=760,fd=31))     
ESTAB     0          64                      <BP_NODE_IP>:ssh                   <WorkingPC_IP>:60573                                                
ESTAB     0          0                       <BP_NODE_IP>:6000                  <RelayNode_IP>:44545     users:(("cardano-node",pid=760,fd=40))     
ESTAB     0          0                       <BP_NODE_IP>:12798                 <RelayNode_IP>:42296     users:(("cardano-node",pid=760,fd=35))     
~~~~~ 略 ~~~~~
```

### Relay NodeとBlock Producer Nodeの疎通確認

上記と同じ手順をRelay Nodeに対して実行します。

クライアント（Block Producer Node）からRelay Nodeの6000番ポートへ疎通が取れる状態か確認します。（以下、ポート番号は適宜変更）主にファイアウォールのポート確認になります。

正常な場合の表示

```
$ curl -v telnet://<RELAY_NODE_IP>:6000
*   Trying <RELAY_NODE_IP>:6000...
* TCP_NODELAY set
* Connected to <RELAY_NODE_IP> (<RELAY_NODE_IP>) port 6000 (#0)
```

NGの場合の表示（この場合Relay Nodeのファイアウォールを確認してください）

```
$ curl -v telnet://<RELAY_NODE_IP>:6000
*   Trying <RELAY_NODE_IP>:6000...
* TCP_NODELAY set　
```

Relay Nodeでcardano-nodeのサービス(サービス名は任意)が確認対象のポート(6000)でLISTENしてるか確認します。（`cardano-node run` コマンドで指定しているポートになります）

```
$ ss -lnpt
State    Recv-Q   Send-Q     Local Address:Port       Peer Address:Port   Process
LISTEN   0        150            127.0.0.1:12788           0.0.0.0:*       users:(("cardano-node",pid=1797,fd=17))
LISTEN   0        4096       127.0.0.53%lo:53              0.0.0.0:*
LISTEN   0        128              0.0.0.0:22              0.0.0.0:*
LISTEN   0        8                0.0.0.0:6000            0.0.0.0:*       users:(("cardano-node",pid=1797,fd=29))
LISTEN   0        150              0.0.0.0:12798           0.0.0.0:*       users:(("cardano-node",pid=1797,fd=18))
LISTEN   0        4096                   *:9100                  *:*
LISTEN   0        128                 [::]:22                 [::]:*
~~~~~ 略 ~~~~~
```

Relay NodeでESTAB（TCPコネクションが確立した状態）か確認します。\
下記では、\<RELAY\_NODE\_IP>の6000ポートが\<BP\_NODE\_IP>の43603ポートとセッションを確立している事がわかります。反対にPeer Address列の\<BP\_NODE\_IP>の6000ポートが\<RELAY\_NODE\_IP>の40969ポートとセッションを確立しています。\
BlockProducer Nodeと比べて、トポロジーファイルに書かれている外部のRelayNodeの分だけ出力があります。

ここでBlock Producer Nodeが表示されない場合はtopologyファイルの確認が必要です。

```
$ ss -tp
State Recv-Q Send-Q          Local Address:Port              Peer Address:Port  Process 
ESTAB 0      0             <RELAY_NODE_IP>:6000              <BP_NODE_IP>:43603  users:(("cardano-node",pid=1797,fd=67))                         
ESTAB 0      0             <RELAY_NODE_IP>:40969             <BP_NODE_IP>:6000   users:(("cardano-node",pid=1797,fd=30))                         
ESTAB 0      0             <RELAY_NODE_IP>:41410             <BP_NODE_IP>:9100                                                                   
ESTAB 0      0             <RELAY_NODE_IP>:40034             <BP_NODE_IP>:12798
~~~~~ 略 ~~~~~
```

### パブリックからRelay Nodeへの疎通確認

（ファイアウォールでIP指定のアクセス制限をかけていない限り）Block Producer NodeからRelayNodeの疎通確認が問題なければ外部からもアクセスが可能な状態になります。\
その上でRelayNodeでのトランザクションが増えない場合は、DBが同期されるのを待ってみる、topologyファイルとファイアウォールの確認（IPとポートが許可されているか）が必要となります。

### その他確認ツール

「Relay Node <-> Block Producer Node」、「作業端末 -> RelayNode」の疎通確認の他、不要なポートが開いていないかなどのチェックにも使えます。

#### Nmap

`nmap`は対象のノードに対してポートスキャンをすることで、どのポートが外部からアクセス可能な状態か調査することができるツールです。 （別途`sudo apt install nmap`でインストールが必要です）<br>

```
$ nmap <RELAY_NODE_IP> -Pn

Starting Nmap 6.40 ( http://nmap.org ) at 2020-08-13 09:46 UTC
Nmap scan report for <BP_NODE_IP>
Host is up (0.021s latency).
Not shown: 999 filtered ports
PORT     STATE SERVICE
6000/tcp open  nessus  <<<<< 6000ポートのみが開放されていることが分かりました。
```

上記は作業端末からRelay Nodeに対して実行した例になります。\
作業端末からBlock Producer Nodeに対して実行した場合は`22/tcp open ssh`以外は不要なため、表示されない事が望ましいです。（sshのポート番号は任意）<br>

#### 疎通確認できるウェブサイト

余計なツールをインストールしたくない場合、Relay Nodeに関しては、<https://www.cman.jp/network/support/port.html> など、インターネットからノードに対して、IPとポートを指定して確認ができるサイトがあります。作業端末のPCからは`curl -v telnet://<RelayNode_IP>:6000`などで確認可能です。\
\
Block Producer Nodeに関しては、主にRelay Nodeからのみ確認可能です。（作業端末からコネクションが張れてしまった場合は再確認してください）


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sugar-stake-pool.gitbook.io/cardano-kb/cardano-node-operation/ndono.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
