美文网首页沙大斌AlmaLinux
20220726-Alma Linux8添加静态路由

20220726-Alma Linux8添加静态路由

作者: 負笈在线 | 来源:发表于2022-07-26 11:37 被阅读0次

一、临时添加和删除静态路由

1、显示路由表

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 ens33
172.26.37.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33

2、临时添加静态路由

# route add -net  172.26.38.0/24 gw 172.26.37.253 ens33
# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 ens33
172.26.37.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
172.26.38.0     172.26.37.253   255.255.255.0   UG    0      0        0 ens33

3、临时删除静态路由

# route del -net  172.26.37.0/24

二、设置永久的静态路由

永久静态路由需要写到 /etc/sysconfig/network-scripts/route-interface 文件中

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 ens33
172.26.37.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33

# vi /etc/sysconfig/network-scripts/route-ens33
172.26.38.0/24 via 172.26.37.253

# ifdown ens33 && ifup ens33     或者重启系统

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         _gateway        0.0.0.0         UG    100    0        0 ens33
172.26.37.0     0.0.0.0         255.255.255.0   U     100    0        0 ens33
172.26.38.0     172.26.37.253   255.255.255.0   UG    100    0        0 ens33

相关文章

网友评论

    本文标题:20220726-Alma Linux8添加静态路由

    本文链接:https://www.haomeiwen.com/subject/nxdoirtx.html