@ユメイ1 小时前

09/7
19:12
internet

crs305使用ponstick通过dac连接UCG Fiber

/interface list
add name=MGMT

/interface bridge
add name=br-pon \
protocol-mode=rstp \
vlan-filtering=no \
igmp-snooping=no

/interface bridge port

# SFP1 = PONStick
# VLAN99 untagged management
# VLAN1268/44/40 tagged
add bridge=br-pon \
interface=sfp-sfpplus1 \
pvid=99 \
ingress-filtering=yes \
frame-types=admit-all \
hw=yes

# SFP2 = local management
add bridge=br-pon \
interface=sfp-sfpplus2 \
pvid=99 \
ingress-filtering=yes \
frame-types=admit-only-untagged-and-priority-tagged \
hw=yes \
edge=yes

# SFP3 = UCG WAN
# untagged PPPoE -> VLAN1268
# tagged VLAN99 -> management
add bridge=br-pon \
interface=sfp-sfpplus3 \
pvid=1268 \
ingress-filtering=yes \
frame-types=admit-all \
hw=yes \
edge=yes

# SFP4 = local management
add bridge=br-pon \
interface=sfp-sfpplus4 \
pvid=99 \
ingress-filtering=yes \
frame-types=admit-only-untagged-and-priority-tagged \
hw=yes \
edge=yes

# ether1 = IPTV
add bridge=br-pon \
interface=ether1 \
pvid=44 \
ingress-filtering=yes \
frame-types=admit-all \
hw=yes \
edge=yes

/interface bridge vlan

# Management VLAN99
add bridge=br-pon \
vlan-ids=99 \
tagged=br-pon,sfp-sfpplus3 \
untagged=sfp-sfpplus1,sfp-sfpplus2,sfp-sfpplus4

# Internet VLAN1268
add bridge=br-pon \
vlan-ids=1268 \
tagged=sfp-sfpplus1 \
untagged=sfp-sfpplus3

# IPTV VLAN44
add bridge=br-pon \
vlan-ids=44 \
tagged=sfp-sfpplus1 \
untagged=ether1

# IPTV multicast VLAN40
add bridge=br-pon \
vlan-ids=40 \
tagged=sfp-sfpplus1 \
untagged=ether1

/interface vlan
add name=vlan99-mgmt \
interface=br-pon \
vlan-id=99

/ip address
add address=192.168.0.2/24 \
interface=vlan99-mgmt

/ip route
add dst-address=172.22.22.0/24 gateway=192.168.0.3 comment=”UCG LAN via VLAN99″

/interface list member
add interface=vlan99-mgmt list=MGMT

/ip neighbor discovery-settings
set discover-interface-list=MGMT

/tool mac-server
set allowed-interface-list=MGMT

/tool mac-server mac-winbox
set allowed-interface-list=MGMT

/interface bridge
set br-pon vlan-filtering=yes

上海联通适用自带管理网卡输出iptv

ucg 7号sfp+口 接入wan

ip link add link eth6 name eth6.99 type vlan id 99
ip link set eth6.99 up
ip addr add 192.168.0.3/24 dev eth6.99

UCG-Fiber + CRS305 VLAN99 最终方案

一、拓扑

                 UCG-Fiber
                    │
                   eth6
                    │
              eth6.99 / VLAN99
              192.168.0.3/24
                    │
                    │ VLAN 99 Tagged
                    │
               CRS305 SFP3
                    │
                  br-pon
                    │
             VLAN99 Untagged
                    │
               CRS305 SFP1
                    │
               192.168.0.1

CRS305 本身:

CRS305 管理地址:192.168.0.2/24
UCG VLAN99地址:192.168.0.3/24
VLAN ID:99

因此 UCG 上:

ip route get 192.168.0.2

应该得到:

192.168.0.2 dev eth6.99 src 192.168.0.3

二、UCG-Fiber 的 GitHub on_boot

unifi-utilities/unifi-common

以后如果需要重新安装,使用:

curl -fsL "https://raw.githubusercontent.com/unifi-utilities/unifi-common/HEAD/remote_install.sh" | /bin/bash

但你现在不需要重新安装


三、on_boot 的目录

/data/on_boot.d/

udm-boot.service 是:

find -L /data/on_boot.d/ -mindepth 1 -maxdepth 1 -type f

它会执行目录里的所有普通文件

所以:

50-ucg-vlan99.sh
50-ucg-vlan99.sh.bak

会被执行两次。

删除:

rm -f /data/on_boot.d/50-ucg-vlan99.sh.bak

四、正式的 on_boot VLAN99 脚本

文件:

/data/on_boot.d/50-ucg-vlan99.sh

内容就是你现在已经验证过的版本:

#!/bin/bash

PARENT="eth6"
VLAN_IF="eth6.99"
VLAN_ID="99"
IP_ADDR="192.168.0.3/24"
SUBNET="192.168.0.0/24"

LOG="/data/ucg-vlan99.log"

log() {
    echo "$(date '+%F %T') $*" >> "$LOG"
}

log "===== VLAN99 START ====="

# 等待 eth6 出现
for i in $(seq 1 60); do
    if ip link show "$PARENT" >/dev/null 2>&1; then
        break
    fi
    sleep 1
done

if ! ip link show "$PARENT" >/dev/null 2>&1; then
    log "ERROR: $PARENT not found"
    exit 1
fi

# 创建 VLAN99
if ! ip link show "$VLAN_IF" >/dev/null 2>&1; then
    log "Creating $VLAN_IF"
    ip link add link "$PARENT" name "$VLAN_IF" type vlan id "$VLAN_ID"
fi

# UP
ip link set "$VLAN_IF" up

