install frr on ubuntu24

概述

如果在下述安装中有报错,在 这里 或许能找到解决方法


1、BGP和OSPF的工作原理简介
🌐 BGP(Border Gateway Protocol):
属于 EGP(外部网关协议),用于不同自治系统之间;
是 路径向量协议,不是基于链路状态;
控制互联网路由(实际是整个互联网的“路线总控”);
使用 AS_PATH 属性记录一条路径经过的自治系统,防止路由环路;
对带宽/时延不敏感,但支持非常强的路由策略(如过滤、优选等);
一般通过 TCP 179端口 建立邻居关系

🌍 BGP就像跨国快递公司之间的邮件转运系统
每个快递公司(AS)告诉其他公司:“你要去某地,可以找我,我知道路线。”
每个公司只告诉别人“我能通到哪儿”,不会暴露内部结构;
每个公司选择“转发路径”根据多个标准(比如路径短、政策偏好);
如果某条路线断了,BGP 会找替代路径;
典型用于互联网的全球路由系统

BGP工作流程
1. 建立邻居关系(peer)
    → Router A 配置 B 和它是邻居,TCP 建立连接(port 179)

2. 交换路由信息
    → 发送 BGP Update 信息,包含可达的网络(prefix + AS path)

3. 路由选择
    → 每台路由器根据策略(AS路径长度、优先级)选最优路径

4. 路由传递
    → 将选中的“最佳路径”通告给其他邻居

5. 动态更新
    → 如果路径不可达,发送 Withdraw 消息撤回原来通告的路由





🔁 OSPF(Open Shortest Path First):
属于 IGP(内部网关协议),适合在一个自治系统(AS)内使用;
基于 链路状态路由协议(LSRP);
使用 Dijkstra 最短路径优先算法 构建路由表;
每个路由器通过发送 LSA(链路状态通告) 来通告自己看到的网络状态,最终形成一个完整的网络拓扑图;
快速收敛,适合大型企业网络

OSPF就像公司内部邮递系统
每个部门(路由器)把楼层图(拓扑)分享给大家,大家都知道怎么走最近的路线去送信
每个部门告诉其他部门“我这边通哪条楼道可以去哪儿”;
所有部门都会知道整栋楼的结构,并用**最短路径算法(SPF)**算出最优路线;
如果哪条楼道被封了,大家很快会更新楼层图

# OSPF工作流程
1. 建立邻居关系
    → Router A 和 B 在同一个网段发送 Hello
    → 匹配成功后变为邻居(Neighbor)

2. 交换链路状态
    → 互相发送 Link State Advertisement(LSA)

3. 构建拓扑图
    → 所有路由器构建出一样的“网络地图”(LSDB)

4. 计算最短路径
    → 每个路由器运行 Dijkstra 算法得出最短路径表(SPF)

5. 路由表更新
    → 将最短路径结果写入路由表(RIB)



前奏

ubuntu24/2U/4G/
192.168.2.114/24   桥接
10.0.0.1/24        自定义

生产级测试建议配置(大规模拓扑、MPLS流量工程)
项目	      建议配置
CPU	      4核或以上
内存	      8GB或更多
网卡	      至少3个(模拟多个物理链路)
网络	      支持GNS3/EVE-NG 或 Linux Bridge/NAT结构
功能扩展	  支持 GRE/IPIP/VXLAN 隧道模拟远程连接场景





rambo@ubuntu24-1:~$ cat /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: http://cn.archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg



# 配置IP
rambo@ubuntu24-1:~$ sudo chmod 600 /etc/netplan/01-network-manager-all.yaml
rambo@ubuntu24-1:~$ sudo vim /etc/netplan/01-network-manager-all.yaml
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    ens33: # 替换为你的网络接口名称
      dhcp4: false # 关闭 DHCP
      dhcp6: false # 关闭 DHCP
      addresses: [172.16.186.117/24]    # 静态 IP 地址和子网掩码
      routes:
        - to: default
          via: 172.16.186.2     # 网关地址
      nameservers:
        addresses: [172.16.186.2]   # DNS 服务器地址
        search: []


rambo@ubuntu24-1:~$ sudo netplan apply

前期铺垫安装

