惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

羽毛の家

百樂滿回水器PH-2568EFF添加到HASS – 羽毛の家 百樂滿回水器PH-2568EFF添加到HASS – 羽毛の家 EC20模塊獲取設置IMEI – 羽毛の家 EC20模塊獲取設置IMEI – 羽毛の家 OpenWRT PPPoE重連之後無網絡的解決 – 羽毛の家 OpenWRT PPPoE重連之後無網絡的解決 – 羽毛の家 Ubuntu Use An Entire Disk And Set Up LVM 空間沒使用全的解決方案 – 羽毛の家 Ubuntu Use An Entire Disk And Set Up LVM 空間沒使用全的解決方案 – 羽毛の家 OpenWRT部署SpeedTest-X供測速使用 – 羽毛の家 OpenWRT部署SpeedTest-X供測速使用 – 羽毛の家 微信開發者工具小程序真機調試提示房間已在調試中 – 羽毛の家 微信開發者工具小程序真機調試提示房間已在調試中 – 羽毛の家 OpenWRT下使用藍牙共享網絡 – 羽毛の家 OpenWRT下使用藍牙共享網絡 – 羽毛の家 移遠RM500Q-GL在NSA組網下鎖5G – 羽毛の家 移遠RM500Q-GL在NSA組網下鎖5G – 羽毛の家 OpenWRT多網關情況下MiniUpnpd添加映射失敗501 – 羽毛の家 OpenWRT多網關情況下MiniUpnpd添加映射失敗501 – 羽毛の家 OpenWRT多WAN情況下 數據包哪裏進哪裏出 – 羽毛の家
OpenWRT多WAN情況下 數據包哪裏進哪裏出 – 羽毛の家
yumao · 2020-05-15 · via 羽毛の家

Welcome to Yumao′s Blog.

OpenWRT多WAN情況下 數據包哪裏進哪裏出

, 2020年05月15日 , Linux , 评论 在〈OpenWRT多WAN情況下 數據包哪裏進哪裏出〉中留言功能已關閉 ,

使用單路由多WAN的OpenWRT設備的時候
會發現默認出局會走躍點最低的闸道器
例如有電信 移動雙PPPOE的情況下
電信躍點20 移動躍點50
在外部訪問路由服務的時候會發現

訪問電信IP的時候業務正常
訪問移動IP的時候會發現無包返回
抓包的時候發現數據包會從電信直接出去了
因爲默認路由走的是電信
那麽就嘗試使用打標的方式做到哪裏進哪裏出策略路由方案

本操作基于iptables ipset實現
在INPUT鏈采集對應網口的入局src然後設置到ipset的hash表
然後在OUTPUT鏈中判斷dst從而進行打標
最後策略路由中基于打標走對應路由

1.網口自動設置路由表

#電信
>vi /etc/ppp/ip-up.d/ctc
#!/bin/sh
ip route flush table 220
ip route add default dev pppoe-wan table 220
ip rule add fwmark 220 table 220
exit 0
#移動
>vi /etc/ppp/ip-up.d/cmcc
#!/bin/sh
ip route flush table 250
ip route add default dev pppoe-wan2 table 250
ip rule add fwmark 250 table 250
exit 0

2.分流腳本

>vi /root/swan.sh
#!/bin/sh
#預留網段
ipset -! -R <<-EOF || return 1
    create LOCAL_RULES hash:net hashsize 64 maxelem 25
    add LOCAL_RULES 0.0.0.0/8
    add LOCAL_RULES 10.0.0.0/8
    add LOCAL_RULES 100.64.0.0/10
    add LOCAL_RULES 127.0.0.0/8
    add LOCAL_RULES 169.254.0.0/16
    add LOCAL_RULES 172.16.0.0/12
    add LOCAL_RULES 192.0.0.0/24
    add LOCAL_RULES 192.0.2.0/24
    add LOCAL_RULES 192.31.196.0/24
    add LOCAL_RULES 192.52.193.0/24
    add LOCAL_RULES 192.88.99.0/24
    add LOCAL_RULES 192.168.0.0/16
    add LOCAL_RULES 192.175.48.0/24
    add LOCAL_RULES 198.18.0.0/15
    add LOCAL_RULES 198.51.100.0/24
    add LOCAL_RULES 203.0.113.0/24
    add LOCAL_RULES 224.0.0.0/4
    add LOCAL_RULES 240.0.0.0/4
    add LOCAL_RULES 255.255.255.255
EOF
#初始化HASH表
ipset destroy CTC_SRC
ipset create CTC_SRC hash:ip hashsize 64 maxelem 655350
ipset destroy CMCC_SRC
ipset create CMCC_SRC hash:ip hashsize 64 maxelem 655350
#進行日志輸出
uci set system.@system[0].log_file='/var/log/syslog'
uci set system.@system[0].log_remote='0'
uci commit
/etc/init.d/log reload
iptables -t mangle -N SWANLOG
iptables -t mangle -A SWANLOG -i pppoe-wan -m set --match-set CTC_SRC src -j RETURN
iptables -t mangle -A SWANLOG -i pppoe-wan -j LOG --log-prefix="CTC "
iptables -t mangle -A SWANLOG -i pppoe-wan2 -m set --match-set CMCC_SRC src -j RETURN
iptables -t mangle -A SWANLOG -i pppoe-wan2 -j LOG --log-prefix="CMCC "
iptables -t mangle -I INPUT -j SWANLOG
#根據日志進行HASH表設置
nohup tail -fn0 /var/log/syslog |grep "CTC " |grep -E -o "SRC=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"| awk -F '=' '{system("ipset add CTC_SRC "$2)}{system("ipset del CMCC_SRC "$2)}' > /dev/null 2>&1 &
nohup tail -fn0 /var/log/syslog |grep "CMCC " |grep -E -o "SRC=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"| awk -F '=' '{system("ipset add CMCC_SRC "$2)}{system("ipset del CTC_SRC "$2)}' > /dev/null 2>&1 &
#根據HASH表對出局數據表打標
iptables -t mangle -N SWANMARK
iptables -t mangle -A SWANMARK -m set --match-set LOCAL_RULES dst -j RETURN
iptables -t mangle -A SWANMARK -m set --match-set CTC_SRC dst -j MARK --set-mark 220
iptables -t mangle -A SWANMARK -m set --match-set CMCC_SRC dst -j MARK --set-mark 250
#對路由本設備進行出局打標
iptables -t mangle -I OUTPUT -j SWANMARK
#對路由子設備進行路由打標
#iptables -t mangle -I PREROUTING -j SWANMARK