# 添加管理 IP
if ! ip -4 addr show dev "$VLAN_IF" | grep -q "192.168.0.3/24"; then
    log "Adding $IP_ADDR"
    ip addr add "$IP_ADDR" dev "$VLAN_IF"
fi

# 确保路由存在
ip route replace "$SUBNET" dev "$VLAN_IF" src 192.168.0.3

log "VLAN99 ready"

ip -br addr show "$VLAN_IF" >> "$LOG"
ip route show "$SUBNET" >> "$LOG"

log "===== VLAN99 END ====="

exit 0

权限:

chmod +x /data/on_boot.d/50-ucg-vlan99.sh

五、为什么脚本里面要有 route replace

这一句:

ip route replace "$SUBNET" dev "$VLAN_IF" src 192.168.0.3

对应:

192.168.0.0/24
        ↓
    eth6.99
        ↓
192.168.0.3

所以 UCG 到:

192.168.0.2

会走 VLAN99。

这也是你之前验证:

ip route get 192.168.0.2

得到:

192.168.0.2 dev eth6.99 src 192.168.0.3

的原因。


六、Watchdog

为了防止 UniFi 网络组件在启动后重新初始化 eth6,你后来又加了一层 watchdog。

文件:

/etc/systemd/system/ucg-vlan99-watchdog.service

内容:

[Unit]
Description=UCG VLAN99 Watchdog
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/sbin/ucg-vlan99-watchdog.sh
Restart=always
RestartSec=2

[Install]
WantedBy=multi-user.target

七、Watchdog 脚本

文件:

/usr/local/sbin/ucg-vlan99-watchdog.sh

最终版本:

#!/bin/bash

PARENT="eth6"
VLAN_IF="eth6.99"
VLAN_ID="99"
IP_ADDR="192.168.0.3/24"
SUBNET="192.168.0.0/24"
LOG="/data/ucg-vlan99.log"

log() {
    echo "$(date '+%F %T') WATCHDOG: $*" >> "$LOG"
}

ensure_vlan() {
    # eth6 不存在,什么都不做
    ip link show "$PARENT" >/dev/null 2>&1 || return 0

    # eth6 存在但还没 UP,等待 UniFi 网络初始化
    state=$(ip -o link show "$PARENT" 2>/dev/null | sed -n 's/.*state \([^ ]*\).*/\1/p')
    [ "$state" = "UP" ] || return 0

    # VLAN 不存在 → 创建
    if ! ip link show "$VLAN_IF" >/dev/null 2>&1; then
        log "eth6.99 missing, creating VLAN99"

        if ip link add link "$PARENT" \
            name "$VLAN_IF" \
            type vlan id "$VLAN_ID" 2>>"$LOG"; then
            log "VLAN99 created"
        else
            log "ERROR: failed to create VLAN99"
            return 1
        fi

        ip link set "$VLAN_IF" up 2>>"$LOG"
    fi

    # 确保 UP
    ip link set "$VLAN_IF" up 2>/dev/null

    # 确保 IP
    if ! ip -4 addr show dev "$VLAN_IF" | grep -q "192.168.0.3/24"; then
        log "192.168.0.3/24 missing, adding"

        ip addr add "$IP_ADDR" dev "$VLAN_IF" 2>>"$LOG"
    fi

    # 确保直连路由
    ip route replace "$SUBNET" \
        dev "$VLAN_IF" \
        src 192.168.0.3 2>>"$LOG"
}

log "WATCHDOG started"

while true; do
    ensure_vlan
    sleep 3
done

权限:

chmod +x /usr/local/sbin/ucg-vlan99-watchdog.sh

八、启用 Watchdog

systemctl daemon-reload
systemctl enable --now ucg-vlan99-watchdog.service

检查:

systemctl status ucg-vlan99-watchdog --no-pager

应该是:

Active: active (running)

udm-boot 不一样:

udm-boot       → active (exited)   正常
watchdog       → active (running)  正常

因为 watchdog 是一个永久运行的循环:

while true; do
    ensure_vlan
    sleep 3
done

九、两套机制的分工

这是整个方案最重要的地方:

udm-boot

负责:

开机
 ↓
等待 eth6
 ↓
创建 eth6.99
 ↓
VLAN 99
 ↓
192.168.0.3/24
 ↓
192.168.0.0/24 route

watchdog

负责:

运行期间
 ↓
每 3 秒检查
 ↓
eth6 是否 UP
 ↓
eth6.99 是否存在
 ↓
IP 是否存在
 ↓
route 是否正确
 ↓
缺失就恢复

所以两者不是完全重复,而是:

             UCG 开机
                │
                ▼
        ┌───────────────┐
        │   udm-boot    │
        └───────┬───────┘
                │
                ▼
           eth6.99
           VLAN 99
                │
                ▼
          192.168.0.3
                ▲
                │
        ┌───────┴───────┐
        │    watchdog   │
        │   每3秒检查    │
        └───────────────┘

十、最终检查命令

以后重启 UCG 后,直接跑这一组:

systemctl status udm-boot --no-pager
systemctl status ucg-vlan99-watchdog --no-pager
ip -d link show eth6.99
ip addr show eth6.99
ip route get 192.168.0.2
ping -c 4 192.168.0.2
cat /data/ucg-vlan99.log

十一、最终状态应该是

UCG-Fiber
│
├── eth6
│
├── eth6.99
│     ├── VLAN ID 99
│     └── 192.168.0.3/24
│
├── udm-boot.service
│     └── /data/on_boot.d/50-ucg-vlan99.sh
│
└── ucg-vlan99-watchdog.service
      └── /usr/local/sbin/ucg-vlan99-watchdog.sh
             │
             └── 每3秒检查 VLAN99
                         │
                         ▼
                    CRS305 SFP3
                         │
                      VLAN99
                         │
                    192.168.0.2

crs305使用ponstick通过dac连接UCG Fiber