route 路由使用记录

一、路由的基本介绍

路由是计算机网络中的一个重要概念,它用于确定数据包从源地址到目的地址的路径。在网络中,路由器是负责转发数据包的设备。
下面是关于路由的基本知识和使用方法的介绍:
路由表:路由器通过路由表来确定数据包的下一跳。路由表中包含了目的网络的IP地址和对应的下一跳地址。当路由器接收到一个数据包时,它会查找路由表,找到与目的地址匹配的条目,并将数据包发送到相应的下一跳地址。
静态路由:静态路由是手动配置的路由,管理员需要手动添加路由表的条目。静态路由的优点是简单、可靠,适用于小型网络或者需要固定路由的场景。但是,静态路由不适用于大型网络或者网络拓扑经常变化的情况。
动态路由:动态路由是通过动态路由协议学习到的路由。动态路由协议有自己的路由算法,能够自动适应网络拓扑的变化。常见的动态路由协议有OSPF、IS-IS、BGP等。动态路由的优点是能够自动适应网络变化,减少管理员的配置工作量。但是,动态路由也需要一定的计算和通信开销。
路由选择:当到达同一目的地的多条路由具有相同的路由优先级时,路由开销最小的将成为当前的最优路由。路由开销可以根据不同的路由协议和网络条件进行计算,常见的开销指标包括带宽、延迟、可靠性等。
路由器配置:配置路由器的路由表可以使用命令行界面(CLI)或者图形用户界面(GUI)。管理员可以手动添加静态路由,也可以配置动态路由协议来学习路由。

二、路由指令-手动配置

1. 路由帮助

route --help

在这里插入图片描述
在这里插入图片描述

2. 路由查找

route -n

在这里插入图片描述

Destination     Gateway         Genmask         Flags 	Metric 		Ref   	 Use		 Iface
目标            下一跳/网关        子网掩码          标志  	跃点   		引用  	使用 	接口
OUTPUTThe output of the kernel routing table is organized in the following columnsDestinationThe destination network or destination host.GatewayThe gateway address or '*' if none set.GenmaskThe netmask for the destination net; '255.255.255.255' for a host destination and '0.0.0.0' for the default route.Flags  Possible flags includeU (route is up)H (target is a host)G (use gateway)R (reinstate route for dynamic routing)D (dynamically installed by daemon or redirect)M (modified from routing daemon or redirect)A (installed by addrconf)C (cache entry)!  (reject route)Metric The 'distance' to the target (usually counted in hops).Ref    Number of references to this route. (Not used in the Linux kernel.)Use    Count of lookups for the route.  Depending on the use of -F and -C this will be either route cache misses (-F) or hits (-C).Iface  Interface to which packets for this route will be sent.MSS    Default maximum segment size for TCP connections over this route.Window Default window size for TCP connections over this route.irtt   Initial RTT (Round Trip Time). The kernel uses this to guess about the best TCP protocol parameters without waiting on (possibly slow) answers.HH (cached only)The number of ARP entries and cached routes that refer to the hardware header cache for the cached route. This will be -1 if a  hardware  address  isnot needed for the interface of the cached route (e.g. lo).Arp (cached only)Whether or not the hardware address for the cached route is up to date.

3. 路由添加

route add
示例
route add -net 192.168.2.15 netmask 255.255.255.255 metric 1024 gw 192.168.2.1 dev eth1

4. 路由删除

route del
或
route delete示例
route del -net 192.168.2.15 netmask 255.255.255.255 metric 1024 gw 192.168.2.1 dev eth1

4. 其它

-net 就是说你这条路由目标是一个网络地址,或者说是一个网段;
-host 说你这个路由目标是一个主机地址,是一个到主机的路由;
官方参数有介绍

三、官方参数介绍

