海运的博客

n1盒子连接手机4G无线热点做k2p宽带pppoe备份线路并切换

发布时间:February 24, 2021 // 分类:N1,K2P // No Comments

k2p主路由地址:192.168.1.1
n1盒子地址:192.168.1.2
k2p添加低优先级默认路由走n1,此路由只有pppoe断开后才有效:

ip rou add default via 192.168.1.2 dev br-lan metric 1000

n1盒子用netplan配置无线网络默认路由和无线热点的路由优先级,默认情况下走k2p主路由,当路由器pppoe不能连接时打开手机无线热点则自动走手机4g网络连接。

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            addresses:
            - 192.168.1.2/24
            dhcp4: false
            dhcp6: true
            accept-ra: true
            #gateway4: 192.168.1.1
            routes:
                - to: 0.0.0.0/0
                  via: 192.168.1.1
                  metric: 1000
            nameservers:
                addresses:
                - 192.168.1.1
                search: []

    wifis:
      wlan0:
        #防止开机时wlan0未连接导致systemd-networkd-wait-online阻塞系统启动
        optional: true
        dhcp4: yes
        dhcp6: no
        dhcp4-overrides:
            route-metric: 600
        access-points:
            "Phone-ssid":
                password: "www.haiyun.me"

n1盒子开启snat及网络转发:

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sysctl -w net.ipv4.ip_forward=1

潘多拉/OpenWRT配置无线wifi访客网络

发布时间:March 18, 2019 // 分类:K2P // No Comments

配置一个无线接口,device名称见同配置文件:

config wifi-iface 'guest'
        option device 'ra'
        option mode 'ap'
        option ssid 'PandoraBox-2.4G-Guest'
        option network 'guest'
        option rssikick '0'
        option rssiassoc '0'
        option encryption 'psk2'
        option key 'password'
        option isolate '1'

给创建的无线接口配置静态IP:

config interface 'guest'
       option proto 'static'
       option ipaddr '10.0.0.1'
       option netmask '255.255.255.0'

配置dhcp:

config dnsmasq
        #监听所有网卡
        option nonwildcard '0'
        #监听特定网卡
        #option nonwildcard '1'
        #list interface 'lan'    
        #list interface 'guest'  
        #略过

config dhcp 'guest'
        option interface 'guest'
        option start '100'
        option limit '150'
        option leasetime '1h'

配置iptables防火墙,访客网络接口为ra1:

iptables -A INPUT -i ra1 -p udp -m multiport --dport 53,67:68 -j ACCEPT
iptables -A FORWARD -i ra1 -o pppoe-wan -j ACCEPT

同时开放5G和2.4G访客网络:

config wifi-iface 'guest'
        option device 'ra'
        option mode 'ap'
        option ssid 'PandoraBox-2.4G-Guest'
        option network 'guest'
        option rssikick '0'
        option rssiassoc '0'
        option encryption 'psk2'
        option key 'password'
        option isolate '1'

config wifi-iface 'guest5'
        option device 'rax'
        option mode 'ap'
        option ssid 'PandoraBox-5G-Guest'
        option network 'guest'
        option rssikick '0'
        option rssiassoc '0'
        option encryption 'psk2'
        option key 'password'
        option isolate '1'

将2.4G和5G桥接:

config interface 'guest'
        option proto 'static'
        option ipaddr '10.0.0.1'
        option netmask '255.255.255.0'
        option type 'bridge'
        option _orig_ifname 'ra1 rax1'
        option _orig_bridge 'true'
        option ifname 'rax1'
iptables -A INPUT -i br-guest -p udp -m multiport --dport 53,67:68 -j ACCEPT
iptables -A FORWARD -i br-guest -o pppoe-wan -j ACCEPT

更改guest无线密码:

#!/bin/sh
str=haiyun`date +%s|cut -c 7-10|sed 's/4/6/g'`
echo $str
uci set wireless.guest.key=$str
uci set wireless.guest5.key=$str
uci commit wireless
wifi reload

参考:
https://openwrt.org/docs/guide-user/network/wifi/guestwifi/guest-wlan

ImageBuilder制作k2p潘多拉/PandoraBox固件

发布时间:November 2, 2018 // 分类:K2P // 8 Comments

基于ubuntu 18.04,安装依赖:

apt install build-essential libncurses5-dev zlib1g-dev gawk git  libssl-dev wget unzip python ocaml-nox help2man texinfo yui-compressor

下载最新版本18.10的ImageBuilder:

https://downloads.pangubox.com/pandorabox/18.10/targets/ralink/mt7621/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64.tar.xz
tar Jxf PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64.tar.xz
cd PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64

查看可编译的固件型号及其包含的软件包:

make info

制作固件:

#info显示的所有机型固件
make image
#仅制作k2p固件
make image PROFILE="k2p"
#安装额外的软件包,自编译软件先把软件放到packages/目录下
make image PROFILE="k2p" PACKAGES="wget"
#添加files目录内文件到固件内,如files/etc/config/network网络配置文件
make image PROFILE="k2p" FILES="files"
#查看更多选项
make help

默认的软件包在以下两个文件内:

include/target.mk
.profiles.mk 

开始使用默认配置制作k2p固件:

make image PROFILE="k2p"

遇到以下错误:

 regexp could be something like 'pkgname*' '*file*' or similar
 e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'
Makefile:140: recipe for target 'package_install' failed
make[2]: *** [package_install] Error 1
make[2]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:110: recipe for target '_call_image' failed
make[1]: *** [_call_image] Error 2
make[1]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:196: recipe for target 'image' failed
make: *** [image] Error 2

因为在Makerfile 144行要预先安装kernel文件,而package没kernel软件包,下载kernel:

wget https://downloads.pangubox.com/pandorabox/18.10/targets/ralink/mt7621/packages/kernel_3.14.79-1_mipsel_1004kc_dsp.ipk -P packages/

再次执行又出现错误:

Collected errors:
 * opkg_install_cmd: Cannot install package dosfsck.
 * opkg_install_cmd: Cannot install package fkmod-leds-gpio.
 * opkg_install_cmd: Cannot install package kmod-ipt-nathelper.
 * opkg_install_cmd: Cannot install package mkdosfs.
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for ralink-utils:
 *      kmod-ipt-nathelper-extra * 
Makefile:140: recipe for target 'package_install' failed
make[2]: *** [package_install] Error 255
make[2]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:110: recipe for target '_call_image' failed
make[1]: *** [_call_image] Error 2
make[1]: Leaving directory '/tmp/PandoraBox-ImageBuilder-ralink-mt7621.Linux-x86_64'
Makefile:196: recipe for target 'image' failed
make: *** [image] Error 2

因为新版的openwrt将kmod-ipt-nathelper-extra 更改为kmod-nf-nathelper-extra,而潘多拉的源package没修改依赖,使用以下脚本在制作时更新源后修改软件依赖项kmod-ipt-nathelper-extra为kmod-nf-nathelper-extra:

#!/bin/bash
for file in `ls dl/18.10*`;do 
        echo $file;
        mv $file $file.gz
        gunzip $file.gz
        sed -i 's/kmod-ipt-nathelper-extra/kmod-nf-nathelper-extra/g' $file
        gzip -9 $file
        mv $file.gz $file
done
sed -i 's/kmod-ipt-nathelper/kmod-nf-nathelper/g' include/target.mk 

将以上保存为fix.sh到image build目录加可执行权限,并修改Makefile文件在122行$(MAKE) package_install前插入:

$(TOPDIR)/fix.sh

再次执行又遇到以下错误:

Collected errors:
 * opkg_install_cmd: Cannot install package dosfsck.
 * opkg_install_cmd: Cannot install package fkmod-leds-gpio.
 * opkg_install_cmd: Cannot install package mkdosfs.

因为上面这3个软件有的改名,有的名字写错,修复下:

sed -i 's/fkmod-leds-gpio/kmod-leds-gpio/g' .profiles.mk
sed -i 's/mkdosfs dosfsck/dosfstools/g' .profiles.mk
````
再次执行终于制作完成k2p固件,将制作的固件scp到路由/tmp/目录开始刷机:

scp bin/targets/ralink/mt7621/PandoraBox-ralink-mt7621-k2p-2018-10-26-git-85c67caa2-squashfs-sysupgrade.bin 192.168.168.1:/tmp/

k2p路由内使用[sysupgrade命令刷机][1]:

sysupgrade -n -v /tmp/PandoraBox-ralink-mt7621-k2p-2018-10-26-git-85c67caa2-squashfs-sysupgrade.bin

