MENU

在openwrt上配置TunnelBroker的BGP Tunnel並進行ipv6宣告

上一篇文章描述了如何在不借助ISP的情況下宣告自己的IPv6,此文章則是對上一篇文章的實現,這篇文章將使用openwrt和bird6進行,在閱讀此篇文章之前建議先閱讀前面4篇文章.

準備

實現廣播需要以下先決條件

  • 一個openwrt的路由器(這裡使用newifi3 d2)
  • 一個ASN
  • 一個ipv6 block

這裡要注意,路由器的內存應該是512M或以上,宣告ip後會有很多路由表存在於自己的路由器上,這會佔用大量的內存(pop越多,對等越多則路由表越多,內存佔用越大),所以要求路由器有大容量的內存來保存路由表,內存當然是越大越好,最低不應該低於256m(如果你只打算使用TunnelBroker的BGP Tunnel來宣告ipv6則256m夠用),而閃存則建議32M或以上,推薦使用支持硬NAT的路由器,以便達到最佳傳輸速度.
這裡推薦一部分自己篩選出來的其它幾個:edgerouter-x(內存閃存各256m,cpu為mtk) edgerouter-lite(內存512m閃存未知,cpu為:broadcom) wrt1900ac(256m內存128m閃存,cpu為:marvell)

安裝必要組件

所有用到的組件官方倉庫全部提供,所以只需要使用opkg安裝即可.

opkg update
opkg install bird6 birdc6 6in4 luci-proto-ipv6

也可以考慮安裝luci-app-bird6bird6-uci進行配置和管理,但是我感覺luci很難用,所以沒有安裝它.

配置隧道

TunnelBrocker的隧道詳情內就有配置示例,可以直接使用

uci set network.henet=interface
uci set network.henet.proto=6in4
uci set network.henet.peeraddr=你的公網ip
uci set network.henet.ip6addr='隧道的客戶端ipv6'
uci set network.henet.ip6prefix='/64'
uci set network.henet.tunnelid=你的隧道id
uci set network.henet.username=你的tunnerbroker的用戶名
uci set network.henet.password='你的tunnerbroker的密碼'
uci commit network

uci set firewall.@zone[1].network='wan henet'
uci commit firewall

/etc/init.d/network restart
/etc/init.d/firewall reload

然後在網絡->接口,應該可以看到一個HENET的接口.

配置bird6

關於隧道的配置上一篇文章內已經有說明,這裡只配置bird6,文件位置在/etc/bird6.conf

log syslog all;
router id 你的公網ip;

filter normal_out
{
    if proto = "Announce" then accept;
    if proto = "NA" then reject;
    reject;
}

protocol static Announce
{
    import all;
    route 2333:2333:233::/48 reject;
}

protocol static NA
{
    route 2333:2333:233::/60 reject;
}

protocol kernel {
        scan time 60;
        import none;
}

#protocol static
#{
#    route  2333:2333:233::/48 via 1234:5467:7890::2;
#}

protocol device {
        scan time 60;
}

protocol direct
{
    interface "br-lan";
    import all;
}

protocol direct
{
    interface "6in4-henet"; #你的6in4網卡名稱
    import all;
}

protocol bgp he
{
        local as 你的asn;
        source address 隧道客戶端ipv6;
        import all;
        export filter normal_out;
        graceful restart on;
        multihop 2;
        neighbor 隧道服務端ipv6 as 6939;
}

關於filter normal_out和其下面兩個protocol static,這是餘暉脈脈小伙伴提供給我的,其中Announce裡是需要宣告的ip block,NA裡則是需要過濾的ip block,為了防止給路由造成麻煩,一致認為宣告的ip block最小為/48,這個filter就是為了實現此功能而設計的,在Announce內填寫宣告的ip block,分配給內部網卡或者子級設備使用的小於/48的block或單一ip則要放進NA裡.

關於router id部分,事後驗證如果router id不能正確設置,則可能會導致不能正確路由的情況,下面代碼是由Vicer為我修改的壹個hotplug腳本,當pppoe撥號後會自動取獲得的ip修改bird6配置文件並重啟bird6.

#!/bin/sh

update_bird(){
    IP="$(curl -4 -s --connect-timeout 10 -m 20 https://ipinfo.io/ip | grep -o '[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}')"
    if [ ! -n "$IP" ]; then
        sleep 5s
        update_bird
    else
        sed -i "s/^router id.*/router id $IP;/" /etc/bird6.conf
        /etc/init.d/bird6 restart
    fi
}


if [ "ifup" == "$ACTION" ] && [ "pppoe-wan" == "$DEVICE" ]; then
    update_bird
fi

exit 0

將它保存到/etc/hotplug.d/iface/30-bird且權限設置為目錄內其它腳本同等權限即可,當然,文件名和前面的優先級可以修改.

配置好後重啟bird6後使用其它ipv6的機器進行路由追踪,如果發現有路由則為廣播成功.

後續配置

成功宣告之後則要將ip分配給自己或子級設備使用.
首先設置HENET網卡,添加路由前綴
網絡->接口->HENET->編輯->一般配置->基本設置->IPv6路由前缀,這裡填寫宣告的ip block,然後點擊保存並應用.

然後設置lan接口,為下級分配更小的block給二級路由器下面的設備使用,這裡需要設置多處
網絡->接口->LAN->編輯->一般配置->基本設置->IPv6分配长度,可以填寫任意小於/48的設置,推薦設置為/60,這樣子級設備還可以為它的子級設備分配更小的塊.
然後同頁面找到DHCP服务器->IPv6设置->DHCPv6模式將其改為有狀態.
然後保存並應用

然後回到網絡->接口,將LAN獲取的IP block添加到/etc/bird6.confNA裡,然後重啟bird6,大功告成,你的子級設備可以通過dhcp獲取一個ipv6以及一個/60的block給它的子級設備分配.

最后编辑于: 2019 年 01 月 22 日
添加新评论

已有 5 条评论
  1. FontanaE FontanaE

    我的openwrt源里没有bird6 birdc 6in4啊 好难受 不知道换了多少软件源都没有 从腾讯换到中科大再换回官方 从版本号换到snapshot 都没有 我都麻了都

    1. @FontanaEopenwrt版本?

    2. FontanaE FontanaE

      @shirakunPowered by LuCI openwrt-18.06-k5.4 branch (git-21.355.72893-3484628) / ArgonTheme v1.7.2 / ImmortalWrt 18.06-SNAPSHOT r11451-f2be5aa53c (2021-12-29)

    3. @FontanaE刚刚看了下软件源,现在已经变成bird1-ipv6了

    4. FontanaE FontanaE

      @shirakun我就说,,好像某个软件源里是有bird1-ipv6来着,但是同样有bird2-ipv6等等,请问一共需要安装哪些包来替换bird6 bird6c和6in4呢

996.icu 996.icu