mirror of
https://github.com/garywill/linux-router.git
synced 2025-12-30 18:58:28 +01:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
718a1752f1 | ||
|
|
5dcfacc418 | ||
|
|
0c85f00297 | ||
|
|
a2fcbc4781 | ||
|
|
63cd88b5fc | ||
|
|
957ed25f07 | ||
|
|
183cf44934 | ||
|
|
4e92b3ebf5 | ||
|
|
992ad00ca1 | ||
|
|
9d874dbe88 | ||
|
|
b94cf7c43f | ||
|
|
0acb16dbaa | ||
|
|
73441c4ed3 | ||
|
|
8527e1a9b6 | ||
|
|
18a57119b9 | ||
|
|
7f1ae6282e | ||
|
|
4515dde9b4 |
116
README.md
116
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)
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
Basic features:
|
||||
@@ -61,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
|
||||
@@ -98,7 +124,7 @@ sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [26
|
||||
|
||||
</details>
|
||||
|
||||
### LAN without Internet
|
||||
### Create LAN without providing Internet
|
||||
|
||||
<details>
|
||||
|
||||
@@ -342,7 +368,7 @@ Options:
|
||||
Using this you can't use same wlan interface
|
||||
for both Internet and AP
|
||||
--virt-name <name> Set name of virtual interface
|
||||
-c <channel> Channel number (default: 1)
|
||||
-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)
|
||||
@@ -356,13 +382,28 @@ Options:
|
||||
(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
|
||||
@@ -374,15 +415,7 @@ Options:
|
||||
--stop <id> Stop a running instance
|
||||
For <id> you can use PID or subnet interface name.
|
||||
You can get them with '--list-running'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
## 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
|
||||
@@ -403,28 +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
|
||||
6. WiFi country code, if user assigns
|
||||
|
||||
## Install
|
||||
## Meet contributor(s) and become one of them
|
||||
|
||||
1-file-script. Download and run (meet the dependencies).
|
||||
Visit [**my homepage** 🏡](https://garywill.github.io) to see **more tools and projects** 🛠️.
|
||||
|
||||
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:
|
||||
> [❤️ 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 (^_^ ) 🍻
|
||||
|
||||
| Linux distro | |
|
||||
| ------------ | ---------------------------------------------------------------------------------------------------------- |
|
||||
| Any | download [1-file-script](https://raw.githubusercontent.com/garywill/linux-router/master/lnxrouter) and run |
|
||||
🤝 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.
|
||||
|
||||
## Dependencies
|
||||
👨💻 You can be contributor, too!
|
||||
|
||||
- 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)
|
||||
- 🍃 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
|
||||
|
||||
@@ -496,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](#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!
|
||||
|
||||
144
lnxrouter
144
lnxrouter
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=0.6.7
|
||||
VERSION=0.7.1
|
||||
PROGNAME="$(basename $0)"
|
||||
|
||||
export LC_ALL=C
|
||||
@@ -88,7 +88,7 @@ Options:
|
||||
Using this you can't use same wlan interface
|
||||
for both Internet and AP
|
||||
--virt-name <name> Set name of virtual interface
|
||||
-c <channel> Channel number (default: 1)
|
||||
-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)
|
||||
@@ -102,13 +102,28 @@ Options:
|
||||
(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
|
||||
@@ -179,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=
|
||||
@@ -373,6 +394,10 @@ parse_user_options(){
|
||||
CHANNEL="$1"
|
||||
shift
|
||||
;;
|
||||
--hs20)
|
||||
shift
|
||||
HOTSPOT20=1
|
||||
;;
|
||||
-w)
|
||||
shift
|
||||
WPA_VERSION="$1"
|
||||
@@ -380,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"
|
||||
@@ -1506,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
|
||||
|
||||
@@ -1522,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
|
||||
@@ -1648,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
|
||||
|
||||
@@ -1687,6 +1728,15 @@ prepare_wifi_interface() {
|
||||
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() {
|
||||
@@ -1748,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
|
||||
@@ -1755,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
|
||||
@@ -1910,7 +1990,7 @@ run_wifi_ap_processes() {
|
||||
# sleep 1
|
||||
#done
|
||||
#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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user