centos静态路由添加

一、添加临时路由(重启后路由失效)

[root@local~]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.85.2    0.0.0.0         UG    100    0        0 eth0
10.28.0.0       192.168.85.2    255.255.0.0     UG    100    0        0 eth0
192.168.85.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
[root@local~]#route add -net 172.168.0.0 netmask 255.255.0.0 gateway 192.168.85.2 #添加172.168.0.0段路由

使用route -n查看当前系统路由
[root@local ~]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.85.2    0.0.0.0         UG    100    0        0 eth0
10.28.0.0       192.168.85.2    255.255.0.0     UG    100    0        0 eth0
172.168.0.0     192.168.85.2    255.255.0.0     UG    0      0        0 eth0 #路由生效
192.168.85.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
主机路由同上方法

二、静态路由配置(重启后依然生效)

1、进入到网络配置文件目录

cd /etc/sysconfig/network-scripts/

2、创建route-interface文件 #interface名需要与网卡名称对应(以网卡名为eth0网卡举例)

3、编辑vim route-eth0文件

wq保存退出

4、使用service network restart重启网络服务使网络服务生效

出现ok字样表示重启网络服务成功

查看当前路由

猜你喜欢

转载自blog.csdn.net/weixin_42211117/article/details/107619352