centos怎样加静态路由

centos怎样加静态路由,第1张

一、ip route显示和设定路由

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11864830.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存