OPTIONS-A familyuse the specified address family (eg `inet'). Use route --help for a full list. You can use -6 as an alias for --inet6 and -4 as an alias for -A inet-F     operate on the kernel's FIB (Forwarding Information Base) routing table.  This is the default.-C     operate on the kernel's routing cache.-v     select verbose operation.-n     show  numerical  addresses  instead  of  trying to determine symbolic host names. This is useful if you are trying to determine why the route to yournameserver has vanished.-e     use netstat(8)-format for displaying the routing table.  -ee will generate a very long line with all parameters from the routing table.del    delete a route.add    add a new route.target the destination network or host. You can provide an addresses or symbolic network or host name. Optionally you can use /prefixlen notation instead ofusing the netmask option.-net   the target is a network.-host  the target is a host.netmask NMwhen adding a network route, the netmask to be used.gw GW  route packets via a gateway.NOTE:  The  specified  gateway  must  be reachable first. This usually means that you have to set up a static route to the gateway beforehand. If youspecify the address of one of your local interfaces, it will be used to decide about the interface to which the packets should be routed to. This  isa BSDism compatibility hack.metric Mset  the metric field in the routing table (used by routing daemons) to M. If this option is not specified the metric for inet6 (IPv6) address familydefaults to '1', for inet (IPv4) it defaults to '0'. You should always specify an explicit metric value to not rely on those  defaults  -  they  alsodiffer from iproute2.mss M  sets MTU (Maximum Transmission Unit) of the route to M bytes.  Note that the current implementation of the route command does not allow the option toset the Maximum Segment Size (MSS).window Wset the TCP window size for connections over this route to W bytes. This is typically only used on AX.25 networks and with drivers unable  to  handleback to back frames.irtt I set  the  initial  round  trip time (irtt) for TCP connections over this route to I milliseconds (1-12000). This is typically only used on AX.25 net‐works. If omitted the RFC 1122 default of 300ms is used.reject install a blocking route, which will force a route lookup to fail.  This is for example used to mask out networks before  using  the  default  route.This is NOT for firewalling.mod, dyn, reinstateinstall a dynamic or modified route. These flags are for diagnostic purposes, and are generally only set by routing daemons.dev If force  the route to be associated with the specified device, as the kernel will otherwise try to determine the device on its own (by checking alreadyexisting routes and device specifications, and where the route is added to). In most normal networks you won't need this.If dev If is the last option on the command line, the word dev may be omitted, as it's the default. Otherwise the order of the route modifiers  (met‐ric netmask gw dev) doesn't matter.

四、官方示例

EXAMPLESroute add -net 127.0.0.0 netmask 255.0.0.0 metric 1024 dev loadds  the  normal  loopback  entry, using netmask 255.0.0.0 and associated with the "lo" device (assuming this device was previously set up correctlywith ifconfig(8)).route add -net 192.56.76.0 netmask 255.255.255.0 metric 1024 dev eth0adds a route to the local network 192.56.76.x via "eth0".  The word "dev" can be omitted here.route del defaultdeletes the current default route, which is labeled "default" or 0.0.0.0 in the destination field of the current routing table.route del -net 192.56.76.0 netmask 255.255.255.0deletes the route. Since the Linux routing kernel uses classless addressing, you pretty much always have to specify the netmask that is  same  as  asseen in 'route -n' listing.route add default gw mangoadds  a  default  route (which will be used if no other route matches).  All packets using this route will be gatewayed through the address of a nodenamed "mango". The device which will actually be used for that route depends on how we can reach "mango" - "mango"  must  be  on  directly  reachableroute.route add mango sl0Adds the route to the host named "mango" via the SLIP interface (assuming that "mango" is the SLIP host).route add -net 192.57.66.0 netmask 255.255.255.0 gw mangoThis command adds the net "192.57.66.x" to be gatewayed through the former route to the SLIP interface.route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0This  is an obscure one documented so people know how to do it. This sets all of the class D (multicast) IP routes to go via "eth0". This is the cor‐rect normal configuration line with a multicasting kernel.route add -net 10.0.0.0 netmask 255.0.0.0 metric 1024 rejectThis installs a rejecting route for the private network "10.x.x.x."route -6 add 2001:0002::/48 metric 1 dev eth0This adds a IPv6 route with the specified metric to be directly reachable via eth0.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/288662.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux ARM64 处理器内存屏障

一、内存类型: ARMv8架构将系统中所有的内存,按照它们的特性,划分成两种,即普通内存和设备内存。并且它们是互斥的,也就是说系统中的某段内存要么是普通内存,要么是设备内存,不能都是。 1&…

乐理基础-情绪与速度、具体的速度、BPM

首先音乐中的一拍并不是一个具体的时间(详情看这两个 认识音符、什么是一拍),一拍并不是1图6:秒、2秒、3秒这样一个具体的时间,只能说在同样一份乐谱和同样一个速度下,全音符、二分音符、四分音符等等会依次…

b站高可用架构 笔记

b站高可用架构 关键点:主机房,多活和多活机房 参考文章:bilibili技术总监毛剑:B站高可用架构实践 1. 前端和数据中心负载均衡 前端负载均衡(动态CDN):最近节点、带宽策略、可用服务容量 数据中心负载均衡:均衡流量、识别异常节…

jvm相关命令操作

查看jvm使用情况 jmap -heap PID 查看线程使用情况 jstack pid 查看当前线程数 jstack 21294 |grep -E (#[0-9]) -o -c 查看系统线程数 top -H top -Hp pid #查看具体的进程中的线程信息 使用 jps 命令查看配置了JVM的服务 查看某个进程JVM的GC使用情况 jstat -gc 进程…

独立搭建UI自动化测试框架分享

今天给大家分享一个seleniumtestngmavenant的UI自动化,可以用于功能测试,也可按复杂的业务流程编写测试用例,今天此篇文章不过多讲解如何实现CI/CD,只讲解自己能独立搭建UI框架,如果有其他好的框架也可以联系我&#x…

【Kafka每日一问】kafka中partition 的多个节点是分布在不同的broker上面吗

kafka中partition 的多个节点是分布在不同的broker上面吗 是的,Kafka中的partition(分区)会被复制到不同的broker上。每个partition都可以配置多个副本(replica),这些副本都保存着相同的消息。当一个producer往这个partition写入消息时,消息…

测试自动化平台 | 测试开发工程师的进阶之路

一、测试工程师的现状 很多测试小伙伴在工作中有时会比较迷茫,不知该怎样突破瓶颈,更好的发展。 那么测试人员究竟该如何打破瓶颈继续向上提升呢?如果你苦于不知所措,又满怀斗志向上的话,不妨一起聊聊。测试职业发展…

D : B DS二叉排序树_树中第k小的元素

Description 给定一个二叉排序树和一个整数k,要求输出树中第k个最小元素(k从1开始计数)。 Input 第一行输入t,表示有t个测试样例。 第二行起,首先输入n,接着输入n个整数表示一个二叉排序树,接着输入k。 以此类推共…

爱芯派pro通过无线网卡rtl8188eu连接热点

爱芯派pro通过无线网卡rtl8188eu连接热点 爱芯派pro目前的底板的pcie的复位有问题,所以pcie接口无法挂载上去,所以自己购买的rtl8822网卡也用不了,然后想起来自己还有正点原子的rtl8188eu网卡,但是没有和工作人员进行摸索后才知道…

0x26 广搜变形

0x26 广搜变形 1.双端队列BFS 在最基本的广度优先搜索中,每次沿着分支的扩展都记为“一步”,我们通过逐层搜索,解决了求从起始状态到每个状态的最少步数的问题。这其实等价于在一张边权均为1的图上执行广度优先遍历,求出每个点相…

idea 如何使用 JaCoCo 跑覆盖率

背景介绍 什么代码覆盖? 代码覆盖(Code coverage)是软件测试中的一种度量,描述程序中源代码被测试的比例和程度,所得比例称为代码覆盖率。简单来理解,就是单元测试中代码执行量与代码总量之间的比率。 Java常用的单元测试覆盖率…

为什么要用云渲染?3d Max云渲染怎么使用?

云计算技术的兴起让渲染任务的执行更加灵活和高效。借助于云计算服务,影视和动画制作公司能够将大型和资源密集型的渲染任务外包至远程服务器。这些任务在云渲染服务器上按块处理,而更小规模的渲染作业则可在本地工作站上完成。这种作业分配方法大幅优化…