Coder Social home page Coder Social logo

padavan-wireguard-client's Introduction

English | Русский

WireGuard client for routers with Padavan based firmware

Single executable file only requiring standard WireGuard config file to work.

Prerequisites

  1. Firmware with WireGuard support.
    E.g. padavan-ng from Alexey, on your router up and running.

  2. Ability to run commands on your router.
    Preferably via SSH, but you could also use router web UI.

    More info

    Enable SSH access in router's web UI: AdministrationServicesEnable SSH Server?Yes

    SSH connection credentials are the same that you use for web UI.

    Linux, Mac OS and Windows 10+ usually have SSH client preinstalled, just launch terminal and connect:

    On older Windows versions you could use PuTTY, Tabby or other SSH clients.

    When you have SSH client installed, you can often connect just by following this link:

    Paste it into your browser's address bar manually and hit Enter, since GitHub doees not allow active links with non-standard protocols.

  3. Ability to copy files to your router.
    SFTP is usually used for this, which is based on SSH.

    More info

    On Windows you could use WinSCP, for Mac OS there is Cyberduck. Linux file managers usually support SFTP out of the box, look for "Network" or "Other places" section.

    You can connect just by following this link:

    sftp://[email protected]/etc/storage/
    

    Paste it into your browser's address bar manually and hit Enter, since GitHub doees not allow active links with non-standard protocols.

WireGuard client set up

I will mostly use CLI commands here to remove risk of misinterpretation, but file / directory operations might be as well performed via SFTP, or course.

  1. If you have previous version of this WireGuard client installed (the one that consisted of several .sh files), you need to disable / remove it. Let's rename its directory for now without deleting anything:

    mv /etc/storage/wireguard /etc/storage/wireguard.bak
  2. Create wireguard directory in /etc/storage:

    mkdir /etc/storage/wireguard
  3. Copy client.sh to it:

    wget https://github.com/shvchk/padavan-wireguard-client/raw/main/client.sh -O /etc/storage/wireguard/client.sh

    [!WARNING]
    I recommend inspecting the client.sh script before running it. It's a good practice before running any code on your device, especially remote code.

  4. Make it executable:

    chmod +x /etc/storage/wireguard/client.sh
  5. Copy WireGuard client config file to /etc/storage/wireguard

    Config file name will be used as a WireGuard interface name. E.g. for wg0.conf client create wg0 interface.

    [!IMPORTANT]
    File name should only consist of letters, numbers and _ = + . - characters, be less than 16 characters long and end with .conf. If directory has multiple config files, first one in alphabetic order will be used.

  6. Start WireGuard client:

    /etc/storage/wireguard/client.sh start
  7. Check if internet is working fine on your devices:

    ping -c 3 -W 1 1.1.1.1
  8. In case of problems, stop WireGuard client:

    /etc/storage/wireguard/client.sh stop
  9. After you made sure everything is working fine, enable autostart:

    /etc/storage/wireguard/client.sh autostart enable
  10. Save changes:

    mtd_storage.sh save
  11. Restart router

Uninstall

/etc/storage/wireguard/client.sh stop
/etc/storage/wireguard/client.sh autostart disable
rm -rf /etc/storage/wireguard
mtd_storage.sh save

Add exceptions

You can add exceptions in one of these files:

  • /etc/storage/started_script.sh (web UI: CustomizationScriptsRun After Router Started)

  • /etc/storage/post_iptables_script.sh (web UI: CustomizationScriptsRun After Firewall Rules Restarted)

First add a tiny helper function:

direct() {
  ip rule del $1 $2 || :
  ip rule add $1 $2 table main pref 30
}

You can then use it like this: direct <to|from> <IP-address|subnet>. Examples:

  • Route traffic to IP 9.9.9.9 directly: direct to 9.9.9.9

  • Route traffic to subnet 1.2.0.0/16 directly: direct to 1.2.0.0/16

  • Route traffic from IP 192.168.1.11 directly: direct from 192.168.1.11

  • Route traffic from subnet 10.11.12.0/24 directly: direct to 10.11.12.0/24

You can add as many of these rules as you like, one per line.

If you changed files via SSH, don't forget to save changes:

mtd_storage.sh save

padavan-wireguard-client's People

Contributors

shvchk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

padavan-wireguard-client's Issues

Трафик в обход wireguard

Здравствуйте, сейчас весь трафик заворачивается в wireguard, подскажите правила в добавок к текущим чтобы пробросить IP одного клиента обход wireguard?

Ошибка в dev версии

Если запустит и остановить скрипт, то появляются следующие ошибки во время запуска:
/etc/storage/wireguard # /etc/storage/wireguard/client.sh start
RTNETLINK answers: No such process
RTNETLINK answers: No such file or directory
RTNETLINK answers: No such file or directory
iptables: Bad rule (does a matching rule exist in that chain?).
iptables: No chain/target/match by that name.
iptables: No chain/target/match by that name.
/etc/storage/wireguard # /etc/storage/wireguard/client.sh stop
RTNETLINK answers: No such file or directory
/etc/storage/wireguard #

