よく使うネットワーク関連のコマンドをいちいち調べるのがめんどくさいので、一回まとめとく。
今回は Mac で使うものについて。linux は使えるやつもある。windows はいろいろ違いすぎるのでやらない。
オプションについては help の内容の内で使いそうなものだけにする。
詳しくは man ページを調べて下さい。
1. ping
ICMP の ECHO_REQUEST パケットを送信することで、接続できるか確認する。
デフォルトでは Control + C で停止し、パケロス率や RTT を表示する。
ping: option requires an argument -- h usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize] [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl] [-p pattern] [-S src_addr] [-s packetsize] [-t timeout][-W waittime] [-z tos] host ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload] [-M mask | time] [-m ttl] [-p pattern] [-S src_addr] [-s packetsize] [-T ttl] [-t timeout] [-W waittime] [-z tos] mcast-group Apple specific options (to be specified before mcast-group or host like all options) -b boundif # bind the socket to the interface -k traffic_class # set traffic class socket option -K net_service_type # set traffic class socket options -apple-connect # call connect(2) in the socket -apple-time # display current time
-c count : パケットの送信回数を指定する。
-f : floodping。パケットが戻ってくるとすぐ、もしくは、1 秒間に 100 回の、いずれか多い回数だけパケットを送る。 ネットワークに負荷がかかる。スーパーユーザのみ使用可能。
-i wait : パケットの送信間隔を指定する。デフォルトは 1 秒。
-m ttl : TTL を指定した値に設定する。
-s packetsize : 何バイトのデータを送信するか指定する。デフォルトは 56 で、ICMP ヘッダの 8 バイトを加えて、64 バイトの ICMP データになる。
ルータ(192.168.1.1)での使用例.
$ ping -c 3 -i 2 -s 1500 192.168.1.1 PING 192.168.1.1 (192.168.1.1): 1500 data bytes 1508 bytes from 192.168.1.1: icmp_seq=0 ttl=64 time=4.801 ms 1508 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=3.816 ms 1508 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=3.810 ms --- 192.168.1.1 ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 3.810/4.142/4.801/0.466 ms
2. ifconfig
ネットワークインターフェースの情報を表示、設定を行う。
usage: ifconfig [-C] [-L] interface address_family [address [dest_address]]
[parameters]
ifconfig interface create ifconfig -a [-C] [-L] [-d] [-m] [-u] [-v] [address_family] ifconfig -l [-d] [-u] [address_family] ifconfig [-C] [-L] [-d] [-m] [-u] [-v]
-a : 存在するインターフェイスごとの情報を表示する。
-l : 存在するインターフェイス名を表示する。
up(down) : 指定したインターフェイスを起動(終了)する。
使用例 : $ sudo ifconfig en0 up
ether : 指定したインターフェイスの MAC アドレスを変更する。
使用例 : $ sudo ifconfig en0 ether a0:07:aa:f5:11:28
$ ifconfig -a lo0: flags=8049<up,loopback,running,multicast> mtu 16384 options=1203<rxcsum,txcsum,txstatus,sw_timestamp> inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 nd6 options=201<performnud,dad> en0: flags=8863<up,broadcast,smart,running,simplex,multicast> mtu 1500 ether a0:07:aa:f5:11:28 ...</up,broadcast,smart,running,simplex,multicast></performnud,dad></rxcsum,txcsum,txstatus,sw_timestamp></up,loopback,running,multicast>
3. traceroute
通信経路上のルータのリストを表示する。
Usage: traceroute [-adDeFInrSvx] [-A as_server] [-f first_ttl] [-g gateway] [-i iface] [-M first_ttl] [-m max_ttl] [-p port] [-P proto] [-q nqueries] [-s src_addr] [-t tos] [-w waittime] [-z pausemsecs] host [packetlen]
-I : UDP のかわりに ICMP を使用する。
-w : タイムアウト時間(秒)を指定する。
$ traceroute -w 2 8.8.8.8 traceroute to 8.8.8.8 (8.8.8.8), 64 hops max, 52 byte packets 1 ntt.setup (192.168.1.1) 3.235 ms 1.245 ms 0.961 ms 2 153.153.242.250 (153.153.242.250) 6.452 ms 4.721 ms 4.506 ms 3 153.153.242.201 (153.153.242.201) 4.681 ms 5.652 ms 5.428 ms 4 153.153.252.133 (153.153.252.133) 5.812 ms 6.034 ms 5.948 ms 5...
4. netstat
network statistics” の略。ネットワーク接続状態やソケット/インターフェイスごとのネットワーク統計などを確認するために使用する。
Usage: netstat [-AaLlnW] [-f address_family | -p protocol] netstat [-gilns] [-f address_family] netstat -i | -I interface [-w wait] [-abdgRtS] netstat -s [-s] [-f address_family | -p protocol] [-w wait] netstat -i | -I interface -s [-f address_family | -p protocol] netstat -m [-m] netstat -r [-Aaln] [-f address_family] netstat -rs [-s]
-a : すべてのソケットを表示する。
-A : プロトコルの種別を選択(ipv4)。
使用例 $ netstat -A inet
-e : 詳細情報を表示する。
-l : Listen 状態のソケットの状態を表示する。
-n : 名前解決を行わず数字のまま出力する。
-r : ルーティングテーブルを表示する。
-t : tcp ソケットを表示する。
-u : udp ソケットを表示する。
-I : インターフェイスを指定。
$ netstat -nr Routing tables Internet: Address Destination Gateway Flags Refs Use Netif Expire default 192.168.1.1 UGSc 21 44 en0 127 127.0.0.1 UCS 0 0 lo0 127.0.0.1 127.0.0.1 UH 5 4175 lo0 169.254 link#5 UCS 0 0 en0 192.168.1 link#5 UCS 4 0 en0 192.168.1.1/32 link#5 UCS ...
コメント