当前位置:网站首页>多网络设备存在时,如何配置其上网优先级?
多网络设备存在时,如何配置其上网优先级?
2022-06-27 08:20:00 【武汉万象奥科】
常见的上网外设有有线以太网、WIFI、4G/5G等接口,一块硬件主板经常会搭载多种网络访问硬件资源。如何配置不同网络外设的使用优先级呢?本文将为您介绍Linux系统下的常用配置方法。
测试环境:HDG2L-IOT评估套件,搭载双千兆网、4G CAT1模组;运行Ubuntu系统,内核版本5.10 。具体操作步骤见下文。
图1 HDG2L-IOT套件
1、获取IP地址
网络设备获取IP地址。固定IP模式下略过此步骤,自动IP模式下执行以下操作。
- 将以太网,wifi连接上网络
- 使用udhcpc -i eth0 -q命令,让以太自动寻找IP
- 进入到/home/wifi目录,执行wifi.sh,让wifi接入路由器;一路千兆网口与路由器保持正常连接。
2、查看路由信息表
使用route命令查看路由信息,可以看到以太网eth0和wifi网络wlan0的路由信息都自动生成了,而且存在两个默认网关。如果访问外网,系统会根据路由缓存信息和速度最优的原则,通过速度更快的网关进行访问。
图2 路由表
3、修改网关优先级
Linux系统支持对默认网关的优先级进行设置,这时需要用到mteric这个参数。当系统中有多个默认网关时,数据包会通过metric更低的接口传输,通常情况下,默认的metric都为0,所以优先级是相同的。
配置网关优先级即配置网络设备的metric值,下面我们就为eth0和wlan0分别设置优先级。
- 首先将metric值为0的默认网关删除:
- 然后重新设置默认网关和metric:
- 最后使用route命令查看网关,可以看到wifi的wlan0和以太eth0的metric 的值分别为10和20,配置优先级成功。
图3 优先级配置
4、验证优先级
验证优先级的方法有很多,此处提供一个较为简单易用的方法。
使用ping 114.114.114.114 -I wlan0和ping 114.114.114.114 -I eth0命令可以分别获取wlan0、eth0的网络延时,使用ping 114.114.114.114 可以获取当前默认上网设备的网络延时,两者的值进行对比可验证配置结论。
注意:此方法有局限性,wlan0、eth0的网络延时接近时不可使用此方法。
边栏推荐
- (note) Anaconda navigator flashback solution
- Filter filter
- L'introduction en bourse de Wild Wind Pharmaceutical a pris fin: Yu pinzeng, qui avait l'intention de lever 540 millions de RMB, a effectué un investissement P2P.
- 分析日志.log
- sql注入之order by注入
- [12. maximum continuous non repeating subsequence]
- Analysis log log
- 【11. 二维差分】
- 【原创】TypeScript字符串utf-8编码解码
- Linux下Redis的安装
猜你喜欢
Redis的持久化机制
Ue5 magic power - POI solution
野風藥業IPO被終止:曾擬募資5.4億 實控人俞蘠曾進行P2P投資
准备好迁移上云了?请收下这份迁移步骤清单
JVM常见的垃圾收集器
Win10 how to manage startup items?
lvgl 说明3关于lvgl guider的使用
VIM from dislike to dependence (20) -- global command
[batch dos-cmd command - summary and summary] - environment variables, path variables, search file location related instructions - set, path, where, what if there are spaces in the path parameters of
Redis主从复制以及哨兵模式
随机推荐
并发编程JUC的AQS底层源码
【c ++ primer 笔记】第4章 表达式
JS EventListener
Futures reverse Documentary - training for traders
Win10 how to manage startup items?
Read datasets iteratively with xgboost
分析日志.log
lvgl 说明3关于lvgl guider的使用
vim 从嫌弃到依赖(20)——global 命令
Game asset reuse: a new way to find required game assets faster
[batch dos-cmd command - summary and summary] - how to distinguish the internal command and external command of CMD, and the difference between CMD command and run (win+r) command,
参考 | 升级 Win11 移动热点开不了或者开了连不上
MySQL environment variable configuration tutorial
win命令行中导入、导出数据库相关表
Binary tree structure and heap structure foundation
若xn>0,且x(n+1)/xn>1-1/n(n=1,2,...),证明级数∑xn发散
vim 从嫌弃到依赖(19)——替换
【批处理DOS-CMD命令-汇总和小结】-输出/显示命令——echo
Redis的事务
Closure problem