0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Network】IPアドレスとサブネットマスクについて

Last updated at Posted at 2023-03-28

IPアドレスについて

ネットワーク上の各機器に割り振られた機器を識別する為の番号です。
通信を行う際に、利用されます。ネットワーク上の住所と例えられたりします。

IPアドレスは、32ビット(2進数)で表記されています。
普段よく目にする192.168.0.1等の10進数で表記されているIPアドレスは、人に分かりやすいように変換されているものです。

2進数を10進数に変換
11000000 10101000 00000000 00000001 
                 ↓
     192      168        0        1   

IPアドレスは、ネットワーク部・ホスト部で構成されています。
ネットワーク部はIPアドレスが属しているネットワークを表しており、ホスト部はそのネットワーク内の機器を表しています。

192.168.0.1/24の場合は、前半24ビットがネットワーク部/後半8ビットがホスト部となります。
192.168.0がネットワーク部で、1がホスト部となります。

192.168.0.1/24192.168.0.2/24は同じネットワークで通信が可能です。
192.168.0.1/24192.168.1.1/24だとネットワークが違うので、通信を行う事が出来ないです。

Packet Tracerで確認してみます。
下記のように、PCを二つ用意しました。192.168.0.1/24192.168.0.2/24でIPアドレス/サブネットの設定を行っています。

image.png

192.168.0.1/24と192.168.0.2/24
C:\>ping 192.168.0.2

Pinging 192.168.0.2 with 32 bytes of data:

Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

通信出来ている事を確認致しました。次に、192.168.0.1/24192.168.1.1/24で試してみます。

192.168.0.1/24と192.168.1.1/24
C:\>ping 192.168.1.1

Pinging 192.168.1.1 with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.1.1:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

ネットワークが違うので、失敗致しました。

サブネットマスクについて

サブネットマスクは、IPアドレスのネットワーク部で使用するビット数を定義するものです。
サブネットマスクを指定する事で、ネットワーク部とホスト部がどこで区切られているかが分かります。

サブネットマスクが255.255.255.0で設定されている場合を想定します。
255.255.255.0を一旦、2進数に変換します。11111111 11111111 11111111 00000000 となります。
2進数で1の部分がネットワーク部となります。0はホスト部となります。

ホスト部は10進数に変換すると、2^8=256までの値が該当する事がわかりました。
ネットワークアドレス(ホスト部が全て0)とブロードキャストアドレス(ホスト部が全て1)は予約されているIPとなる為、ネットワーク内に254個のホストアドレスを設定出来ます。

サブネットマスクを255.255.254.0で設定して、pingを飛ばしてみます。
2進数に変換すると、11111111 11111111 11111110 00000000です。
なので、ホストアドレスを2^9-2=510は作れます。
IPアドレスを192.168.1.254で設定します。

192.168.0.1/23と192.168.1.254/23
C:\>ping 192.168.1.254

Pinging 192.168.1.254 with 32 bytes of data:

Reply from 192.168.1.254: bytes=32 time<1ms TTL=128
Reply from 192.168.1.254: bytes=32 time<1ms TTL=128
Reply from 192.168.1.254: bytes=32 time<1ms TTL=128
Reply from 192.168.1.254: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.1.254:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

通信出来ました。
以上です。

0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?