# 安装依赖
rambo@ubuntu24-1:~$ sudo apt update -y
rambo@ubuntu24-1:~$ sudo apt install -y \
git autoconf automake libtool make libreadline-dev texinfo \
pkg-config libpam0g-dev libjson-c-dev bison flex \
libc-ares-dev python3-dev python3-sphinx \
install-info build-essential libsnmp-dev perl \
libcap-dev libelf-dev libunwind-dev \
protobuf-c-compiler libprotobuf-c-dev cmake libpcre2-dev \
libcmocka-dev uncrustify doxygen valgrind graphviz python3-pytest


# 克隆libyang
FRR依赖于相对较新的libyang库来提供 YANG/NETCONF 支持,但大多数发行版尚未libyang在其存储库中提供该软件包
构建 FRR 需要libyang 2.1.128 或更新版本


rambo@ubuntu24-1:~$ git clone -b v3.4.2 https://github.com/CESNET/libyang.git
rambo@ubuntu24-1:~$ cd libyang/
rambo@ubuntu24-1:~/libyang$ git checkout v3.4.2
rambo@ubuntu24-1:~/libyang$ mkdir build; cd build
rambo@ubuntu24-1:~/libyang/build$ cmake --install-prefix /usr \
      -D CMAKE_BUILD_TYPE:String="Release" ..

rambo@ubuntu24-1:~/libyang/build$ make
rambo@ubuntu24-1:~/libyang/build$ sudo make install
rambo@ubuntu24-1:~/libyang/build$ cd


安装frr

2台ubuntu24上安装一样

rambo@ubuntu24-1:~$ sudo apt install -y libgrpc++-dev protobuf-compiler-grpc libsqlite3-dev libzmq5 libzmq3-dev

# 添加FRR用户和组
sudo groupadd -r -g 92 frr
sudo groupadd -r -g 85 frrvty
sudo adduser --system --ingroup frr --home /var/run/frr/ --gecos "FRR suite" --shell /sbin/nologin frr
sudo usermod -a -G frrvty frr

# 编译
rambo@ubuntu24-1:~/frr$ sudo mkdir /var/lib/frr /etc/frr 
rambo@ubuntu24-1:~/frr$ sudo chmod -R 0750 /var/lib/frr /etc/frr

rambo@ubuntu24-1:~$ git clone https://github.com/frrouting/frr.git  frr
rambo@ubuntu24-1:~$ cd frr
rambo@ubuntu24-1:~/frr$ ./configure \
    --prefix=/usr \
    --includedir=\${prefix}/include \
    --sbindir=\${prefix}/lib/frr \
    --libdir=\${prefix}/lib/frr \
    --libexecdir=\${prefix}/lib/frr \
    --localstatedir=/var \
    --with-moduledir=\${prefix}/lib/frr/modules \
    --enable-configfile-mask=0640 \
    --enable-logfile-mask=0640 \
    --enable-user=frr \
    --enable-group=frr \
    --enable-vty-group=frrvty \
    --with-pkg-git-version \
    --enable-mpls \
    --with-pkg-extra-version=-MyOwnFRRVersion



rambo@ubuntu24-1:~/frr$ make -j$(nproc)                # 下述的报错没影响,不用管
....
  ....
  CC       lib/tools_ssd-strlcpy.o
  CCLD     tools/ssd
  CCLD     pceplib/libsocket_comm_mock.la
  SPHINX   doc/user/_build/.doctrees/environment.pickle
