Skip to content

Commit

Permalink
tun: auto_route:+ sysctl -w net.ipv4.ip_forward=1
Browse files Browse the repository at this point in the history
  • Loading branch information
e1732a364fed committed Jan 1, 2099
1 parent fa5b9c3 commit bb6aa7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion resource/local.lua
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,9 @@ local config_16_tun = {

--[[
演示 inbound 是 ip+ 自动路由, outbound 是 tcp+tls+ws
演示 inbound 是 ip + 自动全局路由, outbound 是 tcp+tls+ws
这就做出了一个简单的VPN. 注意, 这种情况不可通过 tcp/udp 目标分流, 因为传递的直接是ip, 且未经任何探查和修改
同时为了保证dns 不被污染, 要在 dns_list 中指定一个 好的dns
--]]

Expand Down
2 changes: 1 addition & 1 deletion resource/remote.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Config = {
--]]

---[[
-- 对应 local.lua 使用 tun+IpRelayTest1 的 outbound 配置.
-- 对应 local.lua 使用 tun 的 outbound 配置.
-- 注意, 不像 tproxy, tun 示例不能本机自连测试

outbounds = { {
Expand Down
11 changes: 8 additions & 3 deletions src/net/tun/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ pub fn out_auto_route(params: &OutAutoRouteParams) -> anyhow::Result<()> {

let router_ip = params.router_ip.as_deref().unwrap_or(DEFAULT_ROUTER_IP);

// ip_forward is NECESSARY

let list = format!(
r#"ip route del default
r#"sysctl -w net.ipv4.ip_forward=1
ip route del default
ip route add default via {router_ip} dev {original_dev_name}
iptables -I FORWARD -i {tun_dev_name} -o {original_dev_name} -m conntrack --ctstate NEW -j ACCEPT
iptables -I FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
Expand Down Expand Up @@ -101,8 +104,10 @@ pub fn in_auto_route(params: &InAutoRouteParams) -> anyhow::Result<Option<Vec<St
// 因此该命令的成败不影响大局
let _r = utils::run_command("ip", "route del default");

let list =
format!(r#"ip route add default via {tun_gateway} dev {tun_dev_name} metric 1"#,);
let list = format!(
r#"sysctl -w net.ipv4.ip_forward=1
ip route add default via {tun_gateway} dev {tun_dev_name} metric 1"#,
);

//ip route add default via {router_ip} dev {original_dev_name} metric 10

Expand Down

0 comments on commit bb6aa7a

Please sign in to comment.