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

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

羽毛の家

百樂滿回水器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