/home/rambo/frr/doc/user/bgp.rst:1112: WARNING: duplicate clicmd description of bgp graceful-restart select-defer-time (0-3600), other instance in bgp
/home/rambo/frr/doc/user/bgp.rst:1116: WARNING: duplicate clicmd description of bgp graceful-restart rib-stale-time (1-3600), other instance in bgp
/home/rambo/frr/doc/user/bgp.rst:1120: WARNING: duplicate clicmd description of bgp graceful-restart restart-time (0-4095), other instance in bgp
/home/rambo/frr/doc/user/bgp.rst:1131: WARNING: duplicate clicmd description of bgp graceful-restart stalepath-time (1-4095), other instance in bgp
/home/rambo/frr/doc/user/bgp.rst:1149: WARNING: duplicate clicmd description of bgp graceful-restart, other instance in bgp
/home/rambo/frr/doc/user/bgp.rst:1154: WARNING: duplicate clicmd description of bgp graceful-restart-disable, other instance in bgp
/home/rambo/frr/doc/user/isisd.rst:42: WARNING: duplicate clicmd description of net XX.XXXX. ... .XXX.XX, other instance in fabricd
/home/rambo/frr/doc/user/isisd.rst:52: WARNING: duplicate clicmd description of domain-password [clear | md5] <password>, other instance in fabricd
/home/rambo/frr/doc/user/isisd.rst:57: WARNING: duplicate clicmd description of attached-bit [receive ignore | send], other instance in fabricd
/home/rambo/frr/doc/user/isisd.rst:66: WARNING: duplicate clicmd description of log-adjacency-changes, other instance in fabricd
/home/rambo/frr/doc/user/isisd.rst:91: WARNING: duplicate clicmd description of set-overload-bit, other instance in fabricd
/home/rambo/frr/doc/user/isisd.rst:99: WARNING: duplicate clicmd description of purge-originator, other instance in fabricd
/home/rambo/frr/doc/user/isisd.rst:609: WARNING: duplicate clicmd description of segment-routing srv6, other instance in bgp
/home/rambo/frr/doc/user/isisd.rst:613: WARNING: duplicate clicmd description of locator NAME, other instance in bgp
/home/rambo/frr/doc/user/ospfd.rst:163: WARNING: duplicate clicmd description of timers throttle spf (0-600000) (0-600000) (0-600000), other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:354: WARNING: duplicate clicmd description of maximum-paths (1-64), other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:360: WARNING: duplicate clicmd description of write-multiplier (1-100), other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:529: WARNING: duplicate clicmd description of area A.B.C.D export-list NAME, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:531: WARNING: duplicate clicmd description of area (0-4294967295) export-list NAME, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:556: WARNING: duplicate clicmd description of area A.B.C.D import-list NAME, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:558: WARNING: duplicate clicmd description of area (0-4294967295) import-list NAME, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:565: WARNING: duplicate clicmd description of area A.B.C.D filter-list prefix NAME in, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:567: WARNING: duplicate clicmd description of area A.B.C.D filter-list prefix NAME out, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:569: WARNING: duplicate clicmd description of area (0-4294967295) filter-list prefix NAME in, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:571: WARNING: duplicate clicmd description of area (0-4294967295) filter-list prefix NAME out, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:850: WARNING: duplicate clicmd description of set metric [+|-](0-4294967295), other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:922: WARNING: duplicate clicmd description of graceful-restart [grace-period (1-1800)], other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:935: WARNING: duplicate clicmd description of graceful-restart helper enable [A.B.C.D], other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:945: WARNING: duplicate clicmd description of graceful-restart helper strict-lsa-checking, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:953: WARNING: duplicate clicmd description of graceful-restart helper supported-grace-time (10-1800), other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:958: WARNING: duplicate clicmd description of graceful-restart helper planned-only, other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:1105: WARNING: duplicate clicmd description of mpls-te on, other instance in isisd
/home/rambo/frr/doc/user/ospfd.rst:1110: WARNING: duplicate clicmd description of mpls-te router-address <A.B.C.D>, other instance in isisd
/home/rambo/frr/doc/user/ospfd.rst:1123: WARNING: duplicate clicmd description of mpls-te export, other instance in isisd
/home/rambo/frr/doc/user/ospfd.rst:1199: WARNING: duplicate clicmd description of segment-routing on, other instance in isisd
/home/rambo/frr/doc/user/ospfd.rst:1205: WARNING: duplicate clicmd description of segment-routing global-block (16-1048575) (16-1048575) [local-block (16-1048575) (16-1048575)], other instance in isisd
/home/rambo/frr/doc/user/ospfd.rst:1212: WARNING: duplicate clicmd description of segment-routing node-msd (1-16), other instance in isisd
/home/rambo/frr/doc/user/ospfd.rst:1247: WARNING: duplicate clicmd description of aggregation timer (5-1800), other instance in ospf6d
/home/rambo/frr/doc/user/ospfd.rst:1341: WARNING: duplicate clicmd description of debug ospf [(1-65535)] graceful-restart, other instance in ospfd
/home/rambo/frr/doc/user/pbr.rst:28: WARNING: duplicate label nexthop-groups, other instance in /home/rambo/frr/doc/user/nexthop_groups.rst
/home/rambo/frr/doc/user/pimv6.rst:71: WARNING: duplicate clicmd description of rp keep-alive-timer (1-65535), other instance in pim
/home/rambo/frr/doc/user/pimv6.rst:139: WARNING: duplicate clicmd description of spt-switchover infinity-and-beyond [prefix-list PLIST], other instance in pim
/home/rambo/frr/doc/user/pimv6.rst:149: WARNING: duplicate clicmd description of join-prune-interval (1-65535), other instance in pim
/home/rambo/frr/doc/user/pimv6.rst:157: WARNING: duplicate clicmd description of keep-alive-timer (1-65535), other instance in pim
/home/rambo/frr/doc/user/pimv6.rst:164: WARNING: duplicate clicmd description of packets (1-255), other instance in pim
/home/rambo/frr/doc/user/pimv6.rst:172: WARNING: duplicate clicmd description of register-suppress-time (1-65535), other instance in pim
/home/rambo/frr/doc/user/ripd.rst:97: WARNING: duplicate clicmd description of network NETWORK, other instance in eigrpd
/home/rambo/frr/doc/user/ripd.rst:109: WARNING: duplicate clicmd description of network IFNAME, other instance in babeld
/home/rambo/frr/doc/user/ripd.rst:141: WARNING: duplicate clicmd description of passive-interface (IFNAME|default), other instance in eigrpd
/home/rambo/frr/doc/user/ripd.rst:227: WARNING: duplicate clicmd description of default-information originate, other instance in ospfd
/home/rambo/frr/doc/user/ripd.rst:302: WARNING: duplicate clicmd description of distance (1-255), other instance in ospfd
/home/rambo/frr/doc/user/ripd.rst:307: WARNING: duplicate clicmd description of distance (1-255) A.B.C.D/M, other instance in bgp
/home/rambo/frr/doc/user/ripngd.rst:31: WARNING: duplicate clicmd description of network NETWORK, other instance in ripd
/home/rambo/frr/doc/user/ripngd.rst:35: WARNING: duplicate clicmd description of network IFNAME, other instance in ripd
/home/rambo/frr/doc/user/ripngd.rst:43: WARNING: duplicate clicmd description of allow-ecmp [1-MULTIPATH_NUM], other instance in ripd
/home/rambo/frr/doc/user/ripngd.rst:69: WARNING: duplicate clicmd description of distribute-list [prefix] LIST <in|out> IFNAME, other instance in ripd
/home/rambo/frr/doc/user/ripngd.rst:107: WARNING: duplicate clicmd description of match interface WORD, other instance in ripd
/home/rambo/frr/doc/user/ripngd.rst:123: WARNING: duplicate clicmd description of match metric (0-4294967295), other instance in ripd
/home/rambo/frr/doc/user/routemap.rst:250: WARNING: duplicate clicmd description of set tag <untagged|(1-4294967295)>, other instance in ripngd
/home/rambo/frr/doc/user/routemap.rst:356: WARNING: duplicate clicmd description of set ipv6 next-hop local IPV6_ADDRESS, other instance in ripngd
/home/rambo/frr/doc/user/routemap.rst:373: WARNING: duplicate clicmd description of set l3vpn next-hop encapsulation gre, other instance in bgp
/home/rambo/frr/doc/user/sbfd.rst:214: WARNING: duplicate clicmd description of sbfd reflector source-address 200::D discriminator 456, other instance in sbfd
/home/rambo/frr/doc/user/static.rst:197: WARNING: duplicate clicmd description of segment-routing, other instance in pathd
/home/rambo/frr/doc/user/zebra.rst:143: WARNING: duplicate clicmd description of shutdown, other instance in bfd
/home/rambo/frr/doc/user/zebra.rst:913: WARNING: duplicate clicmd description of segment-routing, other instance in static
/home/rambo/frr/doc/user/zebra.rst:917: WARNING: duplicate clicmd description of srv6, other instance in static
/home/rambo/frr/doc/user/zebra.rst:926: WARNING: duplicate clicmd description of locator NAME, other instance in isisd
/home/rambo/frr/doc/user/zebra.rst:1067: WARNING: duplicate clicmd description of format NAME, other instance in zebra
  SPHINX   doc/user/_build/texinfo/frr.texi
  MAKEINFO doc/user/_build/texinfo/frr.info
