0
点赞
收藏
分享

微信扫一扫

Centos Linux 添加静态路由

李雨喵 2024-09-27 阅读 27
Linux运维

使用ip命令添加

添加网段

[root@sre01 ~]# ip route add 12.12.12.0/24 via 192.168.236.2
[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
11.11.11.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
12.12.12.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

添加主机

[root@sre01 ~]# ip route add 14.14.14.14/32 via 192.168.236.2
[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
11.11.11.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
12.12.12.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
13.13.13.13     192.168.236.2   255.255.255.255 UGH   0      0        0 ens33
14.14.14.14     192.168.236.2   255.255.255.255 UGH   0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
[root@sre01 ~]#

使用route命令添加

添加网段路由

[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

[root@sre01 ~]# route add -net 11.11.11.0/24 gw 192.168.236.2 

[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
11.11.11.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

添加主机路由

[root@sre01 ~]# route add -host 13.13.13.13 gw 192.168.236.2 

[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
11.11.11.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
13.13.13.13     192.168.236.2   255.255.255.255 UGH   0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

删除静态路由

[root@sre01 ~]# ip route del 11.11.11.0/24
[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
12.12.12.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
13.13.13.13     192.168.236.2   255.255.255.255 UGH   0      0        0 ens33
14.14.14.14     192.168.236.2   255.255.255.255 UGH   0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33


[root@sre01 ~]# ip route del 13.13.13.13/32
[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
12.12.12.0      192.168.236.2   255.255.255.0   UG    0      0        0 ens33
14.14.14.14     192.168.236.2   255.255.255.255 UGH   0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

[root@sre01 ~]# route delete -net 12.12.12.0/24
[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
14.14.14.14     192.168.236.2   255.255.255.255 UGH   0      0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

[root@sre01 ~]# route del -host 14.14.14.14
[root@sre01 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.236.2   0.0.0.0         UG    0      0        0 ens33
0.0.0.0         192.168.236.2   0.0.0.0         UG    100    0        0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 ens33
172.16.156.0    0.0.0.0         255.255.255.0   U     101    0        0 ens36
192.168.236.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
[root@sre01 ~]#

举报

相关推荐

0 条评论