树莓派3 有线静态路由设置_clash在树莓派
生活随笔
收集整理的這篇文章主要介紹了
树莓派3 有线静态路由设置_clash在树莓派
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
clash: 上網軟件,不多做介紹
主路由:openwrt
樹莓派系統:archlinux
為什么是樹莓派?
- 主路由性能太差,開著openclash wifi就各種斷連
- 帶寬跑不滿,上樹莓派后家里帶寬能跑滿
- 配合著telegram開關主機、以后想上電智能設備,聊天控制
- 如果路由性能夠請出門左轉openwrt,openclash香的多
到此默認樹莓派已經搞定。
1、更改拓撲結構
樹莓派部分:
開啟ipv4轉發:
1、永久:不同系統可能不用,該方法 systemd 應該是通用的echo 'net.ipv4.ip_forward=1' > /etc/sysctl.d/30-ipforward.conf重啟后生效(沒找到對應的服務,暫定重啟樹莓派) 2、暫時:echo 1 > /proc/sys/net/ipv4/ip_forward立即生效靜態IP:
如果不設置靜態IP,樹莓派會將自己的網關設置成自己。需要根據自己系統修改 vim /etc/systemd/network/eth0.network[Match] Name=eth0[Network] Address=192.168.xxx.xxx/24 # 樹莓派IP地址 Gateway=192.168.xxx.xxx # 主路由器IP DNS=192.168.xxx.xxx # 主路由器IP路由器部分:
通過修改dhcp服務達成目的
openwrt為例:
網絡 -> 接口 -> 編輯局域網 -> DHCP服務器 -> 高級設置 -> DHCP選項(DHCP Option) 添加2條:
3,192.168.xxx.xxx(樹莓派IP) 6,192.168.xxx.xxx3 - 網關 6 - DNS服務器或在 /etc/config/dhcp 直接修改 ``` config dhcp 'lan'option interface 'lan'option start '100'option limit '150'option leasetime '12h'list dhcp_option '3,192.168.xxx.xxx'list dhcp_option '6,192.168.xxx.xxx' ```如果路由上沒辦法可暫時嘗試下手動設置網關和DNS服務器
手機的 wifi 選項可手動設置,電腦類似。
(網關DNS設為樹莓派IP后)此時,電腦已經可以通過樹莓派上網了
2、clash
Dreamacro/clash?github.comclash目錄:
ls -l /etc/clash/drwxr-xr-x 4 root root 4096 Oct 28 05:17 clash-dashboard #ui,作者倉庫里有 -rw-r--r-- 1 root root 446786 Oct 30 07:27 config.yaml # 配置文件 -rw-r--r-- 1 root root 3902254 Oct 27 13:59 Country.mmdb # 自動下載關閉系統自帶DNS:
不關掉無法會占用CLASH的DNS端口 archlinux 自帶兩個DNS服務,都要關掉 systemctl stop systemd-resolved systemctl disable systemd-resolved systemctl stop dnsmasq systemctl disable dnsmasq2.1 非tun版本 —— redir-host (只能代理 TCP)
配置文件設置部分:
來自openclashport: 7890 socks-port: 7891 allow-lan: true bind-address: "ipv4 地址" #默認*會綁定ipv6,bug嫌疑點 ipv6: false mode: rule log-level: debug external-controller: 0.0.0.0:9090 redir-port: 7892 secret: "123456" external-ui: "/home/alarm/yacd/public" # 控制面板文件夾路徑, IP:9090/ui 查看 hosts: ##Custom HOSTS## # experimental hosts, support wildcard (e.g. *.clash.dev Even *.foo.*.example.com) # static domain has a higher priority than wildcard domain (foo.example.com > *.example.com) # NOTE: hosts don't work with `fake-ip`# '*.clash.dev': 127.0.0.1 # 'alpha.clash.dev': '::1' ##Custom HOSTS END## dns:use-hosts: truelisten: 0.0.0.0:53#listen: 127.0.0.1:7874enable: trueipv6: falseenhanced-mode: redir-hostnameserver:- 114.114.114.114- 119.29.29.29fallback:- https://cloudflare-dns.com/dns-query- https://dns.google/dns-query- https://1.1.1.1/dns-query- tls://8.8.8.8:853fallback-filter:geoip: trueipcidr:- 0.0.0.0/8- 10.0.0.0/8- 100.64.0.0/10- 127.0.0.0/8- 169.254.0.0/16- 172.16.0.0/12- 192.0.0.0/24- 192.0.2.0/24- 192.88.99.0/24- 192.168.0.0/16- 198.18.0.0/15- 198.51.100.0/24- 203.0.113.0/24- 224.0.0.0/4- 240.0.0.0/4- 255.255.255.255/32防火墻轉發:
iptables -t nat -N CLASHiptables -t nat -A CLASH -d 10.0.0.0/8 -j RETURN iptables -t nat -A CLASH -d 127.0.0.0/8 -j RETURN iptables -t nat -A CLASH -d 169.254.0.0/16 -j RETURN iptables -t nat -A CLASH -d 172.16.0.0/12 -j RETURN iptables -t nat -A CLASH -d 192.168.0.0/16 -j RETURN iptables -t nat -A CLASH -d 224.0.0.0/4 -j RETURN iptables -t nat -A CLASH -d 240.0.0.0/4 -j RETURNiptables -t nat -A CLASH -p tcp -j REDIRECT --to-ports 7892 iptables -t nat -A PREROUTING -p tcp -j CLASH保存防火墻的配置文件 iptables-save -f /etc/iptables/iptables.rules systemctl enable iptables自啟動腳本:
cat /etc/systemd/system/clash.service ``` [Unit] Description=Clash Daemon[Service] ExecStart=/usr/local/bin/clash -d /etc/clash[Install] WantedBy=multi-user.target2.1 tun版本 —— redir-host
內核:
Release Premium 2020.10.08 · Dreamacro/clash?github.com配置文件設置部分:
在非tun的基礎上增加:experimental:interface-name: eth0 # 網卡 tun:enable: truestack: systemdns-hijack: - tcp://8.8.8.8:53防火墻:
iptables -t mangle -N CLASH iptables -t mangle -A CLASH -d 0.0.0.0/8 -j RETURN iptables -t mangle -A CLASH -d 10.0.0.0/8 -j RETURN iptables -t mangle -A CLASH -d 127.0.0.0/8 -j RETURN iptables -t mangle -A CLASH -d 169.254.0.0/16 -j RETURN iptables -t mangle -A CLASH -d 172.16.0.0/12 -j RETURN iptables -t mangle -A CLASH -d 192.168.0.0/16 -j RETURN iptables -t mangle -A CLASH -d 224.0.0.0/4 -j RETURN iptables -t mangle -A CLASH -d 240.0.0.0/4 -j RETURNiptables -t mangle -A CLASH -j MARK --set-xmark 100iptables -t mangle -A PREROUTING -j CLASH iptables -t mangle -A OUTPUT -m owner --uid-owner 0 -j RETURN iptables -t mangle -A OUTPUT -j CLASH保存防火墻的配置文件 iptables-save -f /etc/iptables/iptables.rules systemctl enable iptables自啟動:
cat /etc/systemd/system/clash.service ``` [Unit] Description=Clash Daemon[Service] ExecStart=/usr/local/bin/clash -d /etc/clash ExecStartPost=/usr/local/bin/clash_tun[Install] WantedBy=multi-user.target ```cat /usr/local/bin/clash_tun ``` #!/bin/bashclash -d /etc/clash & sleep 5 /sbin/ip route add default dev utun table 100 /sbin/ip rule add fwmark 100 lookup 100注釋:
來自:https://comzyh.gitbook.io/clash/real-ip-tun-example clash tun 啟動,下列指令完成后如果可以進行代理就算配置成功了。 因為日志等級為 debug,所以已經能看到各種連接信息了。 # 內網內部數據放過 iptables -t mangle -N CLASH iptables -t mangle -A CLASH -d 0.0.0.0/8 -j RETURN iptables -t mangle -A CLASH -d 10.0.0.0/8 -j RETURN iptables -t mangle -A CLASH -d 127.0.0.0/8 -j RETURN iptables -t mangle -A CLASH -d 169.254.0.0/16 -j RETURN iptables -t mangle -A CLASH -d 172.16.0.0/12 -j RETURN iptables -t mangle -A CLASH -d 192.168.0.0/16 -j RETURN iptables -t mangle -A CLASH -d 224.0.0.0/4 -j RETURN iptables -t mangle -A CLASH -d 240.0.0.0/4 -j RETURN # 除了放過的數據,其它數據都打上標記,標記為100 iptables -t mangle -A CLASH -j MARK --set-xmark 100 # 應用于 mangle 的 PREROUTING 項 iptables -t mangle -A PREROUTING -j CLASH # root 數據放過, 避免回環 iptables -t mangle -A OUTPUT -m owner --uid-owner 0 -j RETURN # 應用于 mangle 的 OUTPUT 項 iptables -t mangle -A OUTPUT -j CLASH # utun 添加策略路由表 ip route add default dev utun table 100 # 標記為100的包由策略路由表100處理 ip rule add fwmark 100 lookup 100bug:
本機除了root能用代理,root需要通過環境變量進行設置。
步驟需要更改,由于沒什么影響暫且擱置
總結
以上是生活随笔為你收集整理的树莓派3 有线静态路由设置_clash在树莓派的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java接口构建英雄属性_Java开发学
- 下一篇: c++求矩阵的秩_Matlab:矩阵的秩