frr.texi:37144: warning: @ref should not appear on @item line
frr.texi:37151: warning: @ref should not appear on @item line
frr.texi:37157: warning: @ref should not appear on @item line
frr.texi:37162: warning: @ref should not appear on @item line
frr.texi:37171: warning: @ref should not appear on @item line
frr.texi:37177: warning: @ref should not appear on @item line
frr.texi:37183: warning: @ref should not appear on @item line
frr.texi:37190: warning: @ref should not appear on @item line
  SPHINX   doc/manpages/_build/.doctrees/environment.pickle
  SPHINX   doc/manpages/_build/man/man.stamp
make[1]: Leaving directory '/home/rambo/frr'




rambo@ubuntu24-1:~/frr$ sudo make install


# 安装FRR配置文件
rambo@ubuntu24-1:~/frr$ 
sudo install -m 775 -o frr -g frr -d /var/log/frr
sudo install -m 775 -o frr -g frrvty -d /etc/frr
sudo install -m 640 -o frr -g frrvty tools/etc/frr/vtysh.conf /etc/frr/vtysh.conf
sudo install -m 640 -o frr -g frr tools/etc/frr/frr.conf /etc/frr/frr.conf
sudo install -m 640 -o frr -g frr tools/etc/frr/daemons.conf /etc/frr/daemons.conf
sudo install -m 640 -o frr -g frr tools/etc/frr/daemons /etc/frr/daemons