k2p下潘多拉/openwrt配置ipv6地址

发布时间:October 27, 2018 // 分类:K2P // 1 Comment

我这宽带分配ipv6使用dhcpv6-pd方式,潘多拉默认配置ipv6就能正常使用,由于使用虚拟机和未使用自带的firewall走了一些坑,顺便将openwrt的ipv6分配了解了下。
wan6接口的dhcpv6客户端获取ipv6公网前缀:
2018-10-27_110916.png

路由获取IPV6前缀后向局域网内机器分发址使用RA路由通告和dhcpv6方式:
支持IPV6的主机会主动发路由器询问报文,然后路由器RA返回是否使用DHCPV6分配或用IP前缀、网关,机器根据MAC生成IPV6地址,最新的RA协议支持RDNSS可配置DNS,Windows 10最新系统才支持。

dhcpv6支持有状态和无状态,有状态类似于DHCPV4,无状态使用RA通告配置IP,DHCPV6配置DNS、NTP等扩展配置信息,据说android系统不支持dhcpv6。

有公网前缀的不要单独使用有状态的,不然pppoe重新报号前缀改变内网机器前缀不改。
有状态的+无状态的,使用dhcpv6有状态分配地址,同时如果有公网前缀也使用无状态分配,无前缀只使用DHCPV6有状态分配。

RA和DHCPV6模式有:服务器模式、中继模式、混合模式,前缀分配使用服务器模式,如果运营商不支持dhcpv6-pd可使用中继方式,中继模式要将wan6的dhcp客户端设置成master,lan的dhcp相当于slave。
混合模式会根据配置自动选择使用中继还是服务器模式。
If the interface was master, then hybrid means relay or disabled. If there was no slave relay in the other interfaces, then it will be configured to disabled.

If the interface was not master, then hybrid means relay or server. If there was no master, then the interface will be configured to server.

默认lan接口的dhcpv6服务器配置:
2018-10-27_111135.png
通告的DNS地址就是RDNSS,填写此项客户端可通过RA通告配置DNS地址,如果客户端支持RDNSS关闭DHCPV6服务也能正常使用了。

总结分配IP方式使用RA+DHCPV6无状态或RA+RDNSS不用DHCPV6就可以了。
配置iptables:

ip6tables -F
ip6tables -X
ip6tables -Z
ip6tables -P INPUT   DROP
ip6tables -P OUTPUT  ACCEPT
ip6tables -P FORWARD DROP

ip6tables -A INPUT -i lo -j ACCEPT
ip6tables -A INPUT -i br-lan -j ACCEPT
#路由通告使用icmpv6协议,类型133-137
ip6tables -A INPUT -p icmpv6 -j ACCEPT
#这个一定要允许,不然获取不到公网ipv6前缀
ip6tables -A INPUT -m conntrack --ctstate NEW -m udp -p udp --sport 547 --dport 546 -s fe80::/64 -d fe80::/64 -j ACCEPT
#ip6tables -A INPUT -s fe80::/10 -d fe80::/10 -p udp -m udp --sport 547 --dport 546 -j ACCEPT
#ip6tables -A INPUT -p icmpv6 --icmpv6-type echo-request -j ACCEPT
ip6tables -A INPUT -i pppoe-wan -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
ip6tables -A FORWARD -i br-lan -o pppoe-wan  -j ACCEPT
ip6tables -A FORWARD -i br-lan -o br-lan  -j ACCEPT
ip6tables -A FORWARD -i pppoe-wan -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

ip6tables -t mangle -F
ip6tables -t mangle -X
ip6tables -t mangle -Z
ip6tables -t mangle -A POSTROUTING -o pppoe-wan -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu 

参考:
https://community.arubanetworks.com/t5/Controller-Based-WLANs/Explain-the-M-and-O-bit-in-IPv6-DHCP-server-configuration-What/ta-p/177442
https://github.com/gnu4cn/ccna60d/blob/master/d07-IPv6.md
https://www.v2ex.com/t/486379
http://www.right.com.cn/forum/thread-338106-1-1.html
https://qiita.com/kwi/items/c002cd3c466504c96391
https://i-meto.com/lede-ipv6/
https://openwrt.org/docs/techref/odhcpd

此内容被密码保护

发布时间:March 22, 2018 // 分类:K2P // No Comments

请输入密码访问

分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...