title: "树莓派无线中继为有线网络,第二局域网,DHCP服务器,支持ipv6上网"
date: 2020-07-15
tags: ["raspiberry","linux","debian"]
categories: ["raspiberry","linux","debian"]
0.环境
光猫--->主路由器--->5GWiFi--->树莓派--->交换机--->电脑
1.安装依赖
提前连接好WiFi!!!
apt-get install brctl dnsmasq radvd ndp6
2.配置DHCP与radvd以及nat转发设置
vi /etc/dnsmasq.conf
dhcp-sequential-ip
dhcp-range=10.96.181.10,10.96.181.240,255.255.255.0,12h
dhcp-range=fd00::22, fd00::44, 64, 12h
resolv-file=/etc/resolv.dnsmasq.conf
enable-ra
vi /etc/radvd.conf
interface br0
{
AdvSendAdvert on;
IgnoreIfMissing on;
prefix 2001:db8:1:0::/64
{
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
};
};
vi /etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.all.proxy_ndp=1
vi /etc/npd6.conf
prefix=2001:db8:1:0::
interface = wlan0
ralogging = off
listtype = none
listlogging = off
collectTargets = 100
linkOption = false
ignoreLocal = true
routerNA = true
maxHops = 255
pollErrorLimit = 20
3.建立网桥,配置ipv6穿透
#!/bin/sh
brctl addbr br0
brctl addif br0 eth0
brctl stp br0 yes
ifconfig br0 10.96.181.1 netmask 255.255.255.0 up
ifconfig eth0 0.0.0.0 up
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
ifconfig br0 inet6 add 2001:db8:1:0:33fa:24b1/64 #网桥ipv6地址
ip6tables -t nat -A POSTROUTING -s 2001:db8:1:0::/64 -j MASQUERADE #内网IPV6前缀,与/etc/radvd.conf一致
ip -6 route add 2000::/3 via fe80::6609:80ff:fe71:a3f4 dev wlan0 #广域网IPV6网关
ifconfig eth0 0.0.0.0 up
注意设置广域网ipv6网关
注意eth0不要设置ip否则无法上网
4.检查服务并重启
service dnsmasq start
service radvd start
service npd6 start
将第三步设置开机自动执行即可
本文所有参考
https://blog.csdn.net/pengluer/article/details/6222749
https://blog.csdn.net/xrfsycg/article/details/8663018?utm_source=blogxgwz3
https://my.oschina.net/u/2306127/blog/813483
https://blog.csdn.net/wr132/article/details/78986190
https://blog.cyyself.name/2018/09/raspberry-pi-as-wifi-router/
https://www.cnblogs.com/kekeoutlook/p/11123062.html
Q.E.D.