linux添加路由

本文深入解析了Linux环境下静态路由的配置方法,包括如何通过主机名和IP地址添加路由条目,以及路由条目的组成部分和功能解释。同时提供了Linux环境下配置静态路由的实践案例,帮助读者理解路由配置的重要性及其实用性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、添加静态路由命令

 添加一条到主机192.168.168.110的路由(通过eth0)

[root@localhost ~]# route add -host 192.168.1.110  dev eth0        
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.110   *               255.255.255.255 UH    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

添加一条到主机192.168.168.110的路由(通过ip192.168.1.143)

[root@localhost ~]# route add -host 192.168.168.110 gw 192.168.1.143    
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.110   *               255.255.255.255 UH    0      0        0 eth0
192.168.168.110 192.168.1.143   255.255.255.255 UGH   0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     1      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

添加到网络的路由(通过eth0)

[root@localhost ~]# route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.110   *               255.255.255.255 UH    0      0        0 eth0
192.168.168.110 192.168.1.143   255.255.255.255 UGH   0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

添加到网络的路由(通过ip192.168.1.1)

[root@localhost ~]# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.1.1 
[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.110   *               255.255.255.255 UH    0      0        0 eth0
192.168.168.110 192.168.1.143   255.255.255.255 UGH   0      0        0 eth0
192.168.100.0   192.168.1.1     255.255.255.0   UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
Destination表示路由的目标IP地址
Gateway表示网关使用的主机名或者是IP地址。上面输出的"*"表示没有网关
Genmask表示路由的网络掩码
Flags是表示路由的标志。可用的标志及其意义是:U表示路由在启动,H表示target是一台主机,G表示使用网关,R表示对动态路由进行复位设置;D表示动态安装路由,M表示修改路由,!表示拒绝路由。
Metric表示路由的单位开销量
Ref表示依赖本路由现状的其它路由数目
Use表示路由表条目被使用的数目
Iface表示路由所发送的包的目的网络
 
以上形式添加路由系统重启后会失效,要永久生效的话,编辑/etc/sysconfig/network-scripts/route-eth0文件。
[root@localhost ~]# vim /etc/sysconfig/network-scripts/route-eth0
192.168.1.0 via 192.168.1.143



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值