mirror of
https://github.com/garywill/linux-router.git
synced 2025-12-30 02:38:28 +01:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
f6995bc30c | ||
|
|
f8cbf5eded | ||
|
|
15a2e0ce53 | ||
|
|
083cd42afd |
207
README.md
207
README.md
@@ -1,10 +1,11 @@
|
||||
# Linux-router
|
||||
|
||||
Set Linux as router in one command. Able to Provide Internet, or create Wifi hotspot. Support transparent proxy (redsocks). Also useful for routing VM/containers.
|
||||
Set Linux as router in one command. Able to provide Internet, or create WiFi hotspot. Support transparent proxy (redsocks). Also useful for routing VM/containers.
|
||||
|
||||
It wraps `iptables`, `dnsmasq` etc. stuff. Use in one command, restore in one command or by `control-c` (or even by closing terminal window).
|
||||
|
||||
[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
|
||||
|
||||
@@ -12,17 +13,19 @@ Basic features:
|
||||
|
||||
- Create a NATed sub-network
|
||||
- Provide Internet
|
||||
- DHCP server (and RA) + DNS server
|
||||
- Configuring what DNS the DHCP server offers to clients
|
||||
- Configuring upstream DNS for local DNS server (kind of a DNS proxy)
|
||||
- DHCP server (and RA)
|
||||
- Specify what DNS the DHCP server assigns to clients
|
||||
- DNS server
|
||||
- Specify upstream DNS (kind of a plain DNS proxy)
|
||||
- IPv6 (behind NATed LAN, like IPv4)
|
||||
- Creating Wifi hotspot:
|
||||
- Creating WiFi hotspot:
|
||||
- Channel selecting
|
||||
- Choose encryptions: WPA2/WPA, WPA2, WPA, No encryption
|
||||
- Create AP on the same interface you are getting Internet (usually require same channel)
|
||||
- Transparent proxy (redsocks)
|
||||
- Transparent DNS proxy (hijack port 53 packets)
|
||||
- Compatible with NetworkManager (automatically set interface as unmanaged)
|
||||
- Detect NetworkManager and make sure it won't interfere (handle interface (un)managed status)
|
||||
- You can run many instances, to create many different networks. Has instances managing feature.
|
||||
|
||||
**For many other features, see below [CLI usage](#cli-usage-and-other-features)**
|
||||
|
||||
@@ -36,7 +39,7 @@ Internet----(eth0/wlan0)-Linux-(wlanX)AP
|
||||
|
||||
```
|
||||
Internet
|
||||
Wifi AP(no DHCP) |
|
||||
WiFi AP(no DHCP) |
|
||||
|----(wlan1)-Linux-(eth0/wlan0)------
|
||||
| (DHCP)
|
||||
|--client
|
||||
@@ -59,6 +62,31 @@ Internet----(eth0/wlan0)-Linux-(eth1)------Another PC
|
||||
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
|
||||
|
||||
### Provide Internet to an interface
|
||||
@@ -69,7 +97,7 @@ sudo lnxrouter -i eth1
|
||||
|
||||
no matter which interface (other than `eth1`) you're getting Internet from.
|
||||
|
||||
### Create Wifi hotspot
|
||||
### Create WiFi hotspot
|
||||
|
||||
```
|
||||
sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase
|
||||
@@ -90,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:
|
||||
>
|
||||
> 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*
|
||||
|
||||
</details>
|
||||
|
||||
### LAN without Internet
|
||||
### Create LAN without providing Internet
|
||||
|
||||
<details>
|
||||
|
||||
@@ -136,7 +164,7 @@ sudo lnxrouter -i lxcbr5
|
||||
|
||||
### 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>
|
||||
|
||||
@@ -153,6 +181,10 @@ TransPort [fd00:5:6:7::1]:9040
|
||||
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>
|
||||
|
||||
### Clients-in-sandbox network
|
||||
@@ -171,7 +203,7 @@ sudo lnxrouter -i eth1 \
|
||||
|
||||
</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
|
||||
|
||||
@@ -253,9 +285,13 @@ sudo brctl addbr firejail5
|
||||
|
||||
```
|
||||
sudo lnxrouter -i firejail5 -g 192.168.55.1 --tp 9040 --dns 9053
|
||||
firejail --net=firejail5 --dns=192.168.55.1 --blacklist=/var/run/nscd # nscd is cache service, which shouldn't be accessed in jail here
|
||||
firejail --net=firejail5 --dns=192.168.55.1 --blacklist=/var/run/nscd
|
||||
```
|
||||
|
||||
Firejail's `/etc/resolv.conf` doesn't obtain DNS from DHCP, so we need to assign.
|
||||
|
||||
nscd is domain name cache service, which shouldn't be accessed from in jail here.
|
||||
|
||||
</details>
|
||||
|
||||
### CLI usage and other features
|
||||
@@ -271,24 +307,24 @@ Options:
|
||||
|
||||
-i <interface> Interface to make NATed sub-network,
|
||||
and to provide Internet to
|
||||
(To create Wifi hotspot use '--ap' instead)
|
||||
(To create WiFi hotspot use '--ap' instead)
|
||||
-o <interface> Specify an inteface to provide Internet from.
|
||||
(See Notice 1)
|
||||
(Note using this with default DNS option may leak
|
||||
queries to other interfaces)
|
||||
-n Do not provide Internet (See Notice 1)
|
||||
--ban-priv Disallow clients to access my private network
|
||||
|
||||
|
||||
-g <ip> This host's IPv4 address in subnet (mask is /24)
|
||||
(example: '192.168.5.1' or '5' shortly)
|
||||
-6 Enable IPv6 (NAT)
|
||||
--no4 Disable IPv4 Internet (not forwarding IPv4)
|
||||
(See Notice 1). Usually used with '-6'
|
||||
|
||||
|
||||
--p6 <prefix> Set IPv6 LAN address prefix (length 64)
|
||||
(example: 'fd00:0:0:5::' or '5' shortly)
|
||||
Using this enables '-6'
|
||||
|
||||
|
||||
--dns <ip>|<port>|<ip:port>
|
||||
DNS server's upstream DNS.
|
||||
Use ',' to seperate multiple servers
|
||||
@@ -311,26 +347,28 @@ Options:
|
||||
-d DNS server will take into account /etc/hosts
|
||||
-e <hosts_file> DNS server will take into account additional
|
||||
hosts file
|
||||
|
||||
--dns-nocache DNS server no cache
|
||||
|
||||
--mac <MAC> Set MAC address
|
||||
--random-mac Use random MAC address
|
||||
|
||||
|
||||
--tp <port> Transparent proxy,
|
||||
redirect non-LAN TCP and UDP traffic to port.
|
||||
(usually used with '--dns')
|
||||
|
||||
Wifi hotspot options:
|
||||
redirect non-LAN TCP and UDP(not tested) traffic to
|
||||
port. (usually used with '--dns')
|
||||
|
||||
WiFi hotspot options:
|
||||
--ap <wifi interface> <SSID>
|
||||
Create Wifi access point
|
||||
Create WiFi access point
|
||||
-p, --password <password>
|
||||
Wifi password
|
||||
--qr Show Wifi QR code in terminal
|
||||
|
||||
WiFi password
|
||||
--qr Show WiFi QR code in terminal (need qrencode)
|
||||
|
||||
--hidden Hide access point (not broadcast SSID)
|
||||
--no-virt Do not create virtual interface
|
||||
Using this you can't use same wlan interface
|
||||
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
|
||||
(example: US)
|
||||
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
|
||||
@@ -339,18 +377,33 @@ Options:
|
||||
(default: 2)
|
||||
--psk Use 64 hex digits pre-shared-key instead of
|
||||
passphrase
|
||||
--mac-filter Enable Wifi hotspot MAC address filtering
|
||||
--mac-filter-accept Location of Wifi hotspot MAC address filter list
|
||||
--mac-filter Enable WiFi hotspot MAC address filtering
|
||||
--mac-filter-accept Location of WiFi hotspot MAC address filter list
|
||||
(defaults to /etc/hostapd/hostapd.accept)
|
||||
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
|
||||
--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
|
||||
--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:
|
||||
--daemon Run in background
|
||||
@@ -362,10 +415,43 @@ Options:
|
||||
--stop <id> Stop a running instance
|
||||
For <id> you can use PID or subnet interface name.
|
||||
You can get them with '--list-running'
|
||||
|
||||
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>
|
||||
|
||||
## What changes are done to Linux system
|
||||
|
||||
On exit of a linux-router instance, script **will do cleanup**, i.e. undo most changes to system. Though, **some** changes (if needed) will **not** be undone, which are:
|
||||
|
||||
1. `/proc/sys/net/ipv4/ip_forward = 1` and `/proc/sys/net/ipv6/conf/all/forwarding = 1`
|
||||
2. dnsmasq in Apparmor complain mode
|
||||
3. hostapd in Apparmor complain mode
|
||||
4. Kernel module `nf_nat_pptp` loaded
|
||||
5. The wifi device which is used to create hotspot is `rfkill unblock`ed
|
||||
6. WiFi country code, if user assigns
|
||||
|
||||
## Meet contributor(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, 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>
|
||||
@@ -373,49 +459,24 @@ Options:
|
||||
```
|
||||
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 may cause unwanted packets
|
||||
leakage between 2 networks, which you should be aware of if you
|
||||
want isolated network
|
||||
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>
|
||||
|
||||
## What changes are done to Linux system
|
||||
|
||||
On exit of a linux-router instance, script **will do cleanup**, i.e. undo most changes to system. Though, **some** changes will **not** be undone, which are:
|
||||
|
||||
1. `/proc/sys/net/ipv4/ip_forward = 1` and `/proc/sys/net/ipv6/conf/all/forwarding = 1`
|
||||
2. dnsmasq (if used) in Apparmor complain mode
|
||||
3. hostapd (if used) in Apparmor complain mode
|
||||
4. Kernel module `nf_nat_pptp` loaded
|
||||
5. The wifi device which is used to create hotspot is `rfkill unblock`ed
|
||||
6. Wifi country code, if user specified
|
||||
|
||||
## 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)
|
||||
- qrencode (optional)
|
||||
|
||||
## TODO
|
||||
|
||||
<details>
|
||||
Sooner is better:
|
||||
- Detect firewalld and make sure it won't interfere our interface
|
||||
|
||||
Future:
|
||||
- WPA3
|
||||
- Global IPv6
|
||||
- Explictly ban forwarding if not needed
|
||||
- Bring bridging method back
|
||||
|
||||
</details>
|
||||
|
||||
## License
|
||||
|
||||
linux-router is LGPL licensed
|
||||
@@ -475,14 +536,4 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
</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 and in the code file. Also some unfulfilled enhancements in the Issues. Your name can be here!
|
||||
|
||||
652
lnxrouter
Normal file → Executable file
652
lnxrouter
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=0.6.5
|
||||
VERSION=0.7.1b
|
||||
PROGNAME="$(basename $0)"
|
||||
|
||||
export LC_ALL=C
|
||||
@@ -27,7 +27,7 @@ Options:
|
||||
|
||||
-i <interface> Interface to make NATed sub-network,
|
||||
and to provide Internet to
|
||||
(To create Wifi hotspot use '--ap' instead)
|
||||
(To create WiFi hotspot use '--ap' instead)
|
||||
-o <interface> Specify an inteface to provide Internet from.
|
||||
(See Notice 1)
|
||||
(Note using this with default DNS option may leak
|
||||
@@ -67,26 +67,28 @@ Options:
|
||||
-d DNS server will take into account /etc/hosts
|
||||
-e <hosts_file> DNS server will take into account additional
|
||||
hosts file
|
||||
--dns-nocache DNS server no cache
|
||||
|
||||
--mac <MAC> Set MAC address
|
||||
--random-mac Use random MAC address
|
||||
|
||||
--tp <port> Transparent proxy,
|
||||
redirect non-LAN TCP and UDP traffic to port.
|
||||
(usually used with '--dns')
|
||||
redirect non-LAN TCP and UDP(not tested) traffic to
|
||||
port. (usually used with '--dns')
|
||||
|
||||
Wifi hotspot options:
|
||||
WiFi hotspot options:
|
||||
--ap <wifi interface> <SSID>
|
||||
Create Wifi access point
|
||||
Create WiFi access point
|
||||
-p, --password <password>
|
||||
Wifi password
|
||||
--qr Show Wifi QR code in terminal
|
||||
WiFi password
|
||||
--qr Show WiFi QR code in terminal (need qrencode)
|
||||
|
||||
--hidden Hide access point (not broadcast SSID)
|
||||
--no-virt Do not create virtual interface
|
||||
Using this you can't use same wlan interface
|
||||
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
|
||||
(example: US)
|
||||
--freq-band <GHz> Set frequency band: 2.4 or 5 (default: 2.4)
|
||||
@@ -95,18 +97,33 @@ Options:
|
||||
(default: 2)
|
||||
--psk Use 64 hex digits pre-shared-key instead of
|
||||
passphrase
|
||||
--mac-filter Enable Wifi hotspot MAC address filtering
|
||||
--mac-filter-accept Location of Wifi hotspot MAC address filter list
|
||||
--mac-filter Enable WiFi hotspot MAC address filtering
|
||||
--mac-filter-accept Location of WiFi hotspot MAC address filter list
|
||||
(defaults to /etc/hostapd/hostapd.accept)
|
||||
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
|
||||
--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
|
||||
--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:
|
||||
--daemon Run in background
|
||||
@@ -121,9 +138,9 @@ Options:
|
||||
|
||||
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 may cause unwanted packets
|
||||
leakage between 2 networks, which you should be aware of if you
|
||||
want isolated network
|
||||
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
|
||||
|
||||
Examples:
|
||||
$PROGNAME -i eth1
|
||||
@@ -156,6 +173,7 @@ define_global_variables(){
|
||||
SHOW_DNS_QUERY=0 # log dns
|
||||
ETC_HOSTS=0
|
||||
ADDN_HOSTS=
|
||||
DNS_NOCACHE=
|
||||
CONN_IFACE= # which interface user choose to use to create network
|
||||
INTERNET_IFACE= # which interface to get Internet from
|
||||
THISHOSTNAME= # this host's name the DNS tells clients
|
||||
@@ -176,13 +194,19 @@ define_global_variables(){
|
||||
HIDDEN=0 # hidden wifi hotspot
|
||||
WIFI_IFACE=
|
||||
CHANNEL=default
|
||||
HOTSPOT20=0 # For enabling Hotspot 2.0
|
||||
WPA_VERSION=2
|
||||
MAC_FILTER=0
|
||||
MAC_FILTER_ACCEPT=/etc/hostapd/hostapd.accept
|
||||
IEEE80211N=0
|
||||
REQUIREHT=0
|
||||
IEEE80211AC=0
|
||||
REQUIREVHT=0
|
||||
HT_CAPAB='[HT40+]'
|
||||
VHT_CAPAB=
|
||||
VHTCHANNELWIDTH=0
|
||||
VHTSEG0CHINDEX=0
|
||||
VHTSEG1CHINDEX=0
|
||||
DRIVER=nl80211
|
||||
NO_VIRT=0 # not use virtual interface
|
||||
COUNTRY=
|
||||
@@ -195,6 +219,7 @@ define_global_variables(){
|
||||
|
||||
# script variables
|
||||
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
|
||||
USE_IWCONFIG=0 # some device can't use iw
|
||||
|
||||
@@ -231,16 +256,10 @@ parse_user_options(){
|
||||
shift
|
||||
INTERNET_IFACE="$1"
|
||||
shift
|
||||
echo ""
|
||||
echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
|
||||
echo ""
|
||||
;;
|
||||
-n)
|
||||
shift
|
||||
SHARE_METHOD=none
|
||||
echo ""
|
||||
echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
|
||||
echo ""
|
||||
;;
|
||||
--ban-priv)
|
||||
shift
|
||||
@@ -266,9 +285,6 @@ parse_user_options(){
|
||||
--no4)
|
||||
shift
|
||||
NO4=1
|
||||
echo ""
|
||||
echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
|
||||
echo ""
|
||||
;;
|
||||
--p6)
|
||||
shift
|
||||
@@ -331,6 +347,10 @@ parse_user_options(){
|
||||
ADDN_HOSTS="$1"
|
||||
shift
|
||||
;;
|
||||
--dns-nocache)
|
||||
shift
|
||||
DNS_NOCACHE=1
|
||||
;;
|
||||
|
||||
--isolate-clients)
|
||||
shift
|
||||
@@ -374,6 +394,10 @@ parse_user_options(){
|
||||
CHANNEL="$1"
|
||||
shift
|
||||
;;
|
||||
--hs20)
|
||||
shift
|
||||
HOTSPOT20=1
|
||||
;;
|
||||
-w)
|
||||
shift
|
||||
WPA_VERSION="$1"
|
||||
@@ -381,24 +405,47 @@ parse_user_options(){
|
||||
shift
|
||||
;;
|
||||
|
||||
--ieee80211n)
|
||||
--wifi4|--ieee80211n)
|
||||
shift
|
||||
IEEE80211N=1
|
||||
;;
|
||||
--ieee80211ac)
|
||||
--req-ht|--require-ht)
|
||||
shift
|
||||
REQUIREHT=1
|
||||
;;
|
||||
--wifi5|--ieee80211ac)
|
||||
shift
|
||||
IEEE80211AC=1
|
||||
;;
|
||||
--ht_capab)
|
||||
--req-vht|--require-vht)
|
||||
shift
|
||||
REQUIREVHT=1
|
||||
;;
|
||||
--ht-capab)
|
||||
shift
|
||||
HT_CAPAB="$1"
|
||||
shift
|
||||
;;
|
||||
--vht_capab)
|
||||
--vht-capab)
|
||||
shift
|
||||
VHT_CAPAB="$1"
|
||||
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)
|
||||
shift
|
||||
DRIVER="$1"
|
||||
@@ -408,6 +455,11 @@ parse_user_options(){
|
||||
shift
|
||||
NO_VIRT=1
|
||||
;;
|
||||
--virt-name)
|
||||
shift
|
||||
VIRT_NAME="$1"
|
||||
shift
|
||||
;;
|
||||
|
||||
--country)
|
||||
shift
|
||||
@@ -514,6 +566,10 @@ is_interface() {
|
||||
[[ -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
|
||||
local x
|
||||
for x in /sys/class/ieee80211/*; do
|
||||
@@ -635,19 +691,44 @@ get_interface_mac() {
|
||||
cat "/sys/class/net/${1}/address"
|
||||
}
|
||||
|
||||
get_interface_pci_info() { # pci id / model / virtual
|
||||
is_interface "$1" || return
|
||||
|
||||
local device_path
|
||||
local pci_id
|
||||
local pci_full
|
||||
|
||||
device_path="$(readlink -f /sys/class/net/$1)"
|
||||
|
||||
if [[ "$device_path" == "/sys/devices/pci"* ]]; then
|
||||
pci_id="$(echo $device_path | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)"
|
||||
|
||||
if which lspci >/dev/null 2>&1 ; then
|
||||
pci_full="$( lspci -D -nn | grep -E "^$pci_id " )"
|
||||
echo " PCI: $pci_full"
|
||||
else
|
||||
echo " PCI: $pci_id"
|
||||
fi
|
||||
elif [[ "$device_path" == *"/virtual/"* ]]; then
|
||||
echo " virtual interface"
|
||||
fi
|
||||
# TODO usb
|
||||
# TODO current driver
|
||||
}
|
||||
|
||||
alloc_new_vface_name() { # only for wifi
|
||||
local i=0
|
||||
local v_iface_name=
|
||||
while :; do
|
||||
v_iface_name="x$i${WIFI_IFACE}"
|
||||
if ! is_interface ${v_iface_name} && [[ ! -f $COMMON_CONFDIR/vfaces/${v_iface_name} ]]; then
|
||||
mkdir -p $COMMON_CONFDIR/vfaces
|
||||
touch $COMMON_CONFDIR/vfaces/${v_iface_name}
|
||||
echo "${v_iface_name}"
|
||||
return
|
||||
fi
|
||||
i=$((i + 1))
|
||||
done
|
||||
local v_iface_name="$VIRT_NAME"
|
||||
if [[ -z $VIRT_NAME ]]; then
|
||||
while :; do
|
||||
v_iface_name="x$i${WIFI_IFACE}"
|
||||
i=$((i + 1))
|
||||
is_vface_name_allocated ${v_iface_name} || break
|
||||
done
|
||||
fi
|
||||
mkdir -p $COMMON_CONFDIR/vfaces
|
||||
touch $COMMON_CONFDIR/vfaces/${v_iface_name}
|
||||
echo "${v_iface_name}"
|
||||
}
|
||||
|
||||
dealloc_vface_name() {
|
||||
@@ -830,23 +911,83 @@ check_iptables()
|
||||
fi
|
||||
fi
|
||||
}
|
||||
iptables_()
|
||||
|
||||
CUSTOM_CHAINS_4_filter=
|
||||
CUSTOM_CHAINS_4_nat=
|
||||
CUSTOM_CHAINS_6_filter=
|
||||
CUSTOM_CHAINS_6_nat=
|
||||
iptb()
|
||||
{
|
||||
# NETFILTER_XT_MATCH_COMMENT would be a env variable if user wants to disable '-m comment'
|
||||
if [[ "$NETFILTER_XT_MATCH_COMMENT" == "0" ]]; then
|
||||
iptables -w $@
|
||||
else
|
||||
iptables -w $@ -m comment --comment "lnxrouter-$$-$SUBNET_IFACE"
|
||||
local FoS=$1 # 4 | 6
|
||||
shift
|
||||
local Vis=$1 # 'v' | 'n'
|
||||
shift
|
||||
local T=$1 # table
|
||||
shift
|
||||
local ACT=$1 # action: I | A | N . On undo: I or A -> D , N -> F+X
|
||||
shift
|
||||
local CH=$1 # chain
|
||||
shift
|
||||
|
||||
[[ "$IPV6" -ne 1 && "$FoS" == "6" ]] && return
|
||||
|
||||
local CMD_HEAD=""
|
||||
local MOUTH=""
|
||||
local NECK=""
|
||||
local HAND_UN_NC=0
|
||||
local TAIL=""
|
||||
|
||||
local FULL=""
|
||||
local ADD_TO_UNDO=1
|
||||
|
||||
for arr_name in CUSTOM_CHAINS_4_filter CUSTOM_CHAINS_4_nat CUSTOM_CHAINS_6_filter CUSTOM_CHAINS_6_nat
|
||||
do
|
||||
local arr_content
|
||||
eval arr_content=\"\${$arr_name}\"
|
||||
#echo $arr_content
|
||||
|
||||
for w in $arr_content
|
||||
do
|
||||
if [[ "$arr_name" =~ "$FoS" && "$arr_name" =~ "$T" && "$w" == "$CH" ]]; then
|
||||
ADD_TO_UNDO=0
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
|
||||
[[ "$FoS" == "4" ]] && CMD_HEAD="iptables -w "
|
||||
[[ "$FoS" == "6" ]] && CMD_HEAD="ip6tables -w "
|
||||
|
||||
[[ "$Vis" == 'v' ]] && MOUTH="-v"
|
||||
|
||||
NECK="-t ${T}"
|
||||
|
||||
if [[ "$ACT" == "N" ]]; then
|
||||
eval CUSTOM_CHAINS_${FoS}_${T}=\"\${CUSTOM_CHAINS_${FoS}_${T}} ${CH}\"
|
||||
HAND_UN_NC=1
|
||||
fi
|
||||
return $?
|
||||
}
|
||||
ip6tables_()
|
||||
{
|
||||
if [[ "$NETFILTER_XT_MATCH_COMMENT" == "0" ]]; then
|
||||
ip6tables -w $@
|
||||
else
|
||||
ip6tables -w $@ -m comment --comment "lnxrouter-$$-$SUBNET_IFACE"
|
||||
|
||||
|
||||
|
||||
[[ ! "$NETFILTER_XT_MATCH_COMMENT" == "0" ]] && TAIL="-m comment --comment lrt${$}${SUBNET_IFACE}"
|
||||
|
||||
if [[ "$ADD_TO_UNDO" -eq 1 ]]; then
|
||||
if [[ "$ACT" == "I" || "$ACT" == "A" ]]; then
|
||||
echo "$CMD_HEAD $NECK -D ${CH} $@ $TAIL" >> $CONFDIR/undo_iptables.sh
|
||||
fi
|
||||
|
||||
if [[ "$HAND_UN_NC" -eq 1 ]]; then
|
||||
echo "$CMD_HEAD $NECK -F ${CH} $@ $TAIL" >> $CONFDIR/undo_iptables_2.sh
|
||||
echo "$CMD_HEAD $NECK -X ${CH} $@ $TAIL" >> $CONFDIR/undo_iptables_2.sh
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
FULL="$CMD_HEAD $MOUTH $NECK -${ACT} ${CH} $@ $TAIL"
|
||||
#echo $FULL
|
||||
$FULL
|
||||
return $?
|
||||
}
|
||||
|
||||
@@ -861,214 +1002,128 @@ start_nat() {
|
||||
echo
|
||||
echo "iptables: NAT "
|
||||
if [[ $NO4 -eq 0 ]]; then
|
||||
iptables_ -v -t nat -I POSTROUTING -s ${GATEWAY%.*}.0/24 $IPTABLES_NAT_OUT $MASQUERADE_NOTOUT ! -d ${GATEWAY%.*}.0/24 -j MASQUERADE || die
|
||||
iptables_ -v -I FORWARD -i ${SUBNET_IFACE} $IPTABLES_NAT_OUT -s ${GATEWAY%.*}.0/24 -j ACCEPT || die
|
||||
iptables_ -v -I FORWARD -o ${SUBNET_IFACE} $IPTABLES_NAT_IN -d ${GATEWAY%.*}.0/24 -j ACCEPT || die
|
||||
fi
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -v -t nat -I POSTROUTING -s ${PREFIX6}/64 $IPTABLES_NAT_OUT $MASQUERADE_NOTOUT ! -d ${PREFIX6}/64 -j MASQUERADE || die
|
||||
ip6tables_ -v -I FORWARD -i ${SUBNET_IFACE} $IPTABLES_NAT_OUT -s ${PREFIX6}/64 -j ACCEPT || die
|
||||
ip6tables_ -v -I FORWARD -o ${SUBNET_IFACE} $IPTABLES_NAT_IN -d ${PREFIX6}/64 -j ACCEPT || die
|
||||
fi
|
||||
}
|
||||
stop_nat() {
|
||||
echo "iptables: stop NAT"
|
||||
if [[ $NO4 -eq 0 ]]; then
|
||||
iptables_ -t nat -D POSTROUTING -s ${GATEWAY%.*}.0/24 $IPTABLES_NAT_OUT $MASQUERADE_NOTOUT ! -d ${GATEWAY%.*}.0/24 -j MASQUERADE
|
||||
iptables_ -D FORWARD -i ${SUBNET_IFACE} $IPTABLES_NAT_OUT -s ${GATEWAY%.*}.0/24 -j ACCEPT
|
||||
iptables_ -D FORWARD -o ${SUBNET_IFACE} $IPTABLES_NAT_IN -d ${GATEWAY%.*}.0/24 -j ACCEPT
|
||||
fi
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -t nat -D POSTROUTING -s ${PREFIX6}/64 $IPTABLES_NAT_OUT $MASQUERADE_NOTOUT ! -d ${PREFIX6}/64 -j MASQUERADE
|
||||
ip6tables_ -D FORWARD -i ${SUBNET_IFACE} $IPTABLES_NAT_OUT -s ${PREFIX6}/64 -j ACCEPT
|
||||
ip6tables_ -D FORWARD -o ${SUBNET_IFACE} $IPTABLES_NAT_IN -d ${PREFIX6}/64 -j ACCEPT
|
||||
iptb 4 v nat I POSTROUTING -s ${GATEWAY%.*}.0/24 $IPTABLES_NAT_OUT $MASQUERADE_NOTOUT ! -d ${GATEWAY%.*}.0/24 -j MASQUERADE || die
|
||||
iptb 4 v filter I FORWARD -i ${SUBNET_IFACE} $IPTABLES_NAT_OUT -s ${GATEWAY%.*}.0/24 -j ACCEPT || die
|
||||
iptb 4 v filter I FORWARD -o ${SUBNET_IFACE} $IPTABLES_NAT_IN -d ${GATEWAY%.*}.0/24 -j ACCEPT || die
|
||||
fi
|
||||
|
||||
iptb 6 v nat I POSTROUTING -s ${PREFIX6}/64 $IPTABLES_NAT_OUT $MASQUERADE_NOTOUT ! -d ${PREFIX6}/64 -j MASQUERADE || die
|
||||
iptb 6 v filter I FORWARD -i ${SUBNET_IFACE} $IPTABLES_NAT_OUT -s ${PREFIX6}/64 -j ACCEPT || die
|
||||
iptb 6 v filter I FORWARD -o ${SUBNET_IFACE} $IPTABLES_NAT_IN -d ${PREFIX6}/64 -j ACCEPT || die
|
||||
}
|
||||
|
||||
start_ban_lan() {
|
||||
echo
|
||||
echo "iptables: Disallow clients to access LAN"
|
||||
iptables_ -N BANLAN-f-${SUBNET_IFACE} || die
|
||||
iptb 4 n filter N lrt${$}${SUBNET_IFACE}-BLF || die
|
||||
# TODO: allow '--dhcp-dns(6)' address port 53, which can be something needed, e.g. a VPN's internal private IP
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 0.0.0.0/8 -j REJECT || die # TODO: use array
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 10.0.0.0/8 -j REJECT || die
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 100.64.0.0/10 -j REJECT || die
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 127.0.0.0/8 -j REJECT || die
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 169.254.0.0/16 -j REJECT || die
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 172.16.0.0/12 -j REJECT || die
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 192.168.0.0/16 -j REJECT || die
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 224.0.0.0/4 -j REJECT || die
|
||||
iptables_ -v -I BANLAN-f-${SUBNET_IFACE} -d 255.255.255.255 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 0.0.0.0/8 -j REJECT || die # TODO: use array
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 10.0.0.0/8 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 100.64.0.0/10 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 127.0.0.0/8 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 169.254.0.0/16 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 172.16.0.0/12 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 192.168.0.0/16 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 224.0.0.0/4 -j REJECT || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLF -d 255.255.255.255 -j REJECT || die
|
||||
|
||||
iptables_ -I FORWARD -i ${SUBNET_IFACE} -j BANLAN-f-${SUBNET_IFACE} || die
|
||||
iptb 4 n filter I FORWARD -i ${SUBNET_IFACE} -j lrt${$}${SUBNET_IFACE}-BLF || die
|
||||
|
||||
iptables_ -N BANLAN-i-${SUBNET_IFACE}
|
||||
#iptables_ -v -I BANLAN-i-${SUBNET_IFACE} -i ${SUBNET_IFACE} -j REJECT || die
|
||||
iptables_ -v -I BANLAN-i-${SUBNET_IFACE} -i ${SUBNET_IFACE} ! -p icmp -j REJECT || die
|
||||
# ipv6 need icmp to function. TODO: maybe we can block some unneeded icmp to improve security
|
||||
iptb 4 n filter N lrt${$}${SUBNET_IFACE}-BLI || die
|
||||
iptb 4 v filter I lrt${$}${SUBNET_IFACE}-BLI -i ${SUBNET_IFACE} ! -p icmp -j REJECT || die # ipv6 need icmp to function. TODO: maybe we can block some unneeded icmp to improve security
|
||||
|
||||
iptables_ -I INPUT -i ${SUBNET_IFACE} -j BANLAN-i-${SUBNET_IFACE} || die
|
||||
iptb 4 n filter I INPUT -i ${SUBNET_IFACE} -j lrt${$}${SUBNET_IFACE}-BLI || die
|
||||
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -N BANLAN-f-${SUBNET_IFACE} || die
|
||||
ip6tables_ -v -I BANLAN-f-${SUBNET_IFACE} -d fc00::/7 -j REJECT || die
|
||||
ip6tables_ -v -I BANLAN-f-${SUBNET_IFACE} -d fe80::/10 -j REJECT || die
|
||||
ip6tables_ -v -I BANLAN-f-${SUBNET_IFACE} -d ff00::/8 -j REJECT || die
|
||||
ip6tables_ -v -I BANLAN-f-${SUBNET_IFACE} -d ::1 -j REJECT || die
|
||||
ip6tables_ -v -I BANLAN-f-${SUBNET_IFACE} -d ::/128 -j REJECT || die
|
||||
ip6tables_ -v -I BANLAN-f-${SUBNET_IFACE} -d ::ffff:0:0/96 -j REJECT || die
|
||||
ip6tables_ -v -I BANLAN-f-${SUBNET_IFACE} -d ::ffff:0:0:0/96 -j REJECT || die
|
||||
|
||||
ip6tables_ -I FORWARD -i ${SUBNET_IFACE} -j BANLAN-f-${SUBNET_IFACE} || die
|
||||
|
||||
ip6tables_ -N BANLAN-i-${SUBNET_IFACE} || die
|
||||
#ip6tables_ -v -I BANLAN-i-${SUBNET_IFACE} -i ${SUBNET_IFACE} -j REJECT || die
|
||||
ip6tables_ -v -I BANLAN-i-${SUBNET_IFACE} -i ${SUBNET_IFACE} ! -p icmpv6 -j REJECT || die
|
||||
iptb 6 n filter N lrt${$}${SUBNET_IFACE}-BLF || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLF -d fc00::/7 -j REJECT || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLF -d fe80::/10 -j REJECT || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLF -d ff00::/8 -j REJECT || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLF -d ::1 -j REJECT || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLF -d ::/128 -j REJECT || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLF -d ::ffff:0:0/96 -j REJECT || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLF -d ::ffff:0:0:0/96 -j REJECT || die
|
||||
|
||||
ip6tables_ -I INPUT -i ${SUBNET_IFACE} -j BANLAN-i-${SUBNET_IFACE} || die
|
||||
fi
|
||||
}
|
||||
stop_ban_lan() {
|
||||
echo "iptables: Unban clients' LAN access"
|
||||
iptb 6 n filter I FORWARD -i ${SUBNET_IFACE} -j lrt${$}${SUBNET_IFACE}-BLF || die
|
||||
|
||||
iptables_ -D FORWARD -i ${SUBNET_IFACE} -j BANLAN-f-${SUBNET_IFACE}
|
||||
|
||||
iptables_ -F BANLAN-f-${SUBNET_IFACE}
|
||||
iptables_ -X BANLAN-f-${SUBNET_IFACE}
|
||||
|
||||
iptables_ -D INPUT -i ${SUBNET_IFACE} -j BANLAN-i-${SUBNET_IFACE}
|
||||
|
||||
iptables_ -F BANLAN-i-${SUBNET_IFACE}
|
||||
iptables_ -X BANLAN-i-${SUBNET_IFACE}
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -D FORWARD -i ${SUBNET_IFACE} -j BANLAN-f-${SUBNET_IFACE}
|
||||
|
||||
ip6tables_ -F BANLAN-f-${SUBNET_IFACE}
|
||||
ip6tables_ -X BANLAN-f-${SUBNET_IFACE}
|
||||
|
||||
ip6tables_ -D INPUT -i ${SUBNET_IFACE} -j BANLAN-i-${SUBNET_IFACE}
|
||||
|
||||
ip6tables_ -F BANLAN-i-${SUBNET_IFACE}
|
||||
ip6tables_ -X BANLAN-i-${SUBNET_IFACE}
|
||||
fi
|
||||
iptb 6 n filter N lrt${$}${SUBNET_IFACE}-BLI || die
|
||||
iptb 6 v filter I lrt${$}${SUBNET_IFACE}-BLI -i ${SUBNET_IFACE} ! -p icmpv6 -j REJECT || die
|
||||
|
||||
iptb 6 n filter I INPUT -i ${SUBNET_IFACE} -j lrt${$}${SUBNET_IFACE}-BLI || die
|
||||
|
||||
}
|
||||
|
||||
allow_dns_port() {
|
||||
echo
|
||||
echo "iptables: allow DNS"
|
||||
iptables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -d ${GATEWAY} -p tcp -m tcp --dport 53 -j ACCEPT || die
|
||||
iptables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -d ${GATEWAY} -p udp -m udp --dport 53 -j ACCEPT || die
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -d ${GATEWAY6} -p tcp -m tcp --dport 53 -j ACCEPT || die
|
||||
ip6tables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -d ${GATEWAY6} -p udp -m udp --dport 53 -j ACCEPT || die
|
||||
fi
|
||||
}
|
||||
unallow_dns_port() {
|
||||
echo "iptables: unallow DNS"
|
||||
iptables_ -D INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -d ${GATEWAY} -p tcp -m tcp --dport 53 -j ACCEPT
|
||||
iptables_ -D INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -d ${GATEWAY} -p udp -m udp --dport 53 -j ACCEPT
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -D INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -d ${GATEWAY6} -p tcp -m tcp --dport 53 -j ACCEPT
|
||||
ip6tables_ -D INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -d ${GATEWAY6} -p udp -m udp --dport 53 -j ACCEPT
|
||||
fi
|
||||
iptb 4 v filter I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -d ${GATEWAY} -p tcp -m tcp --dport 53 -j ACCEPT || die
|
||||
iptb 4 v filter I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -d ${GATEWAY} -p udp -m udp --dport 53 -j ACCEPT || die
|
||||
iptb 6 v filter I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -d ${GATEWAY6} -p tcp -m tcp --dport 53 -j ACCEPT || die
|
||||
iptb 6 v filter I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -d ${GATEWAY6} -p udp -m udp --dport 53 -j ACCEPT || die
|
||||
}
|
||||
|
||||
|
||||
start_catch_dns() {
|
||||
echo
|
||||
echo "iptables: redirect all TCP/UDP packet that destination port is 53"
|
||||
iptables_ -v -t nat -I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY} -p udp -m udp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
iptables_ -v -t nat -I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY} -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -v -t nat -I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY6} -p udp -m udp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
ip6tables_ -v -t nat -I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY6} -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
fi
|
||||
}
|
||||
stop_catch_dns() {
|
||||
echo "iptables: stop redirecting DNS queries"
|
||||
iptables_ -t nat -D PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY} -p udp -m udp --dport 53 -j REDIRECT --to-ports 53
|
||||
iptables_ -t nat -D PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY} -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 53
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -t nat -D PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY6} -p udp -m udp --dport 53 -j REDIRECT --to-ports 53
|
||||
ip6tables_ -t nat -D PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY6} -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 53
|
||||
fi
|
||||
echo "iptables: redirect DNS queries to this host"
|
||||
iptb 4 v nat I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY} -p udp -m udp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
iptb 4 v nat I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY} -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
|
||||
iptb 6 v nat I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY6} -p udp -m udp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
iptb 6 v nat I PREROUTING -i ${SUBNET_IFACE} ! -d ${GATEWAY6} -p tcp -m tcp --dport 53 -j REDIRECT --to-ports 53 || die
|
||||
}
|
||||
|
||||
|
||||
allow_dhcp() {
|
||||
echo
|
||||
echo "iptables: allow dhcp"
|
||||
iptables_ -v -I INPUT -i ${SUBNET_IFACE} -p udp -m udp --dport 67 -j ACCEPT || die
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -v -I INPUT -i ${SUBNET_IFACE} -p udp -m udp --dport 547 -j ACCEPT || die
|
||||
fi
|
||||
}
|
||||
unallow_dhcp() {
|
||||
echo "iptables: unallow dhcp"
|
||||
iptables_ -D INPUT -i ${SUBNET_IFACE} -p udp -m udp --dport 67 -j ACCEPT
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -D INPUT -i ${SUBNET_IFACE} -p udp -m udp --dport 547 -j ACCEPT
|
||||
fi
|
||||
|
||||
iptb 4 v filter I INPUT -i ${SUBNET_IFACE} -p udp -m udp --dport 67 -j ACCEPT || die
|
||||
iptb 6 v filter I INPUT -i ${SUBNET_IFACE} -p udp -m udp --dport 547 -j ACCEPT || die
|
||||
}
|
||||
|
||||
# TODO: use 'DNAT' instead of '--to-ports' to support other IP
|
||||
start_redsocks() {
|
||||
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
|
||||
iptables_ -t nat -N REDSOCKS-${SUBNET_IFACE} || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 0.0.0.0/8 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 10.0.0.0/8 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 100.64.0.0/10 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 127.0.0.0/8 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 169.254.0.0/16 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 172.16.0.0/12 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 192.168.0.0/16 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 224.0.0.0/4 -j RETURN || die
|
||||
iptables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d 255.255.255.255 -j RETURN || 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 10.0.0.0/8 -j RETURN || die
|
||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 100.64.0.0/10 -j RETURN || die
|
||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 127.0.0.0/8 -j RETURN || die
|
||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 169.254.0.0/16 -j RETURN || die
|
||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 172.16.0.0/12 -j RETURN || die
|
||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 192.168.0.0/16 -j RETURN || die
|
||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 224.0.0.0/4 -j RETURN || die
|
||||
iptb 4 n nat A lrt${$}${SUBNET_IFACE}-TP -d 255.255.255.255 -j RETURN || die
|
||||
|
||||
iptables_ -v -t nat -A REDSOCKS-${SUBNET_IFACE} -p tcp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
iptables_ -v -t nat -A REDSOCKS-${SUBNET_IFACE} -p udp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
iptb 4 v nat A lrt${$}${SUBNET_IFACE}-TP -p tcp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
iptb 4 v nat A lrt${$}${SUBNET_IFACE}-TP -p udp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
|
||||
iptables_ -v -t nat -I PREROUTING -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -j REDSOCKS-${SUBNET_IFACE} || die
|
||||
iptb 4 v nat I PREROUTING -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -j lrt${$}${SUBNET_IFACE}-TP || die
|
||||
|
||||
iptables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -p tcp -m tcp --dport ${TP_PORT} -j ACCEPT || die
|
||||
iptables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -p udp -m udp --dport ${TP_PORT} -j ACCEPT || die
|
||||
iptb 4 v filter I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -p tcp -m tcp --dport ${TP_PORT} -j ACCEPT || die
|
||||
iptb 4 v filter I INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -p udp -m udp --dport ${TP_PORT} -j ACCEPT || die
|
||||
fi
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -t nat -N REDSOCKS-${SUBNET_IFACE} || die
|
||||
ip6tables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d fc00::/7 -j RETURN || die
|
||||
ip6tables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d fe80::/10 -j RETURN || die
|
||||
ip6tables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d ff00::/8 -j RETURN || die
|
||||
ip6tables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d ::1 -j RETURN || die
|
||||
ip6tables_ -t nat -A REDSOCKS-${SUBNET_IFACE} -d :: -j RETURN || die
|
||||
|
||||
ip6tables_ -v -t nat -A REDSOCKS-${SUBNET_IFACE} -p tcp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
ip6tables_ -v -t nat -A REDSOCKS-${SUBNET_IFACE} -p udp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
iptb 6 n nat N lrt${$}${SUBNET_IFACE}-TP || die
|
||||
iptb 6 n nat A lrt${$}${SUBNET_IFACE}-TP -d fc00::/7 -j RETURN || die
|
||||
iptb 6 n nat A lrt${$}${SUBNET_IFACE}-TP -d fe80::/10 -j RETURN || die
|
||||
iptb 6 n nat A lrt${$}${SUBNET_IFACE}-TP -d ff00::/8 -j RETURN || die
|
||||
iptb 6 n nat A lrt${$}${SUBNET_IFACE}-TP -d ::1 -j RETURN || die
|
||||
iptb 6 n nat A lrt${$}${SUBNET_IFACE}-TP -d :: -j RETURN || die
|
||||
|
||||
ip6tables_ -v -t nat -I PREROUTING -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -j REDSOCKS-${SUBNET_IFACE} || die
|
||||
iptb 6 v nat A lrt${$}${SUBNET_IFACE}-TP -p tcp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
iptb 6 v nat A lrt${$}${SUBNET_IFACE}-TP -p udp -j REDIRECT --to-ports ${TP_PORT} || die
|
||||
|
||||
iptb 6 v nat I PREROUTING -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -j lrt${$}${SUBNET_IFACE}-TP || die
|
||||
|
||||
iptb 6 v filter I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -p tcp -m tcp --dport ${TP_PORT} -j ACCEPT || die
|
||||
iptb 6 v filter I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -p udp -m udp --dport ${TP_PORT} -j ACCEPT || die
|
||||
|
||||
ip6tables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -p tcp -m tcp --dport ${TP_PORT} -j ACCEPT || die
|
||||
ip6tables_ -v -I INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -p udp -m udp --dport ${TP_PORT} -j ACCEPT || die
|
||||
fi
|
||||
}
|
||||
stop_redsocks() {
|
||||
echo "iptables: stop transparent proxy"
|
||||
if [[ $NO4 -eq 0 ]]; then
|
||||
iptables_ -t nat -D PREROUTING -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -j REDSOCKS-${SUBNET_IFACE}
|
||||
iptables_ -t nat -F REDSOCKS-${SUBNET_IFACE}
|
||||
iptables_ -t nat -X REDSOCKS-${SUBNET_IFACE}
|
||||
|
||||
iptables_ -D INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -p tcp -m tcp --dport ${TP_PORT} -j ACCEPT
|
||||
iptables_ -D INPUT -i ${SUBNET_IFACE} -s ${GATEWAY%.*}.0/24 -p udp -m udp --dport ${TP_PORT} -j ACCEPT
|
||||
fi
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
ip6tables_ -t nat -D PREROUTING -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -j REDSOCKS-${SUBNET_IFACE}
|
||||
ip6tables_ -t nat -F REDSOCKS-${SUBNET_IFACE}
|
||||
ip6tables_ -t nat -X REDSOCKS-${SUBNET_IFACE}
|
||||
|
||||
ip6tables_ -D INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -p tcp -m tcp --dport ${TP_PORT} -j ACCEPT
|
||||
ip6tables_ -D INPUT -i ${SUBNET_IFACE} -s ${PREFIX6}/64 -p udp -m udp --dport ${TP_PORT} -j ACCEPT
|
||||
fi
|
||||
}
|
||||
|
||||
#---------------------------------------
|
||||
backup_ipv6_bits() {
|
||||
mkdir "$CONFDIR/sys_6_conf_iface" || die "Failed making dir to save interface IPv6 status"
|
||||
@@ -1123,7 +1178,7 @@ backup_interface_status() {
|
||||
|
||||
backup_ipv6_bits
|
||||
|
||||
# TODO : backup ip and others
|
||||
# TODO : ? backup ip and others???
|
||||
|
||||
# nm managing status is saved when nm_set_unmanaged()
|
||||
}
|
||||
@@ -1193,25 +1248,9 @@ _cleanup() {
|
||||
}
|
||||
|
||||
clean_iptables() {
|
||||
|
||||
if [[ "$SHARE_METHOD" == "nat" ]]; then
|
||||
stop_nat
|
||||
elif [[ "$SHARE_METHOD" == "redsocks" ]]; then
|
||||
stop_redsocks
|
||||
fi
|
||||
[[ -f $CONFDIR/undo_iptables.sh ]] && bash $CONFDIR/undo_iptables.sh
|
||||
|
||||
if [[ "$DHCP_DNS" == "gateway" || "$DHCP_DNS6" == "gateway" ]]; then
|
||||
unallow_dns_port
|
||||
fi
|
||||
|
||||
[[ "$CATCH_DNS" -eq 1 ]] && stop_catch_dns
|
||||
|
||||
|
||||
if [[ $NO_DNSMASQ -eq 0 ]]; then
|
||||
unallow_dhcp
|
||||
fi
|
||||
|
||||
[[ "$BANLAN" -eq 1 ]] && stop_ban_lan
|
||||
[[ -f $CONFDIR/undo_iptables_2.sh ]] && bash $CONFDIR/undo_iptables_2.sh
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
@@ -1220,17 +1259,19 @@ cleanup() {
|
||||
echo
|
||||
echo "Doing cleanup.. "
|
||||
kill_processes
|
||||
clean_iptables 2> /dev/null
|
||||
echo "Undoing iptables changes .."
|
||||
clean_iptables > /dev/null
|
||||
_cleanup 2> /dev/null
|
||||
|
||||
pgid=$(ps opgid= $$ |awk '{print $1}' )
|
||||
kill -15 -$pgid
|
||||
sleep 1
|
||||
#pgid=$(ps opgid= $$ |awk '{print $1}' )
|
||||
#echo "Killing PGID $pgid ..."
|
||||
#kill -15 -$pgid
|
||||
#sleep 1
|
||||
echo "Cleaning up done"
|
||||
#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
|
||||
echo "Error occured"
|
||||
[[ -n "$1" ]] && echo -e "\nERROR: $1\n" >&2
|
||||
@@ -1487,7 +1528,7 @@ check_other_functions(){
|
||||
|
||||
##### root test ##### NOTE above don't require root ##########
|
||||
if [[ $(id -u) -ne 0 ]]; then
|
||||
echo "You must run it as root." >&2
|
||||
echo "ERROR: Need root to continue" >&2
|
||||
exit 1
|
||||
fi
|
||||
###### NOTE below require root ##########
|
||||
@@ -1513,7 +1554,7 @@ daemonizing_check(){
|
||||
check_wifi_settings() {
|
||||
|
||||
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
|
||||
fi
|
||||
|
||||
@@ -1529,14 +1570,6 @@ check_wifi_settings() {
|
||||
exit 1
|
||||
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
|
||||
echo "Channel number is greater than 14, assuming 5GHz frequency band"
|
||||
FREQ_BAND=5
|
||||
@@ -1592,6 +1625,18 @@ check_wifi_settings() {
|
||||
fi
|
||||
echo "WARN: If AP doesn't work, read https://github.com/oblique/create_ap/blob/master/howto/realtek.md" >&2
|
||||
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() {
|
||||
@@ -1643,20 +1688,21 @@ prepare_wifi_interface() {
|
||||
|
||||
if [[ $NO_VIRT -eq 0 ]]; then
|
||||
## Will generate virtual wifi interface
|
||||
|
||||
# TODO move this to check_wifi_settings() ?
|
||||
if is_interface_wifi_connected ${WIFI_IFACE}; then
|
||||
WIFI_IFACE_FREQ=$(iw dev ${WIFI_IFACE} link | grep -i freq | awk '{print $2}')
|
||||
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
|
||||
FREQ_BAND=5
|
||||
else
|
||||
FREQ_BAND=2.4
|
||||
fi
|
||||
if [[ $WIFI_IFACE_CHANNEL -ne $CHANNEL ]]; then
|
||||
echo "Channel fallback to ${WIFI_IFACE_CHANNEL}"
|
||||
|
||||
echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
|
||||
|
||||
if [[ $CHANNEL == default ]]; then
|
||||
echo "Use wifi adapter current channel $WIFI_IFACE_CHANNEL as target channel"
|
||||
CHANNEL=$WIFI_IFACE_CHANNEL
|
||||
else
|
||||
echo
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
@@ -1669,13 +1715,28 @@ prepare_wifi_interface() {
|
||||
echo "${VWIFI_IFACE} created"
|
||||
else
|
||||
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
|
||||
|
||||
AP_IFACE=${VWIFI_IFACE}
|
||||
else # no virtual wifi interface, use wifi device interface itself
|
||||
AP_IFACE=${WIFI_IFACE}
|
||||
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() {
|
||||
@@ -1737,6 +1798,10 @@ write_hostapd_conf() {
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [[ $HOTSPOT20 -eq 1 ]]; then
|
||||
echo "hs20=1" >> "$CONFDIR/hostapd.conf"
|
||||
fi
|
||||
|
||||
if [[ $IEEE80211N -eq 1 ]]; then
|
||||
cat <<- EOF >> "$CONFDIR/hostapd.conf"
|
||||
ieee80211n=1
|
||||
@@ -1744,14 +1809,40 @@ write_hostapd_conf() {
|
||||
EOF
|
||||
fi
|
||||
|
||||
if [[ $REQUIREHT -eq 1 ]]; then
|
||||
echo "require_ht=1" >> "$CONFDIR/hostapd.conf"
|
||||
fi
|
||||
|
||||
if [[ $IEEE80211AC -eq 1 ]]; then
|
||||
echo "ieee80211ac=1" >> "$CONFDIR/hostapd.conf"
|
||||
fi
|
||||
|
||||
if [[ $REQUIREVHT -eq 1 ]]; then
|
||||
echo "require_vht=1" >> "$CONFDIR/hostapd.conf"
|
||||
fi
|
||||
|
||||
if [[ -n "$VHT_CAPAB" ]]; then
|
||||
echo "vht_capab=${VHT_CAPAB}" >> "$CONFDIR/hostapd.conf"
|
||||
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
|
||||
echo "wmm_enabled=1" >> "$CONFDIR/hostapd.conf"
|
||||
fi
|
||||
@@ -1771,7 +1862,7 @@ write_hostapd_conf() {
|
||||
rsn_pairwise=CCMP
|
||||
EOF
|
||||
else
|
||||
echo "WARN: Wifi is not protected by password" >&2
|
||||
echo "WARN: WiFi is not protected by password" >&2
|
||||
fi
|
||||
chmod 600 "$CONFDIR/hostapd.conf"
|
||||
}
|
||||
@@ -1845,6 +1936,10 @@ write_dnsmasq_conf() {
|
||||
no-poll
|
||||
EOF
|
||||
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
|
||||
cat <<- EOF >> "$CONFDIR/dnsmasq.conf"
|
||||
listen-address=${GATEWAY6}
|
||||
@@ -1977,8 +2072,7 @@ echo
|
||||
echo "PID: $$"
|
||||
|
||||
TARGET_IFACE="$(decide_target_interface)" || exit 1 # judge wired (-i CONN_IFACE) or wireless hotspot (--ap $WIFI_IFACE)
|
||||
echo "Target interface is ${TARGET_IFACE} ($(get_interface_mac $TARGET_IFACE))"
|
||||
# TODO: show interface type, device model and pci/usb id (hwdata pci.ids), current driver
|
||||
echo "Target interface is ${TARGET_IFACE} ($(get_interface_mac $TARGET_IFACE)) $(get_interface_pci_info $TARGET_IFACE)"
|
||||
|
||||
if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then
|
||||
NEW_MACADDR="$(generate_random_mac)"
|
||||
@@ -2057,25 +2151,33 @@ fi
|
||||
|
||||
check_iptables
|
||||
|
||||
echo "NOTICE: Not showing all operations done to iptables rules"
|
||||
|
||||
[[ "$NO4" -eq 1 ]] && echo -e "\nWARN: Since you're using in this mode (no IPv4 Internet), make sure you've read Notice 1\n" >&2
|
||||
|
||||
# enable Internet sharing
|
||||
if [[ "$SHARE_METHOD" == "none" ]]; then
|
||||
|
||||
echo "No Internet sharing"
|
||||
|
||||
echo -e "\nWARN: Since you're using in this mode (no Internet share), make sure you've read Notice 1\n" >&2
|
||||
|
||||
[[ "$BANLAN" -eq 1 ]] && start_ban_lan
|
||||
|
||||
elif [[ "$SHARE_METHOD" == "nat" ]]; then
|
||||
|
||||
[[ "$INTERNET_IFACE" ]] && echo -e "\nWARN: Since you're using in this mode (specify Internet interface), make sure you've read Notice 1\n" >&2
|
||||
|
||||
[[ "$INTERNET_IFACE" && "$dnsmasq_NO_DNS" -eq 0 ]] && echo -e "\nWARN: You specified Internet interface but this host is providing local DNS. In some unexpected case (eg. mistaken configurations), queries may leak to other interfaces, which you should be aware of.\n" >&2
|
||||
|
||||
start_nat
|
||||
|
||||
[[ "$BANLAN" -eq 1 ]] && start_ban_lan
|
||||
|
||||
echo 1 > "/proc/sys/net/ipv4/ip_forward" || die "Failed enabling system ipv4 forwarding"
|
||||
echo 1 > "/proc/sys/net/ipv4/ip_forward" || die "Failed enabling system ipv4 forwarding" # TODO maybe uneeded in '--no4' mode
|
||||
|
||||
if [[ $IPV6 -eq 1 ]]; then
|
||||
echo 1 > "/proc/sys/net/ipv6/conf/all/forwarding" || die "Failed enabling system ipv6 forwarding"
|
||||
echo 1 > "/proc/sys/net/ipv6/conf/all/forwarding" || die "Failed enabling system ipv6 forwarding" # TODO if '-o' used, set only 2 interfaces' bits
|
||||
fi
|
||||
|
||||
# to enable clients to establish PPTP connections we must
|
||||
@@ -2106,7 +2208,7 @@ fi
|
||||
[[ $NO_DNSMASQ -eq 0 ]] && ( allow_dhcp ; start_dnsmasq )
|
||||
|
||||
echo
|
||||
echo "== Setting up completed, now linux-router is working =="
|
||||
echo "== Setting up completed, now linux-router should be working =="
|
||||
|
||||
#============================================================
|
||||
#============================================================
|
||||
|
||||
Reference in New Issue
Block a user