Linux系统添加永久静态路由的方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Linux系统添加永久静态路由的方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2968字,纯文字阅读大概需要5分钟。
内容图文
一、使用route命令添加
使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:
A、添加到主机的路由
# route add –host 192.168.1.10 dev eth0 # route add –host 192.168.1.10 gw 192.168.1.1 # route add -host 192.168.1.3 gw 172.16.0.1 dev eth0 # 其中dev eth0可以省略
B、添加到网络的路由
# route add –net 192.168.1.0/24 gw 192.168.1.1 # route add –net 192.168.1.0/24 dev eth1 # route del -net 192.168.32.7/32 gw 172.18.0.200 # 删除路由
C、添加默认路由
# route add default gw 192.168.1.1
D、删除路由
# route del –host 192.168.1.10 dev eth0 # route del default gw 192.168.1.1 # route del -net 192.168.32.7/32 gw 172.18.0.200 # 删除路由
E、查看添加的所有路由信息
[root@centos-7 network-scripts]# route -n # 第一种查看路由表方法 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.7.2 0.0.0.0 UG 0 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 10.0.0.1 192.168.7.2 255.255.255.255 UGH 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 192.168.7.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 [root@centos-7 network-scripts]# ip route # 第二种查看路由表方法 default via 192.168.7.2 dev eth0 10.0.0.0/24 dev eth0 scope link 10.0.0.1 via 192.168.7.2 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 192.168.7.0/24 dev eth0 proto kernel scope link src 192.168.7.100
二、使用ip route 添加路由
A、添加路由
# ip route add 2.2.2.0/24 via 1.1.1.1 # 前面是路由,后面是网关地址 # ip a a 1.1.1.1/24 dev eth1 # 添加一个IP地址 # ip route add 192.168.0.0/24 via 172.16.0.1 # 添加路由
B、查看路由信息
[root@centos-7 network-scripts]# ip route # 此方法查看到的路由信息方便存在配置文件中,或者用命令也可以直接复制粘贴,方便你我他。 default via 192.168.7.2 dev eth0 10.0.0.0/24 dev eth0 scope link 10.0.0.1 via 192.168.7.2 dev eth0 169.254.0.0/16 dev eth0 scope link metric 1002 192.168.7.0/24 dev eth0 proto kernel scope link src 192.168.7.100
三、将路由永久写到配置文件中,重启网卡永久生效
A、在/etc/sysconfig/network-scripts目录下创建一个route-ethx的网卡名称,添加以下对应要添加的内容即可
[root@centos-7 network-scripts]# cat route-eth0 10.0.0.1 via 192.168.7.2 10.0.0.0/24 dev eth0
B、查看此时配置的路由信息
[root@centos-7 network-scripts]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.7.2 0.0.0.0 UG 0 0 0 eth0 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 10.0.0.1 192.168.7.2 255.255.255.255 UGH 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 192.168.7.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
多个路由器之间的互通,详见此链接:https://www.cnblogs.com/struggle-1216/p/12730939.html
内容总结
以上是互联网集市为您收集整理的Linux系统添加永久静态路由的方法全部内容,希望文章能够帮你解决Linux系统添加永久静态路由的方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。