LoginSignup
3
9

More than 5 years have passed since last update.

ルーティングテーブルの確認コマンドまとめ

Posted at

動作環境

  • macOS Sierra 10.12.1
  • Docker 1.12.3

CentOSの各バージョンにおけるコマンド確認のために、Dockerで各バージョンのものを起動していきます
※ official image を使用 → https://hub.docker.com/_/centos/

各コマンド

  • route [-F]
  • netstat -nr
  • ip route show

CentOS 6.8

CentOS 6.8 では ip コマンドがデフォルトでインストールされておらず、
iproute パッケージをインストールすることで利用が可能になります。

$ docker run -it --hostname centos6 --rm centos:6 /bin/bash

[root@centos6 /]# cat /etc/redhat-release
CentOS release 6.8 (Final)

[root@centos6 /]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         172.17.0.1      0.0.0.0         UG    0      0        0 eth0
172.17.0.0      *               255.255.0.0     U     0      0        0 eth0

[root@centos6 /]# route -F
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         172.17.0.1      0.0.0.0         UG    0      0        0 eth0
172.17.0.0      *               255.255.0.0     U     0      0        0 eth0

[root@centos6 /]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         172.17.0.1      0.0.0.0         UG        0 0          0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 eth0

[root@centos6 /]# ip route show
bash: ip: command not found

[root@centos6 /]# yum install -y iproute

[root@centos6 /]# ip route show
default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0  proto kernel  scope link  src 172.17.0.2

CentOS 7.2

CentOS 7.2 では route / netstat コマンドがデフォルトでインストールされておらず、
net-tools パッケージをインストールすることで利用が可能になります。

そしてなぜか ip コマンドもインストールされておらず・・・
CentOS 7系ならデフォルトでインストールされてるもんだと思ってた・・・
このDockerイメージが対応していないだけなのか否かは謎

CentOS 6.8 と同様に iproute パッケージをインストールすることで利用が可能になった

$ docker run -it --hostname centos7 --rm centos:7 /bin/bash

[root@centos7 /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

[root@centos7 /]# route
bash: route: command not found

[root@centos7 /]# netstat -nr
bash: netstat: command not found

[root@centos7 /]# yum install -y net-tools

[root@centos7 /]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0

[root@centos7 /]# route -F
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0

[root@centos7 /]# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         172.17.0.1      0.0.0.0         UG        0 0          0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U         0 0          0 eth0

[root@centos7 /]# ip route show
bash: ip: command not found

[root@centos7 /]# yum install -y iproute

[root@centos7 /]# ip route show
default via 172.17.0.1 dev eth0
172.17.0.0/16 dev eth0  proto kernel  scope link  src 172.17.0.3

まとめ

まあとりあえず今後は、「iproute パッケージに含まれる ip コマンドを使うことを推奨していくよ〜」とのことでした
ルーティングテーブルの他にもネットワーク関連の操作を多数行うことが出来るのでググってみると良いかもしれません

参考資料

3
9
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
3
9