1、显示路由表
[root@centos7 ~]# ip route show
default via 192.168.150.254 dev enp0s3 proto static metric 1024192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110
太难看了,格式化一下(显示的是默认网关和局域网路由,两行的内容没有共通性):
[root@centos7 tmp]# ip route show|column -t
default via 192.168.150.254 dev enp0s3 proto static metric 1024192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110
2、添加静态路由
[root@centos7 ~]# ip route add 10.15.150.0/24 via 192.168.150.253 dev enp0s3
[root@centos7 ~]#
[root@centos7 ~]# ip route show|column -t
default via 192.168.150.254 dev enp0s3 proto static metric 102410.15.150.0/24 via 192.168.150.253 dev enp0s3 proto static metric 1192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110[root@centos7 ~]#
[root@centos7 ~]# ping 10.15.150.1PING 10.15.150.1 (10.15.150.1) 56(84) bytes of data.64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.77 ms64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.08 ms64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.57 ms
^C
3、删除静态路由
只需要把 add 替换成 del,或者更简单的只写目标网络
[root@centos7 ~]# ip route del 10.15.150.0/24
[root@centos7 ~]# ip route add 10.15.150.0/24 via 192.168.150.253 dev enp0s3[root@centos7 ~]#
[root@centos7 ~]# ip route show|column -t
default via 192.168.150.254 dev enp0s3 proto static metric 1024 10.15.150.0/24 via 192.168.150.253 dev enp0s3 proto static metric 1 192.168.150.0/24 dev enp0s3 proto kernel scope link src 192.168.150.110
[root@centos7 ~]#
[root@centos7 ~]# ping 10.15.150.1
PING 10.15.150.1 (10.15.150.1) 56(84) bytes of data. 64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.77 ms 64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.08 ms 64 bytes from 10.15.150.1: icmp_seq=1 ttl=63 time=1.57 ms
^C
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)