You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux系统双网卡(PPP+以太网)流量路由配置问题求助

Linux双网卡路由配置修复方案

系统环境

root@fl-imx6ull:~# uname -a
Linux fl-imx6ull 4.1.15 #1 SMP PREEMPT Tue Apr 8 08:26:30 MSK 2025 armv7l armv7l armv7l GNU/Linux

网络环境与需求

  • 双网卡:SIMCOM A7682E调制解调器(PPP连接,设备名ppp0)、以太网(设备名eth0)
  • 核心需求:
    • eth0仅用于访问192.168.3.0/24本地子网
    • ppp0作为默认路由,承载所有外网流量

当前问题现象

PPP单独连接时可正常访问外网;连接eth0后,路由表出现default dev eth0 scope link条目,导致外网流量被强制走eth0,最终访问失败:

root@fl-imx6ull:~# ping google.com
PING google.com (173.194.221.100) 56(84) bytes of data.
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=1 ttl=104 time=94.4 ms
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=2 ttl=104 time=86.5 ms
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=3 ttl=104 time=84.8 ms
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=4 ttl=104 time=83.7 ms
fec 2188000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=21 ttl=104 time=78.6 ms
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=22 ttl=104 time=84.8 ms
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=23 ttl=104 time=75.7 ms
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=24 ttl=104 time=83.6 ms
64 bytes from lm-in-f100.1e100.net (173.194.221.100): icmp_seq=25 ttl=104 time=73.4 ms
From fl-imx6ull.local (192.168.3.200) icmp_seq=61 Destination Host Unreachable
From fl-imx6ull.local (192.168.3.200) icmp_seq=62 Destination Host Unreachable

当前路由表状态:

root@fl-imx6ull:~# ip route
default dev eth0  scope link
default via 192.168.3.1 dev eth0
default dev ppp0  scope link
10.64.64.64 dev ppp0  proto kernel  scope link  src 10.184.51.81
169.254.0.0/16 dev eth0  proto kernel  scope link  src 169.254.220.182
192.168.3.0/24 dev eth0  proto kernel  scope link  src 192.168.3.200

现有配置

PPP配置文件(/etc/ppp/peers/simcom-pppd)

# named simcom-pppd and place in /etc/ppp/peers
/dev/ttymxc2 115200
#Insert the username and password for authentication, default user and password are test
user "megafon" password "megafon"
# The chat script, customize your APN in this file
connect 'chat -s -v -f /etc/ppp/peers/simcom-connect-chat'
# The close script
disconnect 'chat -s -v -f /etc/ppp/peers/simcom-disconnect-chat'
# Hide password in debug messages
hide-password
# The phone is not required to authenticate
noauth
# Debug info from pppd
#debug
# If you want to use the HSDPA link as your gateway
defaultroute
# pppd must not propose any IP address to the peer
noipdefault
# No ppp compression
novj
novjccomp
noccp
ipcp-accept-local
ipcp-accept-remote
local
# For sanity, keep a lock on the serial line
lock
modem
dump
nodetach
# Hardware flow control
nocrtscts
remotename 3gppp
ipparam 3gppp
ipcp-max-failure 30
# Ask the peer for up to 2 DNS server addresses
usepeerdns

启动命令:pppd call simcom-pppd &

以太网配置文件(/etc/network/interfaces)

# Wired or wireless interfaces
allow-hotplug eth0
auto eth0
iface eth0 inet static
    address 192.168.3.200
        netmask 255.255.255.0
    up route add default gw 192.168.3.1 ppp0
    down route del default gw 192.168.3.1 ppp0
        gateway 192.168.3.1

启动命令:ifup eth0

修复步骤

1. 修正以太网配置

编辑/etc/network/interfaces,删除多余的gateway配置和错误的up/down路由命令,仅保留静态地址与子网配置:

# Wired or wireless interfaces
allow-hotplug eth0
auto eth0
iface eth0 inet static
    address 192.168.3.200
    netmask 255.255.255.0

说明:去掉gateway后,eth0只会生成192.168.3.0/24的子网路由,不会添加默认路由,避免抢占ppp0的外网流量。

2. 修正PPP配置

编辑/etc/ppp/peers/simcom-pppd,将defaultroute替换为replacedefaultroute:

# 替换前
#defaultroute
# 替换后
replacedefaultroute

说明:replacedefaultroute会让pppd在连接时替换所有现有默认路由,确保ppp0的默认路由优先级最高。

3. 清理当前错误路由

执行命令删除eth0相关的默认路由条目:

ip route del default dev eth0
ip route del default via 192.168.3.1 dev eth0

4. 重启网络服务

# 重启PPP连接
pkill pppd
pppd call simcom-pppd &

# 重启以太网
ifdown eth0 && ifup eth0

验证修复

查看路由表,确认仅保留ppp0的默认路由和eth0的子网路由:

ip route

预期输出示例:

default dev ppp0  scope link
10.64.64.64 dev ppp0  proto kernel  scope link  src 10.184.51.81
192.168.3.0/24 dev eth0  proto kernel  scope link  src 192.168.3.200

此时分别测试ping外网(如google.com)和本地子网(如192.168.3.1),确认流量走向符合需求。


内容的提问来源于stack exchange,提问作者Дмитрий Стеняев

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 07:07:03