查看路由表的命令总结

行动环境

    • macOS Sierra 10.12.1

 

    Docker 1.12.3

为了确认在CentOS的各个版本中的命令,我们将使用Docker来启动每个版本。
※ 使用官方镜像 → https://hub.docker.com/_/centos/

每个命令

    • route [-F]

 

    • netstat -nr

 

    ip route show

CentOS 6.8 ->
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 版本的操作系统

在CentOS 7.2中,默认没有安装route / netstat命令,需要安装net-tools软件包以便使用。

但是不知道为什么,连ip命令都没有安装…
我本以为CentOS 7系默认就会安装…
不知道这个Docker镜像是否支持它还是一个谜。

通过安装iproute包,就可以像CentOS 6.8一样使用它了。

$ 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命令”进行操作哦~不仅可以进行路由表操作,还可以执行其他网络相关操作,你可以试着搜索一下,可能会有所帮助。

请参考以下资料

    • CentOS 7でネットワークの状態確認するためのipコマンド、ssコマンドについてメモ

 

    RHEL7/CentOS7でipコマンドをマスター
广告
将在 10 秒后关闭
bannerAds