# 调整sysctls
为了启用 IPv4/IPv6 转发和 MPLS(如果您的平台支持),需要更改一些sysctl参数
如果您的平台不支持 MPLS,请跳过本节中与 MPLS 相关的配置
rambo@ubuntu24-1:~/frr$ sudo vim /etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1


rambo@ubuntu24-1:~/frr$ sudo sysctl -p



# 添加MPLS内核模块
Ubuntu 24.04 搭载内核 5.4;MPLS 模块默认存在。启用如下:
rambo@ubuntu24-1:~/frr$ sudo vim /etc/modules-load.d/modules.conf
mpls_router
mpls_iptunnel



# 启用MPLS转发
编辑 /etc/sysctl.conf 并添加以下行。确保为每个使用 MPLS 的接口添加一行,内容等于 net.mpls.conf.eth0.input
rambo@ubuntu24-1:~/frr$ sudo vim /etc/sysctl.conf
net.mpls.conf.ens33.input=1
net.mpls.conf.ens36.input=1
net.mpls.platform_labels=100000


rambo@ubuntu24-1:~/frr$ sudo sysctl -p



# 安装服务文件
rambo@ubuntu24-1:~/frr$ sudo install -m 644 tools/frr.service /etc/systemd/system/frr.service
rambo@ubuntu24-1:~/frr$ sudo systemctl enable frr


# 启用守护进程
rambo@ubuntu24-1:~/frr$ sudo grep "=yes" /etc/frr/daemons
bgpd=yes
ospfd=yes
ldpd=yes
eigrpd=yes
vrrpd=yes
vtysh_enable=yes


