mirror of
https://github.com/garywill/linux-router.git
synced 2025-12-30 02:38:28 +01:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
718a1752f1 | ||
|
|
5dcfacc418 | ||
|
|
0c85f00297 | ||
|
|
a2fcbc4781 | ||
|
|
63cd88b5fc | ||
|
|
957ed25f07 | ||
|
|
183cf44934 | ||
|
|
4e92b3ebf5 | ||
|
|
992ad00ca1 | ||
|
|
9d874dbe88 | ||
|
|
b94cf7c43f | ||
|
|
0acb16dbaa | ||
|
|
73441c4ed3 | ||
|
|
8527e1a9b6 | ||
|
|
18a57119b9 | ||
|
|
7f1ae6282e | ||
|
|
4515dde9b4 | ||
|
|
45ad35d29f | ||
|
|
a663d9052b | ||
|
|
e3941c560f | ||
|
|
7ec589b1c2 | ||
|
|
10ca7249cb | ||
|
|
a414ac035b | ||
|
|
b51a2d2349 | ||
|
|
9e1d985623 | ||
|
|
433b3b8d39 | ||
|
|
e8284c5398 | ||
|
|
c2da43250e |
133
README.md
133
README.md
@@ -6,6 +6,7 @@ It wraps `iptables`, `dnsmasq` etc. stuff. Use in one command, restore in one co
|
|||||||
|
|
||||||
[Linux-Router News & Developer Notes 📰](https://github.com/garywill/linux-router/issues/28) | [More tools and projects 🛠️](https://garywill.github.io) | [🍻 Buy me a coffee ❤️](https://github.com/garywill/receiving/blob/master/receiving_methods.md)
|
[Linux-Router News & Developer Notes 📰](https://github.com/garywill/linux-router/issues/28) | [More tools and projects 🛠️](https://garywill.github.io) | [🍻 Buy me a coffee ❤️](https://github.com/garywill/receiving/blob/master/receiving_methods.md)
|
||||||
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
Basic features:
|
Basic features:
|
||||||
@@ -61,6 +62,31 @@ Internet----(eth0/wlan0)-Linux-(eth1)------Another PC
|
|||||||
Internet----(eth0/wlan0)-Linux-(virtual interface)-----VM/container
|
Internet----(eth0/wlan0)-Linux-(virtual interface)-----VM/container
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
1-file-script. Release on [Linux-router repo on Github](https://github.com/garywill/linux-router). Just download and run the bash script (meet the dependencies). In this case use without installation.
|
||||||
|
|
||||||
|
> I'm currently not packaging for any distro. If you do, open a PR and add the link (can be with a version badge) to list here
|
||||||
|
|
||||||
|
| Linux distro | |
|
||||||
|
| ------------ | ---------------------------------------------------------------------------------------------------------- |
|
||||||
|
| Any | download [1-file-script](https://raw.githubusercontent.com/garywill/linux-router/master/lnxrouter) and run without installation |
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
- bash
|
||||||
|
- procps or procps-ng
|
||||||
|
- iproute2
|
||||||
|
- dnsmasq
|
||||||
|
- iptables (or nftables with `iptables-nft` translation linked)
|
||||||
|
- WiFi hotspot dependencies
|
||||||
|
- hostapd
|
||||||
|
- iw
|
||||||
|
- iwconfig (you only need this if 'iw' can not recognize your adapter)
|
||||||
|
- haveged (optional)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Provide Internet to an interface
|
### Provide Internet to an interface
|
||||||
@@ -92,13 +118,13 @@ sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [26
|
|||||||
> In this case of usage, it's recommended to:
|
> In this case of usage, it's recommended to:
|
||||||
>
|
>
|
||||||
> 1. Stop serving local DNS
|
> 1. Stop serving local DNS
|
||||||
> 2. Tell clients which DNS to use (ISP5's DNS. Or, a safe public DNS, like above example)
|
> 2. Tell clients which DNS to use ISP5's DNS. (Or, a safe public DNS, like above example)
|
||||||
|
|
||||||
> Also, read *Notice 1*
|
> Also, read *Notice 1*
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### LAN without Internet
|
### Create LAN without providing Internet
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
@@ -138,7 +164,7 @@ sudo lnxrouter -i lxcbr5
|
|||||||
|
|
||||||
### Transparent proxy
|
### Transparent proxy
|
||||||
|
|
||||||
All clients' Internet traffic go through, for example, Tor
|
All clients' Internet traffic go through, for example, Tor (notice this example is NOT an anonymity use)
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
|
|
||||||
@@ -155,6 +181,10 @@ TransPort [fd00:5:6:7::1]:9040
|
|||||||
DNSPort [fd00:5:6:7::1]:9053
|
DNSPort [fd00:5:6:7::1]:9053
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> **Warn**: Tor's anonymity relies on a purpose-made browser. Using Tor like this (sharing Tor's network to LAN clients) will NOT ensure anonymity.
|
||||||
|
>
|
||||||
|
> Although we use Tor as example here, Linux-router does NOT ensure nor is NOT aiming at anonymity.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
### Clients-in-sandbox network
|
### Clients-in-sandbox network
|
||||||
@@ -173,7 +203,7 @@ sudo lnxrouter -i eth1 \
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
> This script comes with no warrenty. Use on your own risk
|
> Linux-router comes with no warranty. Use on your own risk
|
||||||
|
|
||||||
### Use as transparent proxy for LXD
|
### Use as transparent proxy for LXD
|
||||||
|
|
||||||
@@ -317,26 +347,28 @@ Options:
|
|||||||
-d DNS server will take into account /etc/hosts
|
-d DNS server will take into account /etc/hosts
|
||||||
-e <hosts_file> DNS server will take into account additional
|
-e <hosts_file> DNS server will take into account additional
|
||||||
hosts file
|
hosts file
|
||||||
|
--dns-nocache DNS server no cache
|
||||||
|
|
||||||
--mac <MAC> Set MAC address
|
--mac <MAC> Set MAC address
|
||||||
--random-mac Use random MAC address
|
--random-mac Use random MAC address
|
||||||
|
|
||||||
--tp <port> Transparent proxy,
|
--tp <port> Transparent proxy,
|
||||||
redirect non-LAN TCP and UDP traffic to port.
|
redirect non-LAN TCP and UDP(not tested) traffic to
|
||||||
(usually used with '--dns')
|
port. (usually used with '--dns')
|
||||||
|
|
||||||
WiFi hotspot options:
|
WiFi hotspot options:
|
||||||
--ap <wifi interface> <SSID>
|
--ap <wifi interface> <SSID>
|
||||||
Create WiFi access point
|
Create WiFi access point
|
||||||
-p, --password <password>
|
-p, --password <password>
|
||||||
WiFi password
|
WiFi password
|
||||||
--qr Show WiFi QR code in terminal
|
--qr Show WiFi QR code in terminal (need qrencode)
|
||||||
|
|
||||||
--hidden Hide access point (not broadcast SSID)
|
--hidden Hide access point (not broadcast SSID)
|
||||||
--no-virt Do not create virtual interface
|
--no-virt Do not create virtual interface
|
||||||
Using this you can't use same wlan interface
|
Using this you can't use same wlan interface
|
||||||
for both Internet and AP
|
for both Internet and AP
|
||||||
-c <channel> Channel number (default: 1)
|
--virt-name <name> Set name of virtual interface
|
||||||
|
-c <channel> Specify channel (default: use current, or 1 / 36)
|
||||||
--country <code> Set two-letter country code for regularity
|
--country <code> Set two-letter country code for regularity
|
||||||
(example: US)
|
(example: US)
|
||||||
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
|
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
|
||||||
@@ -350,13 +382,28 @@ Options:
|
|||||||
(defaults to /etc/hostapd/hostapd.accept)
|
(defaults to /etc/hostapd/hostapd.accept)
|
||||||
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
|
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
|
||||||
--isolate-clients Disable wifi communication between clients
|
--isolate-clients Disable wifi communication between clients
|
||||||
|
|
||||||
--ieee80211n Enable IEEE 802.11n (HT)
|
|
||||||
--ieee80211ac Enable IEEE 802.11ac (VHT)
|
|
||||||
--ht_capab <HT> HT capabilities (default: [HT40+])
|
|
||||||
--vht_capab <VHT> VHT capabilities
|
|
||||||
|
|
||||||
--no-haveged Do not run haveged automatically when needed
|
--no-haveged Do not run haveged automatically when needed
|
||||||
|
--hs20 Enable Hotspot 2.0
|
||||||
|
|
||||||
|
WiFi 4 (802.11n) configs:
|
||||||
|
--wifi4 Enable IEEE 802.11n (HT)
|
||||||
|
--req-ht Require station HT (High Throughput) mode
|
||||||
|
--ht-capab <HT caps> HT capabilities (default: [HT40+])
|
||||||
|
|
||||||
|
WiFi 5 (802.11ac) configs:
|
||||||
|
--wifi5 Enable IEEE 802.11ac (VHT)
|
||||||
|
--req-vht Require station VHT (Very High Thoughtput) mode
|
||||||
|
--vht-capab <VHT caps> VHT capabilities
|
||||||
|
|
||||||
|
--vht-ch-width <index> Index of VHT channel width:
|
||||||
|
0 for 20MHz or 40MHz (default)
|
||||||
|
1 for 80MHz
|
||||||
|
2 for 160MHz
|
||||||
|
3 for 80+80MHz (Non-contigous 160MHz)
|
||||||
|
--vht-seg0-ch <channel> Channel index of VHT center frequency for primary
|
||||||
|
segment. Use with '--vht-ch-width'
|
||||||
|
--vht-seg1-ch <channel> Channel index of VHT center frequency for secondary
|
||||||
|
(second 80MHz) segment. Use with '--vht-ch-width 3'
|
||||||
|
|
||||||
Instance managing:
|
Instance managing:
|
||||||
--daemon Run in background
|
--daemon Run in background
|
||||||
@@ -368,15 +415,7 @@ Options:
|
|||||||
--stop <id> Stop a running instance
|
--stop <id> Stop a running instance
|
||||||
For <id> you can use PID or subnet interface name.
|
For <id> you can use PID or subnet interface name.
|
||||||
You can get them with '--list-running'
|
You can get them with '--list-running'
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## Notice
|
|
||||||
|
|
||||||
<details>
|
|
||||||
|
|
||||||
```
|
|
||||||
Notice 1: This script assume your host's default policy won't forward
|
Notice 1: This script assume your host's default policy won't forward
|
||||||
packets, so the script won't explictly ban forwarding in any
|
packets, so the script won't explictly ban forwarding in any
|
||||||
mode. In some unexpected case (eg. mistaken configurations) may
|
mode. In some unexpected case (eg. mistaken configurations) may
|
||||||
@@ -397,19 +436,35 @@ On exit of a linux-router instance, script **will do cleanup**, i.e. undo most c
|
|||||||
5. The wifi device which is used to create hotspot is `rfkill unblock`ed
|
5. The wifi device which is used to create hotspot is `rfkill unblock`ed
|
||||||
6. WiFi country code, if user assigns
|
6. WiFi country code, if user assigns
|
||||||
|
|
||||||
## Dependencies
|
## Meet contributor(s) and become one of them
|
||||||
|
|
||||||
- bash
|
Visit [**my homepage** 🏡](https://garywill.github.io) to see **more tools and projects** 🛠️.
|
||||||
- procps or procps-ng
|
|
||||||
- iproute2
|
> [❤️ Buy me a coffee](https://github.com/garywill/receiving/blob/master/receiving_methods.md) , this project took me lots of time! ([❤️ 扫码领红包并打赏一个!](https://github.com/garywill/receiving/blob/master/receiving_methods.md))
|
||||||
- dnsmasq
|
>
|
||||||
- iptables (or nftables with `iptables-nft` translation linked)
|
> 🥂 ( ^\_^) o自自o (^_^ ) 🍻
|
||||||
- WiFi hotspot dependencies
|
|
||||||
- hostapd
|
🤝 Bisides, thank [create_ap](https://github.com/oblique/create_ap) by [oblique](https://github.com/oblique). This script was forked from create\_ap. Now they are quite different. (See `history` branch for how I modified create_ap). 🤝 Also thank those who contributed to that project.
|
||||||
- iw
|
|
||||||
- iwconfig (you only need this if 'iw' can not recognize your adapter)
|
👨💻 You can be contributor, too!
|
||||||
- haveged (optional)
|
|
||||||
- qrencode (optional)
|
- 🍃 There're some TO-DOs listed, in both [readme TODO](#todo) and [in the code file](https://github.com/garywill/linux-router/search?q=TODO&type=code)
|
||||||
|
- 🍃 Also some [unfulfilled enhancements in the Issues](https://github.com/garywill/linux-router/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
|
||||||
|
- 🙋♂️ Contributions are not limited to coding. There're [some posts and questions](https://github.com/garywill/linux-router/issues) that need more people to answer
|
||||||
|
|
||||||
|
## Notice
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
```
|
||||||
|
Notice 1: This script assume your host's default policy won't forward
|
||||||
|
packets, so the script won't explictly ban forwarding in any
|
||||||
|
mode. In some unexpected case (eg. mistaken configurations) may
|
||||||
|
cause unwanted packets leakage between 2 networks, which you
|
||||||
|
should be aware of if you want isolated network
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
@@ -481,14 +536,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
## Meet developer(s) and become one of them
|
|
||||||
|
|
||||||
Visit [**my homepage** 🏡](https://garywill.github.io) to see **more tools and projects** 🛠️.
|
|
||||||
|
|
||||||
> [❤️ Buy me a coffee](https://github.com/garywill/receiving/blob/master/receiving_methods.md) , this project took me lots of time! ([❤️ 扫码领红包并打赏一个!](https://github.com/garywill/receiving/blob/master/receiving_methods.md))
|
|
||||||
>
|
|
||||||
> 🥂 ( ^\_^) o自自o (^_^ ) 🍻
|
|
||||||
|
|
||||||
🤝 Bisides, thank [create_ap](https://github.com/oblique/create_ap) by [oblique](https://github.com/oblique). This script was forked from create\_ap. Now they are quite different. (See `history` branch for how I modified create_ap). 🤝 Also thank those who contributed to that project.
|
|
||||||
|
|
||||||
👨💻 You can be contributor, too! 🍃 There're some TO-DOs listed, at both [above](#todo) and [in the code file](https://github.com/garywill/linux-router/search?q=TODO&type=code). 🍃 Also some [unfulfilled enhancements in the Issues](https://github.com/garywill/linux-router/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement). Your name can be here!
|
|
||||||
|
|||||||
218
lnxrouter
218
lnxrouter
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
VERSION=0.6.6
|
VERSION=0.7.1
|
||||||
PROGNAME="$(basename $0)"
|
PROGNAME="$(basename $0)"
|
||||||
|
|
||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
@@ -67,26 +67,28 @@ Options:
|
|||||||
-d DNS server will take into account /etc/hosts
|
-d DNS server will take into account /etc/hosts
|
||||||
-e <hosts_file> DNS server will take into account additional
|
-e <hosts_file> DNS server will take into account additional
|
||||||
hosts file
|
hosts file
|
||||||
|
--dns-nocache DNS server no cache
|
||||||
|
|
||||||
--mac <MAC> Set MAC address
|
--mac <MAC> Set MAC address
|
||||||
--random-mac Use random MAC address
|
--random-mac Use random MAC address
|
||||||
|
|
||||||
--tp <port> Transparent proxy,
|
--tp <port> Transparent proxy,
|
||||||
redirect non-LAN TCP and UDP traffic to port.
|
redirect non-LAN TCP and UDP(not tested) traffic to
|
||||||
(usually used with '--dns')
|
port. (usually used with '--dns')
|
||||||
|
|
||||||
WiFi hotspot options:
|
WiFi hotspot options:
|
||||||
--ap <wifi interface> <SSID>
|
--ap <wifi interface> <SSID>
|
||||||
Create WiFi access point
|
Create WiFi access point
|
||||||
-p, --password <password>
|
-p, --password <password>
|
||||||
WiFi password
|
WiFi password
|
||||||
--qr Show WiFi QR code in terminal
|
--qr Show WiFi QR code in terminal (need qrencode)
|
||||||
|
|
||||||
--hidden Hide access point (not broadcast SSID)
|
--hidden Hide access point (not broadcast SSID)
|
||||||
--no-virt Do not create virtual interface
|
--no-virt Do not create virtual interface
|
||||||
Using this you can't use same wlan interface
|
Using this you can't use same wlan interface
|
||||||
for both Internet and AP
|
for both Internet and AP
|
||||||
-c <channel> Channel number (default: 1)
|
--virt-name <name> Set name of virtual interface
|
||||||
|
-c <channel> Specify channel (default: use current, or 1 / 36)
|
||||||
--country <code> Set two-letter country code for regularity
|
--country <code> Set two-letter country code for regularity
|
||||||
(example: US)
|
(example: US)
|
||||||
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
|
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
|
||||||
@@ -100,13 +102,28 @@ Options:
|
|||||||
(defaults to /etc/hostapd/hostapd.accept)
|
(defaults to /etc/hostapd/hostapd.accept)
|
||||||
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
|
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
|
||||||
--isolate-clients Disable wifi communication between clients
|
--isolate-clients Disable wifi communication between clients
|
||||||
|
|
||||||
--ieee80211n Enable IEEE 802.11n (HT)
|
|
||||||
--ieee80211ac Enable IEEE 802.11ac (VHT)
|
|
||||||
--ht_capab <HT> HT capabilities (default: [HT40+])
|
|
||||||
--vht_capab <VHT> VHT capabilities
|
|
||||||
|
|
||||||
--no-haveged Do not run haveged automatically when needed
|
--no-haveged Do not run haveged automatically when needed
|
||||||
|
--hs20 Enable Hotspot 2.0
|
||||||
|
|
||||||
|
WiFi 4 (802.11n) configs:
|
||||||
|
--wifi4 Enable IEEE 802.11n (HT)
|
||||||
|
--req-ht Require station HT (High Throughput) mode
|
||||||
|
--ht-capab <HT caps> HT capabilities (default: [HT40+])
|
||||||
|
|
||||||
|
WiFi 5 (802.11ac) configs:
|
||||||
|
--wifi5 Enable IEEE 802.11ac (VHT)
|
||||||
|
--req-vht Require station VHT (Very High Thoughtput) mode
|
||||||
|
--vht-capab <VHT caps> VHT capabilities
|
||||||
|
|
||||||
|
--vht-ch-width <index> Index of VHT channel width:
|
||||||
|
0 for 20MHz or 40MHz (default)
|
||||||
|
1 for 80MHz
|
||||||
|
2 for 160MHz
|
||||||
|
3 for 80+80MHz (Non-contigous 160MHz)
|
||||||
|
--vht-seg0-ch <channel> Channel index of VHT center frequency for primary
|
||||||
|
segment. Use with '--vht-ch-width'
|
||||||
|
--vht-seg1-ch <channel> Channel index of VHT center frequency for secondary
|
||||||
|
(second 80MHz) segment. Use with '--vht-ch-width 3'
|
||||||
|
|
||||||
Instance managing:
|
Instance managing:
|
||||||
--daemon Run in background
|
--daemon Run in background
|
||||||
@@ -156,6 +173,7 @@ define_global_variables(){
|
|||||||
SHOW_DNS_QUERY=0 # log dns
|
SHOW_DNS_QUERY=0 # log dns
|
||||||
ETC_HOSTS=0
|
ETC_HOSTS=0
|
||||||
ADDN_HOSTS=
|
ADDN_HOSTS=
|
||||||
|
DNS_NOCACHE=
|
||||||
CONN_IFACE= # which interface user choose to use to create network
|
CONN_IFACE= # which interface user choose to use to create network
|
||||||
INTERNET_IFACE= # which interface to get Internet from
|
INTERNET_IFACE= # which interface to get Internet from
|
||||||
THISHOSTNAME= # this host's name the DNS tells clients
|
THISHOSTNAME= # this host's name the DNS tells clients
|
||||||
@@ -176,13 +194,19 @@ define_global_variables(){
|
|||||||
HIDDEN=0 # hidden wifi hotspot
|
HIDDEN=0 # hidden wifi hotspot
|
||||||
WIFI_IFACE=
|
WIFI_IFACE=
|
||||||
CHANNEL=default
|
CHANNEL=default
|
||||||
|
HOTSPOT20=0 # For enabling Hotspot 2.0
|
||||||
WPA_VERSION=2
|
WPA_VERSION=2
|
||||||
MAC_FILTER=0
|
MAC_FILTER=0
|
||||||
MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept
|
MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept
|
||||||
IEEE80211N=0
|
IEEE80211N=0
|
||||||
|
REQUIREHT=0
|
||||||
IEEE80211AC=0
|
IEEE80211AC=0
|
||||||
|
REQUIREVHT=0
|
||||||
HT_CAPAB='[HT40+]'
|
HT_CAPAB='[HT40+]'
|
||||||
VHT_CAPAB=
|
VHT_CAPAB=
|
||||||
|
VHTCHANNELWIDTH=0
|
||||||
|
VHTSEG0CHINDEX=0
|
||||||
|
VHTSEG1CHINDEX=0
|
||||||
DRIVER=nl80211
|
DRIVER=nl80211
|
||||||
NO_VIRT=0 # not use virtual interface
|
NO_VIRT=0 # not use virtual interface
|
||||||
COUNTRY=
|
COUNTRY=
|
||||||
@@ -195,6 +219,7 @@ define_global_variables(){
|
|||||||
|
|
||||||
# script variables
|
# script variables
|
||||||
VWIFI_IFACE= # virtual wifi interface name, if created
|
VWIFI_IFACE= # virtual wifi interface name, if created
|
||||||
|
VIRT_NAME= # name to use for virtual interface if --virt-name is used
|
||||||
AP_IFACE= # can be VWIFI_IFACE or WIFI_IFACE
|
AP_IFACE= # can be VWIFI_IFACE or WIFI_IFACE
|
||||||
USE_IWCONFIG=0 # some device can't use iw
|
USE_IWCONFIG=0 # some device can't use iw
|
||||||
|
|
||||||
@@ -322,6 +347,10 @@ parse_user_options(){
|
|||||||
ADDN_HOSTS="$1"
|
ADDN_HOSTS="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--dns-nocache)
|
||||||
|
shift
|
||||||
|
DNS_NOCACHE=1
|
||||||
|
;;
|
||||||
|
|
||||||
--isolate-clients)
|
--isolate-clients)
|
||||||
shift
|
shift
|
||||||
@@ -365,6 +394,10 @@ parse_user_options(){
|
|||||||
CHANNEL="$1"
|
CHANNEL="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--hs20)
|
||||||
|
shift
|
||||||
|
HOTSPOT20=1
|
||||||
|
;;
|
||||||
-w)
|
-w)
|
||||||
shift
|
shift
|
||||||
WPA_VERSION="$1"
|
WPA_VERSION="$1"
|
||||||
@@ -372,24 +405,47 @@ parse_user_options(){
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--ieee80211n)
|
--wifi4|--ieee80211n)
|
||||||
shift
|
shift
|
||||||
IEEE80211N=1
|
IEEE80211N=1
|
||||||
;;
|
;;
|
||||||
--ieee80211ac)
|
--req-ht|--require-ht)
|
||||||
|
shift
|
||||||
|
REQUIREHT=1
|
||||||
|
;;
|
||||||
|
--wifi5|--ieee80211ac)
|
||||||
shift
|
shift
|
||||||
IEEE80211AC=1
|
IEEE80211AC=1
|
||||||
;;
|
;;
|
||||||
--ht_capab)
|
--req-vht|--require-vht)
|
||||||
|
shift
|
||||||
|
REQUIREVHT=1
|
||||||
|
;;
|
||||||
|
--ht-capab)
|
||||||
shift
|
shift
|
||||||
HT_CAPAB="$1"
|
HT_CAPAB="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--vht_capab)
|
--vht-capab)
|
||||||
shift
|
shift
|
||||||
VHT_CAPAB="$1"
|
VHT_CAPAB="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--vht-ch-width|--vht-channel-width)
|
||||||
|
shift
|
||||||
|
VHTCHANNELWIDTH="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--vht-seg0-ch|--vht-seg0-channel)
|
||||||
|
shift
|
||||||
|
VHTSEG0CHINDEX="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--vht-seg1-ch|--vht-seg1-channel)
|
||||||
|
shift
|
||||||
|
VHTSEG1CHINDEX="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--driver)
|
--driver)
|
||||||
shift
|
shift
|
||||||
DRIVER="$1"
|
DRIVER="$1"
|
||||||
@@ -399,6 +455,11 @@ parse_user_options(){
|
|||||||
shift
|
shift
|
||||||
NO_VIRT=1
|
NO_VIRT=1
|
||||||
;;
|
;;
|
||||||
|
--virt-name)
|
||||||
|
shift
|
||||||
|
VIRT_NAME="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
--country)
|
--country)
|
||||||
shift
|
shift
|
||||||
@@ -505,6 +566,10 @@ is_interface() {
|
|||||||
[[ -d "/sys/class/net/${1}" ]]
|
[[ -d "/sys/class/net/${1}" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_vface_name_allocated(){
|
||||||
|
is_interface "$1" || [[ -f "$COMMON_CONFDIR/vfaces/${1}" ]]
|
||||||
|
}
|
||||||
|
|
||||||
get_interface_phy_device() { # only for wifi interface
|
get_interface_phy_device() { # only for wifi interface
|
||||||
local x
|
local x
|
||||||
for x in /sys/class/ieee80211/*; do
|
for x in /sys/class/ieee80211/*; do
|
||||||
@@ -651,20 +716,19 @@ get_interface_pci_info() { # pci id / model / virtual
|
|||||||
# TODO current driver
|
# TODO current driver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
alloc_new_vface_name() { # only for wifi
|
alloc_new_vface_name() { # only for wifi
|
||||||
local i=0
|
local i=0
|
||||||
local v_iface_name=
|
local v_iface_name="$VIRT_NAME"
|
||||||
while :; do
|
if [[ -z $VIRT_NAME ]]; then
|
||||||
v_iface_name="x$i${WIFI_IFACE}"
|
while :; do
|
||||||
if ! is_interface ${v_iface_name} && [[ ! -f $COMMON_CONFDIR/vfaces/${v_iface_name} ]]; then
|
v_iface_name="x$i${WIFI_IFACE}"
|
||||||
mkdir -p $COMMON_CONFDIR/vfaces
|
i=$((i + 1))
|
||||||
touch $COMMON_CONFDIR/vfaces/${v_iface_name}
|
is_vface_name_allocated ${v_iface_name} || break
|
||||||
echo "${v_iface_name}"
|
done
|
||||||
return
|
fi
|
||||||
fi
|
mkdir -p $COMMON_CONFDIR/vfaces
|
||||||
i=$((i + 1))
|
touch $COMMON_CONFDIR/vfaces/${v_iface_name}
|
||||||
done
|
echo "${v_iface_name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
dealloc_vface_name() {
|
dealloc_vface_name() {
|
||||||
@@ -1021,7 +1085,7 @@ allow_dhcp() {
|
|||||||
# TODO: use 'DNAT' instead of '--to-ports' to support other IP
|
# TODO: use 'DNAT' instead of '--to-ports' to support other IP
|
||||||
start_redsocks() {
|
start_redsocks() {
|
||||||
echo
|
echo
|
||||||
echo "iptables: transparent proxy non-LAN TCP/UDP traffic to port ${TP_PORT}"
|
echo "iptables: transparent proxy non-LAN TCP and UDP(not tested) traffic to port ${TP_PORT}"
|
||||||
if [[ $NO4 -eq 0 ]]; then
|
if [[ $NO4 -eq 0 ]]; then
|
||||||
iptb 4 n nat N lrt${$}${SUBNET_IFACE}-TP || die
|
iptb 4 n nat N lrt${$}${SUBNET_IFACE}-TP || die
|
||||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 0.0.0.0/8 -j RETURN || die
|
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 0.0.0.0/8 -j RETURN || die
|
||||||
@@ -1207,7 +1271,7 @@ cleanup() {
|
|||||||
#kill -9 -$pgid
|
#kill -9 -$pgid
|
||||||
}
|
}
|
||||||
|
|
||||||
# NOTE function die() is designed not to be used before init_trap() executed
|
# NOTE function die() is designed NOT to be used before init_trap() executed
|
||||||
die() { # SIGUSR2
|
die() { # SIGUSR2
|
||||||
echo "Error occured"
|
echo "Error occured"
|
||||||
[[ -n "$1" ]] && echo -e "\nERROR: $1\n" >&2
|
[[ -n "$1" ]] && echo -e "\nERROR: $1\n" >&2
|
||||||
@@ -1490,7 +1554,7 @@ daemonizing_check(){
|
|||||||
check_wifi_settings() {
|
check_wifi_settings() {
|
||||||
|
|
||||||
if ! ( which iw > /dev/null 2>&1 && iw dev $WIFI_IFACE info > /dev/null 2>&1 ); then
|
if ! ( which iw > /dev/null 2>&1 && iw dev $WIFI_IFACE info > /dev/null 2>&1 ); then
|
||||||
echo "WARN: Can't use 'iw' to operate interfce '$WIFI_IFACE', trying 'iwconfig' (not as good as 'iw') ..." >&2
|
echo "WARN: Can't use 'iw' to operate interfce '$WIFI_IFACE', trying 'iwconfig' (not as good as 'iw') ... (Did you spell the interface name right?)" >&2
|
||||||
USE_IWCONFIG=1
|
USE_IWCONFIG=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1506,14 +1570,6 @@ check_wifi_settings() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $CHANNEL == default ]]; then
|
|
||||||
if [[ $FREQ_BAND == 2.4 ]]; then
|
|
||||||
CHANNEL=1
|
|
||||||
else
|
|
||||||
CHANNEL=36
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $FREQ_BAND != 5 && $CHANNEL -gt 14 ]]; then
|
if [[ $FREQ_BAND != 5 && $CHANNEL -gt 14 ]]; then
|
||||||
echo "Channel number is greater than 14, assuming 5GHz frequency band"
|
echo "Channel number is greater than 14, assuming 5GHz frequency band"
|
||||||
FREQ_BAND=5
|
FREQ_BAND=5
|
||||||
@@ -1569,6 +1625,18 @@ check_wifi_settings() {
|
|||||||
fi
|
fi
|
||||||
echo "WARN: If AP doesn't work, read https://github.com/oblique/create_ap/blob/master/howto/realtek.md" >&2
|
echo "WARN: If AP doesn't work, read https://github.com/oblique/create_ap/blob/master/howto/realtek.md" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z $VIRT_NAME ]]; then
|
||||||
|
if [[ ${#WIFI_IFACE} -gt 13 ]]; then
|
||||||
|
echo "WARN: $WIFI_IFACE has ${#WIFI_IFACE} characters which might be too long. If AP doesn't work, see --virt-name and https://github.com/garywill/linux-router/issues/44" >&2
|
||||||
|
fi
|
||||||
|
elif [[ ${#VIRT_NAME} -gt 15 ]]; then
|
||||||
|
echo "WARN: option --virt-name $VIRT_NAME has ${#VIRT_NAME} characters which might be too long, consider making it shorter in case of errors" >&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -z $VIRT_NAME ]] && is_vface_name_allocated $VIRT_NAME; then
|
||||||
|
echo "WARN: interface $VIRT_NAME aleady exists, this will cause an error"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_if_new_mac_valid() {
|
check_if_new_mac_valid() {
|
||||||
@@ -1620,20 +1688,21 @@ prepare_wifi_interface() {
|
|||||||
|
|
||||||
if [[ $NO_VIRT -eq 0 ]]; then
|
if [[ $NO_VIRT -eq 0 ]]; then
|
||||||
## Will generate virtual wifi interface
|
## Will generate virtual wifi interface
|
||||||
|
|
||||||
|
# TODO move this to check_wifi_settings() ?
|
||||||
if is_interface_wifi_connected ${WIFI_IFACE}; then
|
if is_interface_wifi_connected ${WIFI_IFACE}; then
|
||||||
WIFI_IFACE_FREQ=$(iw dev ${WIFI_IFACE} link | grep -i freq | awk '{print $2}')
|
WIFI_IFACE_FREQ=$(iw dev ${WIFI_IFACE} link | grep -i freq | awk '{print $2}')
|
||||||
WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel ${WIFI_IFACE_FREQ})
|
WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel ${WIFI_IFACE_FREQ})
|
||||||
echo "${WIFI_IFACE} already in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
|
|
||||||
if is_5ghz_frequency $WIFI_IFACE_FREQ; then
|
echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
|
||||||
FREQ_BAND=5
|
|
||||||
else
|
if [[ $CHANNEL == default ]]; then
|
||||||
FREQ_BAND=2.4
|
echo "Use wifi adapter current channel $WIFI_IFACE_CHANNEL as target channel"
|
||||||
fi
|
|
||||||
if [[ $WIFI_IFACE_CHANNEL -ne $CHANNEL ]]; then
|
|
||||||
echo "Channel fallback to ${WIFI_IFACE_CHANNEL}"
|
|
||||||
CHANNEL=$WIFI_IFACE_CHANNEL
|
CHANNEL=$WIFI_IFACE_CHANNEL
|
||||||
else
|
fi
|
||||||
echo
|
|
||||||
|
if [[ $WIFI_IFACE_CHANNEL -ne $CHANNEL ]]; then
|
||||||
|
echo "WARN: Wifi adapter already working in channel ${WIFI_IFACE_CHANNEL}, which is different than target channel $CHANNEL" >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1646,13 +1715,28 @@ prepare_wifi_interface() {
|
|||||||
echo "${VWIFI_IFACE} created"
|
echo "${VWIFI_IFACE} created"
|
||||||
else
|
else
|
||||||
VWIFI_IFACE=
|
VWIFI_IFACE=
|
||||||
die "Failed creating virtual WiFi interface. Maybe your WiFi adapter does not fully support virtual interfaces. Try again with '--no-virt'"
|
if [[ ! -z ${VIRT_NAME} ]] && [[ ${#VIRT_NAME} -gt 15 ]]; then
|
||||||
|
die "Failed creating virtual WiFi interface. This is likely because you have set a long name for your virtual interface using --virt-name, try making it shorter'"
|
||||||
|
elif [[ -z ${VIRT_NAME} ]] && [[ ${#WIFI_IFACE} -gt 13 ]]; then
|
||||||
|
die "Failed creating virtual WiFi interface. This is likely because your interface name is too long. Try using '--virt-name <shorter interface name>'"
|
||||||
|
else
|
||||||
|
die "Failed creating virtual WiFi interface. Maybe your WiFi adapter does not fully support virtual interfaces. Try again with '--no-virt'"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AP_IFACE=${VWIFI_IFACE}
|
AP_IFACE=${VWIFI_IFACE}
|
||||||
else # no virtual wifi interface, use wifi device interface itself
|
else # no virtual wifi interface, use wifi device interface itself
|
||||||
AP_IFACE=${WIFI_IFACE}
|
AP_IFACE=${WIFI_IFACE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $CHANNEL == default ]]; then
|
||||||
|
echo "Channel not specified, use default"
|
||||||
|
if [[ $FREQ_BAND == 2.4 ]]; then
|
||||||
|
CHANNEL=1
|
||||||
|
else
|
||||||
|
CHANNEL=36
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
decide_subnet_interface() {
|
decide_subnet_interface() {
|
||||||
@@ -1714,6 +1798,10 @@ write_hostapd_conf() {
|
|||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $HOTSPOT20 -eq 1 ]]; then
|
||||||
|
echo "hs20=1" >> "$CONFDIR/hostapd.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $IEEE80211N -eq 1 ]]; then
|
if [[ $IEEE80211N -eq 1 ]]; then
|
||||||
cat <<- EOF >> "$CONFDIR/hostapd.conf"
|
cat <<- EOF >> "$CONFDIR/hostapd.conf"
|
||||||
ieee80211n=1
|
ieee80211n=1
|
||||||
@@ -1721,14 +1809,40 @@ write_hostapd_conf() {
|
|||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $REQUIREHT -eq 1 ]]; then
|
||||||
|
echo "require_ht=1" >> "$CONFDIR/hostapd.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $IEEE80211AC -eq 1 ]]; then
|
if [[ $IEEE80211AC -eq 1 ]]; then
|
||||||
echo "ieee80211ac=1" >> "$CONFDIR/hostapd.conf"
|
echo "ieee80211ac=1" >> "$CONFDIR/hostapd.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $REQUIREVHT -eq 1 ]]; then
|
||||||
|
echo "require_vht=1" >> "$CONFDIR/hostapd.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n "$VHT_CAPAB" ]]; then
|
if [[ -n "$VHT_CAPAB" ]]; then
|
||||||
echo "vht_capab=${VHT_CAPAB}" >> "$CONFDIR/hostapd.conf"
|
echo "vht_capab=${VHT_CAPAB}" >> "$CONFDIR/hostapd.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $VHTCHANNELWIDTH -gt 0 ]]; then
|
||||||
|
cat <<- EOF >> "$CONFDIR/hostapd.conf"
|
||||||
|
vht_oper_chwidth=${VHTCHANNELWIDTH}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $VHTSEG0CHINDEX -gt 0 ]]; then
|
||||||
|
cat <<- EOF >> "$CONFDIR/hostapd.conf"
|
||||||
|
vht_oper_centr_freq_seg0_idx=${VHTSEG0CHINDEX}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $VHTSEG1CHINDEX -gt 0 ]]; then
|
||||||
|
cat <<- EOF >> "$CONFDIR/hostapd.conf"
|
||||||
|
vht_oper_centr_freq_seg1_idx=${VHTSEG1CHINDEX}
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $IEEE80211N -eq 1 ]] || [[ $IEEE80211AC -eq 1 ]]; then
|
if [[ $IEEE80211N -eq 1 ]] || [[ $IEEE80211AC -eq 1 ]]; then
|
||||||
echo "wmm_enabled=1" >> "$CONFDIR/hostapd.conf"
|
echo "wmm_enabled=1" >> "$CONFDIR/hostapd.conf"
|
||||||
fi
|
fi
|
||||||
@@ -1822,6 +1936,10 @@ write_dnsmasq_conf() {
|
|||||||
no-poll
|
no-poll
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
if [[ $DNS_NOCACHE -eq 1 ]]; then
|
||||||
|
echo "cache-size=0" >> "$CONFDIR/dnsmasq.conf"
|
||||||
|
echo "no-negcache" >> "$CONFDIR/dnsmasq.conf"
|
||||||
|
fi
|
||||||
if [[ $IPV6 -eq 1 ]];then
|
if [[ $IPV6 -eq 1 ]];then
|
||||||
cat <<- EOF >> "$CONFDIR/dnsmasq.conf"
|
cat <<- EOF >> "$CONFDIR/dnsmasq.conf"
|
||||||
listen-address=${GATEWAY6}
|
listen-address=${GATEWAY6}
|
||||||
@@ -1872,7 +1990,7 @@ run_wifi_ap_processes() {
|
|||||||
# sleep 1
|
# sleep 1
|
||||||
#done
|
#done
|
||||||
#echo -n "hostapd PID: " ; cat $CONFDIR/hostapd.pid
|
#echo -n "hostapd PID: " ; cat $CONFDIR/hostapd.pid
|
||||||
pid_watchdog $HOSTAPD_PID 10 "hostapd failed" &
|
pid_watchdog $HOSTAPD_PID 10 "hostapd failed. (tip: try '--hostapd-debug' to get some debug info)" &
|
||||||
sleep 3
|
sleep 3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user