Подключается. Интернета нет.

Добрый день.
Запускаю скрипт, все подымается, ошибок как-бы нет, но на клиентах интернета нет.
Грешил на маршруты, но - с роутера ничего не пингуется наружу, кроме IP wireguard сервера внешний. Внутренний (10.66.66.1) не пингуется почему-то.
Может подскажите что не так, куда копать?

/ # /etc/storage/wireguard/client.sh start
Internet connection established
Setting up WireGuard interface... done
Removing WireGuard traffic rules... done
Setting up WireGuard traffic rules... done
/ # ping -c3 1.1.1.1
PING 1.1.1.1 (1.1.1.1): 56 data bytes
--- 1.1.1.1 ping statistics ---
3 packets transmitted, 0 packets received, 100% packet loss
/ # ip route show table all
default dev wg0  table 51  scope link 
default via 10.0.0.1 dev eth3  metric 1 
10.0.0.0/16 dev eth3  proto kernel  scope link  src 10.0.18.94 
127.0.0.0/8 dev lo  scope link 
192.168.1.0/24 dev br0  proto kernel  scope link  src 192.168.1.1 
broadcast 10.0.0.0 dev eth3  table local  proto kernel  scope link  src 10.0.18.94 
local 10.0.18.94 dev eth3  table local  proto kernel  scope host  src 10.0.18.94 
broadcast 10.0.255.255 dev eth3  table local  proto kernel  scope link  src 10.0.18.94 
local 10.66.66.9 dev wg0  table local  proto kernel  scope host  src 10.66.66.9 
broadcast 127.0.0.0 dev lo  table local  proto kernel  scope link  src 127.0.0.1 
local 127.0.0.0/8 dev lo  table local  proto kernel  scope host  src 127.0.0.1 
local 127.0.0.1 dev lo  table local  proto kernel  scope host  src 127.0.0.1 
broadcast 127.255.255.255 dev lo  table local  proto kernel  scope link  src 127.0.0.1 
broadcast 192.168.1.0 dev br0  table local  proto kernel  scope link  src 192.168.1.1 
local 192.168.1.1 dev br0  table local  proto kernel  scope host  src 192.168.1.1 
broadcast 192.168.1.255 dev br0  table local  proto kernel  scope link  src 192.168.1.1 
unreachable default dev lo  table 0  proto kernel  metric 4294967295  error -128
unreachable default dev lo  table 0  proto kernel  metric 4294967295  error -128
/ # ip rule
0:	from all lookup local 
30:	from all to 13.49.240.77 lookup main 
30:	from all to 192.168.1.1/24 lookup main 
30:	from all to 10.0.18.94/16 lookup main 
40:	from all lookup 51 
32766:	from all lookup main 
32767:	from all lookup default 
wg0       Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.66.66.9  P-t-P:10.66.66.9  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP  MTU:1420  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:44 errors:0 dropped:2648 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:6512 (6.3 KiB)
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
SNAT       all  --  anywhere             anywhere             to:10.66.66.9

Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  wg0    *       0.0.0.0/0            0.0.0.0/0           
11409 1309K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
 6797  593K ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0           
   43  3050 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            state INVALID
   31 10228 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp spt:67 dpt:68
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmp !type 8

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  317 29561 ACCEPT     all  --  br0    br0     0.0.0.0/0            0.0.0.0/0           
 4721  295K TCPMSS     tcp  --  *      !br0    0.0.0.0/0            0.0.0.0/0            tcp flags:0x06/0x02 TCPMSS clamp to PMTU
39576   11M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
   30  4895 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            state INVALID
13839 1260K ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0           
   24  1344 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate DNAT

No internet connection, waiting...

Здравствуйте, у меня возникает проблема в самом начале работы скрипта client.sh - я получаю "No internet connection, waiting..." - при этом, если я делаю ping, как в скрипте "ping -c 1 -W 1 1.1.1.1" - пинг проходит и интернет на роутере и на устройствах есть. Помогите пожалуйста разобраться, в чём причины?

Error: ??? prefix is expected

Привет. После запуска скрипта в терминале роутера:

/etc/storage/wireguard/client.sh start
Internet connection established
Setting up WireGuard interface... done
Removing WireGuard traffic rules... done
Setting up WireGuard traffic rules... Error: ??? prefix is expected rather than "engage.cloudflareclient.com".
Device "eth3" does not exist.
done

Может у меня конфиг не правильный? Сгенерировал на компьютере с помощью wgcf, потом подставил значения в conf.sh:

ADDR="172.16.0.2" # Client (our) address in WireGuard network
MASK="32" # WireGuard network mask
PRIVATE_KEY="blablabla" # Client (our) private key

ENDPOINT_ADDR="engage.cloudflareclient.com" # WireGuard server address
ENDPOINT_PORT="2408" # WireGuard server port
ENDPOINT_PUBLIC_KEY="blablabla" # WireGuard server public key
ENDPOINT_ALLOWED_IP="0.0.0.0/0"

IFACE="wg0"

CFG="/tmp/wireguard_${IFACE}.conf"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.