Help us understand the problem. What is going on with this article?

Mac OS Xのネットワーク関連コマンド

More than 3 years have passed since last update.

Mac OS XはBSD系のため、普段使用しているLinuxとは若干違うネットワーク関連コマンドを表示機能を中心にまとめていきます。

インターフェイス表示

各種ネットワークインターフェイスの一覧、MACアドレス、IPアドレスなどの情報を確認出来ます。VMware Fusionが作成するブリッジなども表示されます。

$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 ::1 prefixlen 128
    inet 127.0.0.1 netmask 0xff000000
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
    nd6 options=1<PERFORMNUD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether XX:XX:XX:XX:XX:XX
    inet6 fe80::XXXX:XXXX:XXXX:XXXX%en0 prefixlen 64 scopeid 0x4
    inet 192.168.10.22 netmask 0xffffff00 broadcast 192.168.10.255
    nd6 options=1<PERFORMNUD>
    media: autoselect
    status: active
en1: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
    options=60<TSO4,TSO6>
    ether XX:XX:XX:XX:XX:XX
    media: autoselect <full-duplex>
    status: inactive
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether XX:XX:XX:XX:XX:XX
    inet 172.16.44.1 netmask 0xffffff00 broadcast 172.16.44.255
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether XX:XX:XX:XX:XX:XX
    inet 192.168.246.1 netmask 0xffffff00 broadcast 192.168.246.255

ルーティングテーブル表示

IPv4とIPv6のルーティングテーブルを確認できます。DHCPで割り当てられたデフォルトルートを確認する時などに使えます。

$ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.10.1        UGSc         1016      127     en0
127                127.0.0.1          UCS             1        0     lo0
127.0.0.1          127.0.0.1          UH              7   155581     lo0
192.168.10         link#4             UCS             6        0     en0
192.168.10.1/32    link#4             UCS             7        0     en0
192.168.10.1       XX:XX:XX:XX:XX:XX  UHLWIir       370     3975     en0    712
192.168.10.21      XX:XX:XX:XX:XX:XX  UHLWIi          3  1877296     en0   1143

Internet6:
Destination                             Gateway                         Flags         Netif Expire
::1                                     ::1                             UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::XX:XXXX:XXXX:XXX%en0              XX:XX:XX:XX:XX:XX               UHLWIi          en0
fe80::XXX:XXXX:XXXX:XXXX%en0            XX:XX:XX:XX:XX:XX               UHLWIi          en0

LISTENポート表示

現在マシンでLISTENしているIPアドレスとポートを表示します。nオプションを追加するとサービス名ではなくポート番号のまま表示されます。

$ netstat -aL
Current listen queue sizes (qlen/incqlen/maxqlen)
Listen         Local Address
0/0/5          localhost.51004
0/0/128        *.6000
0/0/128        *.6000
3/0/128        *.55540
0/0/128        *.17500
0/0/128        localhost.17603
0/0/128        localhost.17600
0/0/128        localhost.6263
0/0/128        localhost.6263
0/0/128        localhost.6258
0/0/128        localhost.6258
0/0/128        localhost.6379
0/0/128        *.http
0/0/2          localhost.49153
0/0/2          localhost.49152

ARPテーブル表示

ARPテーブルの一覧を表示します

$ arp -a
? (172.16.44.255) at (incomplete) on vmnet1 ifscope [ethernet]
? (172.17.8.255) at (incomplete) on vmnet2 ifscope [ethernet]
? (192.168.10.1) at XX:XXXX:XXXX:XXX on en6 ifscope [ethernet]
? (192.168.10.23) at XX:XXXX:XXXX:XXX on en6 ifscope [ethernet]
? (192.168.10.255) at (incomplete) on en6 ifscope [ethernet]
? (192.168.246.255) at (incomplete) on vmnet8 ifscope [ethernet]

ARPエントリー削除

特定のARPエントリーを削除するにはroot権限が必要なため、sudoコマンドで実行します。

$ sudo arp -d 192.168.10.23
192.168.10.23 (192.168.10.23) deleted
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away