Skip to content

Instantly share code, notes, and snippets.

@nick134920
Forked from codehz/iprule.sh
Created April 6, 2023 00:04
Show Gist options
  • Save nick134920/6c40f15c6fd9f522401e5edf2114985d to your computer and use it in GitHub Desktop.
Save nick134920/6c40f15c6fd9f522401e5edf2114985d to your computer and use it in GitHub Desktop.

Revisions

  1. @codehz codehz revised this gist Aug 16, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions iprule.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    ip rule add fwmark 0x233 lookup 100
    ip route add local 0.0.0.0/0 dev lo table 100
  2. @codehz codehz created this gist Aug 16, 2020.
    10 changes: 10 additions & 0 deletions private.nft
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    define private_list = {
    0.0.0.0/8,
    10.0.0.0/8,
    127.0.0.0/8,
    169.254.0.0/16,
    172.16.0.0/12,
    192.168.0.0/16,
    224.0.0.0/4,
    240.0.0.0/4
    }
    39 changes: 39 additions & 0 deletions proxy.nft
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    include "/etc/nftables/private.nft"

    table ip nat {
    chain proxy {
    ip daddr $private_list accept
    meta skuid clash accept
    ip protocol tcp redirect to :8889
    }

    chain output {
    type nat hook output priority filter; policy accept;
    goto proxy
    }

    chain prerouting {
    type nat hook prerouting priority dstnat; policy accept;
    goto proxy
    }
    }

    table ip mangle {
    chain filter {
    ip daddr $private_list accept
    meta skuid clash accept
    return
    }

    chain output {
    type route hook output priority mangle; policy accept;
    jump filter
    ip protocol udp mark set 0x233
    }

    chain prerouting {
    type filter hook prerouting priority mangle; policy accept;
    jump filter
    ip protocol udp tproxy to 127.0.0.1:8889
    }
    }