电竞比分网-中国电竞赛事及体育赛事平台

分享

雙網(wǎng)口nas主機(jī)通過(guò)飛牛fnos使用docker安裝openwrt作為主路由

 pio9999 2025-01-16 發(fā)布于廣西
 本帖最后由 hujinshengys 于 2025-1-10 11:11 編輯

在docker中運(yùn)行openwrt作主路由(pppoe撥號(hào))

查看網(wǎng)口情況:
  1. ifconfig
復(fù)制代碼
輸出以下內(nèi)容:
  1. enp2s0: flags=4419<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  2.         inet 192.168.1.4  netmask 255.255.255.0  broadcast 192.168.1.255
  3.         ether xx:xx:xx:xx:xx:xx  txqueuelen 1000  (Ethernet)
  4.         RX packets 835394  bytes 1122074499 (1.0 GiB)
  5.         RX errors 0  dropped 4720  overruns 0  frame 0
  6.         TX packets 289472  bytes 85663961 (81.6 MiB)
  7.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  8.         device memory 0x80800000-808fffff

  9. enp3s0: flags=4419<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  10.         inet 192.168.6.111  netmask 255.255.255.0  broadcast 192.168.6.255
  11.         inet6 fe80::xxxx:xxxx:xxxx:xxxx  prefixlen 64  scopeid 0x20<link>
  12.         ether xx:xx:xx:xx:xx:xx txqueuelen 1000  (Ethernet)
  13.         RX packets 216925  bytes 79441155 (75.7 MiB)
  14.         RX errors 0  dropped 1754  overruns 0  frame 0
  15.         TX packets 44369  bytes 6535667 (6.2 MiB)
  16.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  17.         device memory 0x80500000-805fffff
復(fù)制代碼
確定enp2s0為wan,enp3s0為lan
開始設(shè)置飛牛中的網(wǎng)絡(luò)環(huán)境,將相關(guān)命令通過(guò)服務(wù)的方式加入開機(jī)啟動(dòng)

本帖隱藏的內(nèi)容

  1. sudo nano /etc/systemd/system/me_to_op.service
復(fù)制代碼
  1. [Unit]
  2. Description=MACVLAN Configuration for me_to_op
  3. After=network-online.target
  4. Wants=network-online.target

  5. [Service]
  6. Type=oneshot
  7. ExecStart=/bin/sh -c "ip link set enp2s0 promisc on; ip link set enp3s0 promisc on; ip link del me_to_op || true; ip link add me_to_op link enp3s0 type macvlan mode bridge; ip addr add 192.168.6.6 dev me_to_op; ip link set me_to_op up; ip route add 192.168.6.1 dev me_to_op; route add default gw 192.168.6.1 me_to_op; echo 'nameserver 192.168.6.1' > /etc/resolv.conf"
  8. RemainAfterExit=yes

  9. [Install]
  10. WantedBy=multi-user.target
復(fù)制代碼
  1. #上述服務(wù)中的命令解釋(不需要輸入以下命令)
  2. sudo ip link set enp2s0 promisc on #設(shè)置網(wǎng)口混雜
  3. sudo ip link set enp3s0 promisc on #設(shè)置網(wǎng)口混雜
  4. #因?yàn)?macvlan 的安全機(jī)制,宿主機(jī)與容器內(nèi)不能通過(guò) macvlan 數(shù)據(jù)互通,但是 macvlan 之間可以互通,增加macvlan接口
  5. sudo ip link del me_to_op #刪除之前殘留設(shè)置
  6. sudo ip link add me_to_op link enp3s0 type macvlan mode bridge #新建me_to_op接口(類型macvlan)
  7. sudo ip addr add 192.168.6.6 dev me_to_op #設(shè)置本機(jī)在me_to_op接口的ip地址
  8. sudo ip link set me_to_op up #啟動(dòng)me_to_op接口
  9. sudo ip route add 192.168.6.1 dev me_to_op #修改路由,通過(guò)me_to_op接口訪問(wèn)openwrt,避免宿主機(jī)與容器之間無(wú)法訪問(wèn)的問(wèn)題
  10. sudo route add default gw 192.168.6.1 me_to_op #修改默認(rèn)路由
  11. sudo sh -c 'echo "nameserver 192.168.6.1" > /etc/resolv.conf' #修改dns服務(wù)器地址
復(fù)制代碼
  1. #重新加載 Systemd 以使更改生效
  2. sudo systemctl daemon-reload
  3. #啟用服務(wù)
  4. sudo systemctl enable me_to_op.service
  5. #啟動(dòng)服務(wù)
  6. sudo systemctl start me_to_op.service
  7. #檢查服務(wù)狀態(tài)
  8. sudo systemctl status me_to_op.service
復(fù)制代碼

創(chuàng)建docker網(wǎng)絡(luò)
  1. docker network create -d macvlan --subnet=192.168.6.0/24 --gateway=192.168.6.1 -o parent=enp3s0 op_lan
復(fù)制代碼
  1. docker network create -d macvlan -o parent=enp2s0 op_wan
復(fù)制代碼

導(dǎo)入docker鏡像
  1. wget https://dl./releases/24.10/targets/x86/64/kwrt-11.25.2024-x86-64-generic-rootfs.tar.gz
復(fù)制代碼
  1. docker import kwrt-11.25.2024-x86-64-generic-rootfs openwrt
復(fù)制代碼
  1. rm kwrt-11.25.2024-x86-64-generic-rootfs.tar.gz
復(fù)制代碼
創(chuàng)建并啟動(dòng)容器
  1. docker run --restart always --name openwrt -d --network op_lan --privileged openwrt:latest /sbin/init
復(fù)制代碼
  1. docker network connect op_wan openwrt
復(fù)制代碼
進(jìn)入openwrt內(nèi)部修改網(wǎng)口設(shè)置
  1. # 進(jìn)入openwrt鏡像內(nèi)部
  2. docker exec -it openwrt bash
  3. vim /etc/config/network
復(fù)制代碼
修改 lan 口ip地址(option ipaddr

  1. config interface 'lan'
  2.         option type 'bridge'
  3.         option ifname 'eth0'
  4.         option proto 'static'
  5.         option netmask '255.255.255.0'
  6.         option ip6assign '60'
  7.         option ipaddr '192.168.6.1'
復(fù)制代碼
  1. #重啟openwrt網(wǎng)絡(luò)
  2. /etc/init.d/network restart
復(fù)制代碼
然后瀏覽器輸入192.168.6.1即可進(jìn)入 openwrt 的后臺(tái)管理頁(yè)面(用戶名root,密碼root,不同openwrt不同,根據(jù)自己選擇的openwrt進(jìn)行輸入,一般來(lái)說(shuō)密碼為password或root)

參考




    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多