沙大斌AlmaLinux

20220726-Alma Linux8添加静态路由

2022-07-26  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读