我有一个主 BSD 路由器 (A) 通过第二个 Linux 路由器 (B) 路由一些子网,一切正常。但是当我尝试从第二个路由器访问这些子网时,它不起作用。听起来返回数据包被丢弃或未正确路由?
我假设它看起来像:来自 B 的请求(A 是默认网关)-> A 决定通过 B 路由-> ...在那里挣扎...
以防万一:A 上的子网列表是动态的,因此我无法保留它的副本来覆盖 B 上的路由。
A(OPNsense)
ifconfig
:
ix0: flags=8863<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=4803828<VLAN_MTU,JUMBO_MTU,WOL_UCAST,WOL_MCAST,WOL_MAGIC,NOMAP>
ether xx:xx:xx:xx:xx:xx
media: Ethernet autoselect (10Gbase-Twinax <full-duplex,rxpause,txpause>)
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
igb0: flags=8863<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
description: WAN (wan)
options=4802028<VLAN_MTU,JUMBO_MTU,WOL_MAGIC,NOMAP>
ether xx:xx:xx:xx:xx:xx
inet xx.xx.100.162 netmask 0xfffffe00 broadcast xx.xx.101.255
inet6 xxxx::xxxx:xxxx:xxxx:xxxx%igb0 prefixlen 64 scopeid 0x2
groups: IG_WAN
media: Ethernet autoselect (1000baseT <full-duplex>)
status: active
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
igb1: flags=8863<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
description: WAN2 (opt7)
options=4802028<VLAN_MTU,JUMBO_MTU,WOL_MAGIC,NOMAP>
ether xx:xx:xx:xx:xx:xx
groups: IG_WAN
media: Ethernet autoselect
status: no carrier
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
enc0: flags=0<> metric 0 mtu 1536
groups: enc
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5
inet 127.0.0.1 netmask 0xff000000
groups: lo
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
...
ix0_vlan4: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
description: SERVICE (opt4)
options=4000000<NOMAP>
ether xx:xx:xx:xx:xx:xx
inet 192.168.4.1 netmask 0xffffff00 broadcast 192.168.4.255
groups: vlan IG_BROADCAST IG_SRV_ACCESS IG_WAN_ACCESS
vlan: 4 vlanproto: 802.1q vlanpcp: 0 parent interface: ix0
media: Ethernet autoselect (10Gbase-Twinax <full-duplex,rxpause,txpause>)
status: active
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
netstat -rn
(xx.xx - WAN 地址):
Routing tables
Internet:
Destination Gateway Flags Netif Expire
default xx.xx.100.1 UGS igb0
8.8.4.4 192.168.4.58 UGHS ix0_vlan
xx.xx.1.2 xx.xx.100.1 UGHS igb0
xx.xx.1.4 xx.xx.100.1 UGHS igb0
xx.xx.100.0/23 link#2 U igb0
xx.xx.100.162 link#2 UHS lo0
127.0.0.1 link#5 UH lo0
127.0.1.1 link#14 UH lo1
...
192.168.4.0/24 link#11 U ix0_vlan
192.168.4.1 link#11 UHS lo0
B(Debian)
ip a
:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
altname enp0s18
inet 192.168.4.58/24 metric 1024 brd 192.168.4.255 scope global dynamic ens18
valid_lft 85211sec preferred_lft 85211sec
inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link
valid_lft forever preferred_lft forever
3: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 500
link/none
inet 198.18.0.1/15 brd 198.19.255.255 scope global tun0
valid_lft forever preferred_lft forever
inet6 xxxx::xxxx:xxxx:xxxx:xxxx/64 scope link stable-privacy
valid_lft forever preferred_lft forever
ip r
:
default via 192.168.4.1 dev ens18 proto dhcp src 192.168.4.58 metric 1024
192.168.4.0/24 dev ens18 proto kernel scope link src 192.168.4.58 metric 1024
192.168.4.1 dev ens18 proto dhcp scope link src 192.168.4.58 metric 1024
198.18.0.0/15 dev tun0 proto kernel scope link src 198.18.0.1
ip r s t 1000
:
default via 198.18.0.1 dev tun0 proto static
198.18.0.0/15 dev tun0 proto static scope link
ip ru
:
0: from all lookup local
32765: from all iif ens18 lookup 1000 proto static
32766: from all lookup main
32767: from all lookup default
tun0
正在通过创建github.com/xjasonyu/tun2socks:
ip tuntap add mode tun dev tun0
ip addr add 198.18.0.1/15 dev tun0
ip link set dev tun0 up
tun2socks -loglevel info -device tun0 -proxy socks5://127.0.0.1:1080
笔记
- 当尝试从 B 访问
8.8.4.4
(例如,当它通过 A 在 A 上路由时192.168.4.1
)时,从系统日志中发现以下内容:IPv4: martian source 8.8.4.4 from 192.168.4.58, on dev ens18
- 按照@AB的建议尝试过
ip rule add iif lo lookup 1000 suppress_prefixlength 0
,但没有成功。