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 
相关推荐
Sokach10151 天前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
AlfredZhao2 天前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3103 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode3 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
A小辣椒5 天前
TShark:Wireshark CLI 功能
linux
A小辣椒5 天前
TShark:基础知识
linux
AlfredZhao5 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao6 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334666 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux