«

RouterOS v7 WireGuard + BGP

myluzh 发布于 阅读:18 RouterOS


0x00 前言

配置wireguard接口互通的过程不再赘述,两端信息如下:

云端 (Cloud-ROS) AS号65001:
router-id:100.100.100.18
WireGuard 接口 IP: 100.100.100.18/24
内网网段: 172.18.0.0/16

家庭端 (Home2-ROS) AS号65000:
router-id:100.100.100.17
WireGuard 接口 IP: 100.100.100.17/24
内网网段: 172.17.10.0/24,172.17.20.0/24,172.17.200.0/24

0x01 配置BGP

1、宣告网段,配置bgp

# CLOUD-ROS 配置 AS号65001
/ip firewall address-list
add address=172.18.0.0/16 comment="Cloud Network" list=BGP-ADVERTISE
/routing bgp instance
add as=65001 disabled=no name=default router-id=100.100.100.18
/routing/bgp/connection
add name="to-home2" as=65001 remote.address=100.100.100.17 remote.as=65002 local.role=ebgp output.network=BGP-ADVERTISE  templates=default instance=default 

# HOME2-ROS 配置 AS号65000
/ip firewall address-list
add address=172.17.0.0/16 comment="HOME2 Network" list=BGP-ADVERTISE
/routing bgp instance
add as=65002 disabled=no name=default router-id=100.100.100.17
/routing/bgp/connection
add name="to-cloud" as=65002 remote.address=100.100.100.18 remote.as=65001 local.role=ebgp output.network=BGP-ADVERTISE  templates=default instance=default 

2、查看bgp连接

# 可以看到bgp链接已经建立established 
[admin@CloudROS] /ip/route>  /routing/bgp/session/print
Flags: E - established 
 0 E name="to-home2-1" instance=default 
     remote.address=100.100.100.17 .as=65002 .id=100.100.100.17 .capabilities=mp,rr,enhe,gr,as4 .afi=ip .messages=17 .bytes=383 .eor="" 
     local.address=100.100.100.18 .as=65001 .id=100.100.100.18 .cluster-id=100.100.100.18 .capabilities=mp,rr,enhe,gr,as4 .afi=ip .messages=17 
     .bytes=383 .eor="" 
     output.procid=20 .network=BGP-ADVERTISE 
     input.procid=20 ebgp 
     hold-time=3m keepalive-time=1m uptime=14m36s710ms last-started=2025-12-18 09:20:30 prefix-count=1 

[admin@HOME2-ROS] /ip/route>  /routing/bgp/session/print
Flags: E - established 
 0 E name="to-cloud-1" instance=default 
     remote.address=100.100.100.18 .as=65001 .id=100.100.100.18 .capabilities=mp,rr,enhe,gr,as4 .afi=ip .messages=17 .bytes=383 .eor="" 
     local.address=100.100.100.17 .as=65002 .id=100.100.100.17 .cluster-id=100.100.100.17 .capabilities=mp,rr,enhe,gr,as4 .afi=ip 
     .messages=17 .bytes=383 .eor="" 
     output.procid=20 .network=BGP-ADVERTISE 
     input.procid=20 ebgp 
     hold-time=3m keepalive-time=1m uptime=14m34s130ms last-started=2025-12-18 09:20:21 prefix-count=1 

3、配置bgp黑洞路由
知识点:RouterOS 的 BGP 宣告逻辑是:“只有当路由表中真的存在这条路由时,我才会把它宣告出去。”
配置完成后,会发现,CLOUD-ROS没有学到172.17.0.0/16的路由。因为 Home2 的 BGP 地址列表里写的是 172.17.0.0/16,但是我的内网路由表是 172.17.10.0/24 和 172.17.200.0/24 这些 /24 的细分路由,而不是汇总路由,BGP 发现路由表里没有 172.17.0.0/16,所以它决定什么都不发。有两个方案,方案1:直接在bgp宣告明确的/24路由,方案2、添加一条黑洞 (Blackhole) 路由,这不仅能让 BGP 成功宣告 172.17.0.0/16,还能防止路由环路。

# 在HOME2-ROS中添加一条黑洞路由,让 /16 出现在路由表中
/ip/route
add dst-address=172.17.0.0/16 blackhole comment="BGP-Aggregate"

原理:现在路由表里有了 172.17.0.0/16(虽然是黑洞),BGP 检查时发现“哦,路由表里有这条”,于是就会把它通过 eBGP 发给 Cloud 端。

# 再次查看CLOUD-ROS路由表 就会发现 有路由了。
[admin@CloudROS] /ip/route> /ip/route/print where bgp
Flags: D - DYNAMIC; A - ACTIVE; b - BGP
Columns: DST-ADDRESS, GATEWAY, ROUTING-TABLE, DISTANCE
    DST-ADDRESS    GATEWAY         ROUTING-TABLE  DISTANCE
DAb 172.17.0.0/16  100.100.100.17  main                 20

routeros BGP ros7 wireguard


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/ros/559.html
文章标题:《RouterOS v7 WireGuard + BGP