Linux添加永久静态路由信息
发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,因为linux服务器有多网卡,需要有些网卡走指定的路由,就需要单独设置静态路由。通过route add添加的静态路由,如果服务器重启或者是网卡重启,这个静态路由就会丢失。[root@test ~]#
千家信息网最后更新 2025年02月04日Linux添加永久静态路由信息因为linux服务器有多网卡,需要有些网卡走指定的路由,就需要单独设置静态路由。
通过route add添加的静态路由,如果服务器重启或者是网卡重启,这个静态路由就会丢失。
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
用route add添加静态路由。
[root@test ~]# route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth0
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
添加成功,但是重启网络服务后路由丢失,证明这个路由是动态参数。
[root@test ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth2: [ OK ]
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
需要永久添加静态路由:
到/etc/sysconfig/network-scripts/下面
[root@test ~]# cd /etc/sysconfig/network-scripts/
加入一条静态路由到route-eth0,让网络服务每次重启都会自动加载这些信息。保证路由不丢失。
[root@shwmsdb1 network-scripts]# cat route-eth0
10.0.0.0/8 via 10.0.0.254
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
10.0.0.0 10.0.0.254 255.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
这样无论是重启主机还是重启网络服务路由信息都不会丢了。
通过route add添加的静态路由,如果服务器重启或者是网卡重启,这个静态路由就会丢失。
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
用route add添加静态路由。
[root@test ~]# route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth0
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
添加成功,但是重启网络服务后路由丢失,证明这个路由是动态参数。
[root@test ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth2: [ OK ]
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
需要永久添加静态路由:
到/etc/sysconfig/network-scripts/下面
[root@test ~]# cd /etc/sysconfig/network-scripts/
加入一条静态路由到route-eth0,让网络服务每次重启都会自动加载这些信息。保证路由不丢失。
[root@shwmsdb1 network-scripts]# cat route-eth0
10.0.0.0/8 via 10.0.0.254
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
10.0.0.0 10.0.0.254 255.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
这样无论是重启主机还是重启网络服务路由信息都不会丢了。
路由
静态
服务
网卡
网络
网络服务
信息
服务器
永久
成功
主机
动态
参数
还是
保证
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库管理员工作流程
高科技网络安全作用
数据库网页上传大小限制
宝安网络安全存储服务器机箱
p7数据库设计
网络安全电厂只监测插拔网口
美国云计算服务器
软件开发 生产者
阿里轻量应用服务器管理
植物数据库垂直拆分
网贷数据库怎么查询安全么
上海数据库技术及应用的试题
服务器为什么不能用公网ip
服务器onload功能
和龙软件开发哪家强
居家办公 软件开发
网络安全审查报表
激战2服务器老闪退
监控服务器显示资源不足
戴尔服务器管理员默认密码
access数据库是
网络安全监督管理员
c语言软件开发课程
科技互联网时代的社会趋势
2b2t服务器ip是什么
免费代理服务器 在线
网络技术管理好不好
软件开发税务国标行业代码
区块链网络安全防护
给数据库添加内容