# 启动FRR
rambo@ubuntu24-1:~/frr$ sudo systemctl restart frr
rambo@ubuntu24-1:~/frr$ sudo systemctl status frr
● frr.service - FRRouting
     Loaded: loaded (/etc/systemd/system/frr.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-04-23 08:41:57 CST; 22s ago
       Docs: https://frrouting.readthedocs.io/en/latest/setup.html
    Process: 70322 ExecStart=/usr/lib/frr/frrinit.sh start (code=exited, status=0/SUCCESS)
   Main PID: 70333 (watchfrr)
     Status: "FRR Operational"
      Tasks: 26 (limit: 4558)
     Memory: 41.9M (peak: 55.0M)
        CPU: 530ms
     CGroup: /system.slice/frr.service
             ├─70333 /usr/lib/frr/watchfrr -d zebra mgmtd bgpd ospfd ldpd eigrpd staticd vrrpd
             ├─70349 /usr/lib/frr/zebra -d -F traditional -A 127.0.0.1 -s 90000000
             ├─70354 /usr/lib/frr/mgmtd -d -F traditional -A 127.0.0.1
             ├─70356 /usr/lib/frr/bgpd -d -F traditional -A 127.0.0.1
             ├─70363 /usr/lib/frr/ospfd -d -F traditional -A 127.0.0.1
             ├─70366 /usr/lib/frr/ldpd -L -u frr -g frr
             ├─70367 /usr/lib/frr/ldpd -E -u frr -g frr
             ├─70368 /usr/lib/frr/ldpd -d -F traditional -A 127.0.0.1
             ├─70372 /usr/lib/frr/eigrpd -d -F traditional -A 127.0.0.1
             ├─70375 /usr/lib/frr/staticd -d -F traditional -A 127.0.0.1
             └─70378 /usr/lib/frr/vrrpd -d -F traditional -A 127.0.0.1

Apr 23 08:41:57 ubuntu24-1 watchfrr[70333]: [QDG3Y-BY5TN] bgpd state -> up : connect succeeded
Apr 23 08:41:57 ubuntu24-1 watchfrr[70333]: [QDG3Y-BY5TN] ospfd state -> up : connect succeeded
Apr 23 08:41:57 ubuntu24-1 watchfrr[70333]: [QDG3Y-BY5TN] ldpd state -> up : connect succeeded
Apr 23 08:41:57 ubuntu24-1 watchfrr[70333]: [QDG3Y-BY5TN] eigrpd state -> up : connect succeeded
Apr 23 08:41:57 ubuntu24-1 watchfrr[70333]: [QDG3Y-BY5TN] staticd state -> up : connect succeeded
Apr 23 08:41:57 ubuntu24-1 watchfrr[70333]: [QDG3Y-BY5TN] vrrpd state -> up : connect succeeded
Apr 23 08:41:57 ubuntu24-1 watchfrr[70333]: [KWE5Q-QNGFC] all daemons up, doing startup-complete notify
Apr 23 08:41:57 ubuntu24-1 frrinit.sh[70322]:  * Started watchfrr
Apr 23 08:41:57 ubuntu24-1 systemd[1]: Started frr.service - FRRouting.
Apr 23 08:41:58 ubuntu24-1 zebra[70349]: [V98V0-MTWPF] client 71 says hello and bids fair to announce only bgp routes vrf=0



vm1上配置bgp、ospf、mpls

下述配置中不要带注释,否则会不生效

rambo@ubuntu24-1:~/frr$ sudo vim /etc/frr/frr.conf
# 配置bgp
router bgp 65001                         # BGP AS号
 bgp router-id 172.16.186.117             # 设置路由器的BGP标识符
 network 172.16.186.117/24                # 广播桥接网卡的网段
 network 10.0.0.1/24                     # 广播LAN网卡的网段
# bgp配置邻居
 neighbor 172.16.186.118 remote-as 65002  # 邻居路由器配置
 neighbor 172.16.186.118 update-source ens33  # 更新源接口
 neighbor 172.16.186.118 ebgp-multihop 2  # 配置多跳BGP(如果需要)
 neighbor 172.16.186.118 activate         # 激活邻居


# 配置ospf
router ospf
 router-id 172.16.186.117        # 设置 OSPF 路由器 ID
 network 172.16.186.117/24 area 0   # 将桥接网卡添加到OSPF Area 0中
 network 10.0.0.1/24 area 0       # 将LAN网卡添加到OSPF Area 0中
# 配置OSPF邻居的接口
  interface ens33
    ip ospf hello-interval 10  # 配置 OSPF Hello 间隔(秒)
    ip ospf dead-interval 40   # 配置 OSPF 死亡间隔(秒)
# 配置其他接口,确保它们参与OSPF
  interface ens36
    ip ospf hello-interval 10
    ip ospf dead-interval 40


# 配置mpls
mpls
 ldp
  router-id 172.16.186.117           # 设置 MPLS 路由器 ID
  interface ens33                   # 配置 MPLS 启用的接口(比如ens33)
  interface ens36                   # 配置第二个接口(根据实际情况选择)
  maximum-paths 16                  # 设置最大路径数
 exit

router eigrp 65001                     # 启用EIGRP路由协议,AS(自治系统)编号为65001
 eigrp router-id 172.16.186.117        # 指定EIGRP的路由器ID
 network 10.0.0.0/24                   # 在EIGRP中声明要参与的网络段,10和172网段
 network 172.16.186.0/24
 no auto-summary                       # 禁用自动汇总。EIGRP默认会对不同网络段进行汇总,禁用该选项可以避免这种行为

 interface ens33                       # 指定哪些接口参与EIGRP路由
  ip eigrp 65001                       # 为接口启用EIGRP路由协议
  passive-interface                    # ens33接口不会发送EIGRP hello报文,通常用于需要防止特定接口参与邻居发现的场景

 interface ens36
  ip eigrp 65001
end

rambo@ubuntu24-1:~/frr$ sudo systemctl restart frr



vm2上配置bgp、ospf、mpls

下述配置中不要带注释,否则会不生效

rambo@ubuntu24-2:~/frr$ sudo vim /etc/frr/frr.conf
log syslog informational
# 配置BGP
router bgp 65002                          # 设置 BGP AS号
 bgp router-id 172.16.186.118             # 设置路由器的 BGP 标识符,应该是第二台的 IP 地址
 network 172.16.186.118/24                # 广播桥接网卡的网段
 network 10.0.0.2/24                      # 广播 LAN 网卡的网段(假设第二台的 LAN 网络是 10.0.0.2/24)
# 配置 BGP 邻居(第一台设备)
 neighbor 172.16.186.117 remote-as 65001  # 邻居路由器配置(与第一台设备互为邻居)
 neighbor 172.16.186.117 update-source ens33  # 更新源接口(与第一台一致)
 neighbor 172.16.186.117 ebgp-multihop 2  # 配置多跳 BGP(如果需要)
 neighbor 172.16.186.117 activate         # 激活邻居

# 配置OSPF
# 第二台设备上配置OSPF与第一台设备一致,确保它们在相同的 OSPF 区域中,并且接口与第一台设备连接。
router ospf
 router-id 172.16.186.118            # 设置 OSPF 路由器 ID,应该是第二台的 IP 地址
 network 172.16.186.118/24 area 0    # 将桥接网卡添加到 OSPF Area 0中
 network 10.0.0.2/24 area 0          # 将 LAN 网卡添加到 OSPF Area 0 中(假设第二台的 LAN 网络是 10.0.0.2/24)
# 配置 OSPF 邻居接口
 interface ens33
   ip ospf hello-interval 10    # 配置OSPF Hello间隔(秒)
   ip ospf dead-interval 40     # 配置OSPF 死亡间隔(秒)
# 配置其他接口,确保它们参与 OSPF
  interface ens36
    ip ospf hello-interval 10
    ip ospf dead-interval 40


# 配置MPLS
mpls
 ldp
  router-id 172.16.186.118           # 设置MPLS路由器ID,应该是第二台的IP地址
  interface ens33                    # 配置MPLS启用的接口(假设接口名称是ens33)
  interface ens36                    # 配置第二个接口(根据实际情况选择)
  maximum-paths 16                   # 设置最大路径数
 exit

router eigrp 65001
 eigrp router-id 172.16.186.117
 network 10.0.0.0/24
 network 172.16.186.0/24
 no auto-summary

 interface ens33
  ip eigrp 65001
  passive-interface

 interface ens36
  ip eigrp 65001

end


rambo@ubuntu24-1:~/frr$ sudo systemctl restart frr


2台都配置好后做检查

# 在第一台ubuntu24上
1、检查bgp配置
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show ip bgp summary"

IPv4 Unicast Summary:
BGP router identifier 172.16.186.117, local AS number 65001 VRF default vrf-id 0
BGP table version 2
RIB entries 3, using 384 bytes of memory
Peers 1, using 24 KiB of memory

Neighbor        V         AS   MsgRcvd   MsgSent   TblVer  InQ OutQ  Up/Down State/PfxRcd   PfxSnt Desc
172.16.186.118  4      65001         0         2        0    0    0    never       Active        0 N/A

Total number of neighbors 1


2、检查ospf邻居关系
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show ip ospf neighbor"

Neighbor ID     Pri State           Up Time         Dead Time Address         Interface                  RXmtL RqstL DBsmL
172.16.186.118    1 ExStart/Backup  2.704s            37.294s 172.16.186.118  ens33:172.16.186.117           0     0     0
172.16.186.118    1 ExStart/Backup  2.703s            37.296s 10.0.0.2        ens36:10.0.0.1                 0     0     0



3、查看mpls
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show mpls ldp neighbor"

注:这里不知道是什么情况,不能使用mpls


4、查看EIGRP路由表
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show ip route eigrp"
Codes: K - kernel route, C - connected, L - local, S - static,
       R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR,
       f - OpenFabric, t - Table-Direct,
       > - selected route, * - FIB route, q - queued, r - rejected, b - backup
       t - trapped, o - offload failure

IPv4 unicast VRF default:
E   10.0.0.0/24 [90/28160] is directly connected, ens36, weight 1, 00:00:11
E   172.16.186.0/24 [90/28160] is directly connected, ens33, weight 1, 00:00:11



# 查看EIGRP拓扑表
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show ip eigrp topology"
EIGRP Topology Table for AS(65001)/ID(172.16.186.117)

Codes: P - Passive, A - Active, U - Update, Q - Query, R - Reply
       r - reply Status, s - sia Status

P  10.0.0.0/24, 1 successors, FD is 28160, serno: 0 
       via Connected, ens36
P  172.16.186.0/24, 1 successors, FD is 28160, serno: 0 
       via Connected, ens33






# 查看已学习的 BGP 路由
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show bgp ipv4 unicast"
BGP table version is 2, local router ID is 172.16.186.117, vrf id 0
Default local pref 100, local AS 65001
Status codes:  s suppressed, d damped, h history, u unsorted, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>  10.0.0.0/24      0.0.0.0                  0         32768 i
 *>  172.16.186.0/24  0.0.0.0                  0         32768 i

Displayed 2 routes and 2 total paths


# 查看某个前缀的详细 BGP 路由信息
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show bgp ipv4 unicast 10.0.0.0/24"
BGP routing table entry for 10.0.0.0/24, version 2
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Local
    0.0.0.0 (metric 101) from 0.0.0.0 (172.16.186.117)
      Origin IGP, metric 0, weight 32768, valid, sourced, local, best (First path received)
      Last update: Wed Apr 23 11:28:34 2025


# 查看OSPF路由(从OSPF学到的)
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show ip route ospf"
Codes: K - kernel route, C - connected, L - local, S - static,
       R - RIP, O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, F - PBR,
       f - OpenFabric, t - Table-Direct,
       > - selected route, * - FIB route, q - queued, r - rejected, b - backup
       t - trapped, o - offload failure

IPv4 unicast VRF default:
O   10.0.0.0/24 [110/100] is directly connected, ens36, weight 1, 01:07:40
O   172.16.186.0/24 [110/100] is directly connected, ens33, weight 1, 00:05:44



# 查看OSPF网络/接口状态
rambo@ubuntu24-1:~/frr$ sudo vtysh -c "show ip ospf interface"
ens33 is up
  ifindex 2, MTU 1500 bytes, BW 1000 Mbit <UP,LOWER_UP,BROADCAST,RUNNING,MULTICAST>
  Internet Address 172.16.186.117/24, Broadcast 172.16.186.255, Area 0.0.0.0
  MTU mismatch detection: enabled
  Router ID 172.16.186.117, Network Type BROADCAST, Cost: 100
  Transmit Delay is 1 sec, State Backup, Priority 1
  Designated Router (ID) 172.16.186.118 Interface Address 172.16.186.118/24
  Backup Designated Router (ID) 172.16.186.117, Interface Address 172.16.186.117
  Multicast group memberships: OSPFAllRouters OSPFDesignatedRouters
  Timer intervals configured, Hello 10s, Dead 40s, Wait 40s, Retransmit 5
    Hello due in 0.762s
  Neighbor Count is 1, Adjacent neighbor count is 1
  Graceful Restart hello delay: 10s
  LSA retransmissions: 1
ens36 is up
  ifindex 3, MTU 1500 bytes, BW 1000 Mbit <UP,LOWER_UP,BROADCAST,RUNNING,MULTICAST>
  Internet Address 10.0.0.1/24, Broadcast 10.0.0.255, Area 0.0.0.0
  MTU mismatch detection: enabled
  Router ID 172.16.186.117, Network Type BROADCAST, Cost: 100
  Transmit Delay is 1 sec, State Backup, Priority 1
  Designated Router (ID) 172.16.186.118 Interface Address 10.0.0.2/24
  Backup Designated Router (ID) 172.16.186.117, Interface Address 10.0.0.1
  Multicast group memberships: OSPFAllRouters OSPFDesignatedRouters
  Timer intervals configured, Hello 10s, Dead 40s, Wait 40s, Retransmit 5
    Hello due in 2.541s
  Neighbor Count is 1, Adjacent neighbor count is 1
  Graceful Restart hello delay: 10s
  LSA retransmissions: 1




# 抓包看协议交换过程
rambo@ubuntu24-1:~/frr$ sudo tcpdump -v -i ens33 port 179 or proto ospf

posted @ 2025-04-23 15:33  Linux大魔王  阅读(235)  评论(0)    收藏  举报