iWIN 必須被解散!

Weil Jimmer's BlogWeil Jimmer's Blog


在 OpenWrt 設定 WireGuard VPN 白名單繞過本地網路 並且維持 Kill Switch 開啟

-
發布於 2023-08-31 21:12:17

前言

這是我第四篇有關於軟路由的文章,上篇文章討論到如何設置 WireGuard VPN 介面,以及如何開啟 Kill-Switch。而這篇文章是接續上次的設定,做出延伸,在此分享心得給大家。

目標

為了讓自己的電腦所屬的區域網路 LAN 的流量只通過 WG0,而不通過 WAN,設置了防火牆規則當作 Kill-Switch,同時間啟動特定的路由表,讓 LAN 的網路 0.0.0.0/0 只走 WG0,這導致了一個問題:其他介面的流量進不來 LAN 中

以上是之前介紹過的家庭網路的示意圖。

在這種情況下,因為已經不走 WAN 了,同時間被路由表影響到,當電腦要訪問一級路由器 (也就是 192.168.0.1) 時也會被 block 掉流量,因為 192.168.0.1 是走 WG0 的,自然而然是不可能找得到目的地。從而 block 掉流量,其他地方來的也是,電腦可以收到封包,但是卻沒辦法回傳任何封包,因為沒有路由到那些地方。

為了解決這問題,必須得設定一個近網不走 VPN 的白名單規則,這樣才有機會讓 WAN 的流量到 LAN 中,或是讓 LAN2 的流量到 LAN 中。

安裝

為了解決上述情境,必須安裝一個軟體,VPN Policy-Based Routing。

opkg update
opkg install vpn-policy-routing luci-app-vpn-policy-routing

安裝完後重啟你的介面應該能在 VPN 中看到 VPN Policy-Based Routing 的 WebUI。

在這邊先設定要被 bypass 的路由規則。

這裡,我的電腦 IP 為 192.168.10.100,我設定 192.168.0.1 和 192.168.0.10 和 192.168.0.11 … 等不走 VPN 介面 (wg0)。

這裡只是路由策略,還記得上篇文章提到,我已經設定了 Kill-Switch,防火牆已經擋掉了 LAN 轉發到 WAN。所以,得到防火牆的通訊規則,新增例外。

設定允許 LAN 到 WAN (一級路由的網段下,也就是 192.168.0.0/24) 的一些位置,例如到路由器,到交換器,以及到我的手機。

到這步原則上就 OK 了,如果要到其他介面,例如 LAN2,可以參考下面的配置,不只是要設定 LAN 到 LAN2,同時間也要設定 LAN2 到 LAN,因為這是兩回事。

如果只設定一個方向的話,那就只有單向的訪問能正常運作,例如:當我設定 LAN 可轉發到 LAN2,那麼 PC 訪問 LAN2 下的設備是可以的,但反過來,LAN2 主動訪問 PC 會被拒絕。

這邊我防火牆規則並沒有設定到 192.168.0.11,所以我自然是沒辦法訪問到 192.168.0.11,即便我上面 VPN 設定 192.168.0.11 走 WAN 的路由。

因為 Kill-Switch 的關係,在防火牆規則裡面 LAN 不可以轉發到 WAN,所以沒辦法到 192.168.0.11,會被防火牆擋住(Kill-Switch)。但是可以到 192.168.0.150,因為防火牆規則中允許。

如果,我在防火牆通訊規則也加上允許轉發到 192.168.0.11 的話,那 PC 就可以成功訪問。VPN 路由策略和防火牆規則兩個都要設定,任何一者沒設定都沒辦法成功訪問。

這麼一來就可以不用關閉 wg0 也不用 關閉 kill-switch 就可以到軟路由的上層網段。

By Weil Jimmer


This entry was posted in General, Experience, The Internet, OpenWrt By Weil Jimmer.

About Weil Jimmer

avatar

Hi! Everyone! My name is Weil Jimmer. This is my personal blog. I'm a webmaster of this site. I hope the site will be popular. Now, Let's go! Enjoy gaining more knowledge.
More Details About Me : https://weils.net/profile.php

Leave a Reply

Name*:

Email*:

Website:

Privacy:   

Comment*:

Visitor Count

pop
nonenonenone

Note

支持網路中立性.
Support Net Neutrality.

飽暖思淫欲,饑寒起盜心。

支持臺灣實施無條件基本收入

歡迎前來本站。

Words Quiz


Search

Music

Blogging Journey

4259days

since our first blog post.

The strong do what they can and the weak suffer what they must.

Privacy is your right and ability to be yourself and express yourself without the fear that someone is looking over your shoulder and that you might be punished for being yourself, whatever that may be.

It is quality rather than quantity that matters.

I WANT Internet Freedom.

Reality made most of people lost their childishness.

Justice,Freedom,Knowledge.

Without music life would be a mistake.

Support/Donate

This site also need a little money to maintain operations, not entirely without any cost in the Internet. Your donations will be the best support and power of the site.
MethodBitcoin Address
bitcoin1gtuwCjjVVrNUHPGvW6nsuWGxSwygUv4x
buymeacoffee
Register in linode via invitation link and stay active for three months.Linode

Support The Zeitgeist Movement

The Zeitgeist Movement

The Lie We Live

The Lie We Live

The Questions We Never Ask

The Questions We Never Ask

Man

Man

THE EMPLOYMENT

Man

In The Fall

In The Fall

Facebook is EATING the Internet

Facebook

Categories

Android (7)

Announcement (4)

Arduino (2)

Bash (2)

C (3)

C# (5)

C++ (1)

Experience (51)

Flash (2)

Free (13)

Functions (36)

Games (13)

General (59)

Git (2)

HTML (7)

Java (13)

JS (7)

Mood (24)

NAS (2)

Note (32)

Office (1)

OpenWrt (5)

PHP (9)

Privacy (4)

Product (12)

Python (4)

Software (11)

The Internet (24)

Tools (16)

VB.NET (8)

WebHosting (7)

Wi-Fi (5)

XML (4)