Linux系统中网线与USB网络共享冲突

博客地址:https://www.cnblogs.com/zylyehuo/

问题描述

网络管理器配置了"互斥连接"
有些配置会写成: 插入 USB 网络后,关闭 eth0
有线和usb共享网路,使用同一个网络协议,修改一个的时候会同时把另一个改了
系统把它们当成了同一个网络配置文件在管理。

给两张网卡创建两个独立配置

bash 复制代码
nmcli device status
nmcli connection show

看到类似:

bash 复制代码
DEVICE    TYPE      STATE        CONNECTION
eth0      ethernet  connected    Wired connection 1
usb0      ethernet  connected    Wired connection 1

绑定到具体网卡名
假设

bash 复制代码
有线网卡:eth0
USB共享:usb0

给有线网口创建固定 IP 配置

bash 复制代码
sudo nmcli connection modify eth0-static \
  ipv4.method manual \
  ipv4.addresses 172.16.2.80/24 \
  ipv4.gateway 172.16.2.1 \
  ipv4.never-default no \
  ipv4.ignore-auto-routes no \
  ipv4.route-metric 500 \
  connection.autoconnect yes

eth0 只负责 172.16.2.x 局域网,不抢默认网关,不负责上网

给 USB 共享网络创建单独配置

bash 复制代码
sudo nmcli connection add type ethernet ifname usb0 con-name usb-tether
bash 复制代码
sudo nmcli connection modify usb-tether \
  ipv4.method auto \
  ipv4.never-default no \
  ipv4.ignore-auto-routes no \
  ipv4.route-metric 50 \
  connection.autoconnect yes

重启两个连接

bash 复制代码
sudo nmcli connection down eth0-static
sudo nmcli connection down usb-tether
bash 复制代码
sudo nmcli connection up eth0-static
sudo nmcli connection up usb-tether

调整路由优先级 metric

希望 USB 共享网络负责上网

bash 复制代码
sudo nmcli connection modify usb-tether ipv4.route-metric 100
sudo nmcli connection modify ST1030 ipv4.route-metric 500

看系统准备从哪张网卡访问 8.8.8.8

bash 复制代码
ip route get 8.8.8.8
bash 复制代码
nvidia@EAORA04:~$ ip route get 8.8.8.8
8.8.8.8 via 10.163.44.252 dev usb0 src 10.163.44.216 uid 1000 
    cache 
相关推荐
未济2 天前
linux 配置环境变量
linux
傲世仙尊2 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
_艾伦 耶格尔.2 天前
进程间通信
linux
Liuqy-052 天前
Linux IO编程——静态库、动态库
linux
彧azz2 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅2 天前
linux(8) 软硬链接
linux·运维·服务器
AIgorithmGEEK2 天前
[Linux]线程三部曲(上):一个执行流的诞生——从操作系统一路拆到 pthread_create
linux·线程·pid
琥珀色糖2 天前
SimlpeHttp
linux·服务器
qeen872 天前
【Linux】操作系统之进程介绍(二)
linux·笔记·学习·进程
Zenova EdgeOS2 天前
Linux ss 工业边缘网络分析实战
linux·python·边缘计算·工业网关