From c2da43250ece2e1caf5950a5321ba8d4617ee2ac Mon Sep 17 00:00:00 2001 From: garywill Date: Sun, 3 Apr 2022 17:46:24 +0800 Subject: [PATCH 1/9] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e01173..a2c10f8 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ 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* From e8284c5398c6d41d64b6c57619165d351bb561d2 Mon Sep 17 00:00:00 2001 From: garywill Date: Sun, 3 Apr 2022 17:46:48 +0800 Subject: [PATCH 2/9] add "Install" section in readme --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index a2c10f8..a0c7256 100644 --- a/README.md +++ b/README.md @@ -397,6 +397,16 @@ 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 + +1-file-script. Download and run (meet the dependencies). + +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 | + ## Dependencies - bash From 433b3b8d3918cb5df7247268f35793ae484faa88 Mon Sep 17 00:00:00 2001 From: garywill Date: Sun, 3 Apr 2022 18:03:51 +0800 Subject: [PATCH 3/9] add --dns-nocache option --- README.md | 19 ++++++++++--------- lnxrouter | 10 ++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a0c7256..63aab3e 100644 --- a/README.md +++ b/README.md @@ -284,17 +284,17 @@ Options: queries to other interfaces) -n Do not provide Internet (See Notice 1) --ban-priv Disallow clients to access my private network - + -g 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 Set IPv6 LAN address prefix (length 64) (example: 'fd00:0:0:5::' or '5' shortly) Using this enables '-6' - + --dns || DNS server's upstream DNS. Use ',' to seperate multiple servers @@ -317,21 +317,22 @@ Options: -d DNS server will take into account /etc/hosts -e DNS server will take into account additional hosts file - + --dns-nocache DNS server no cache + --mac Set MAC address --random-mac Use random MAC address - + --tp Transparent proxy, redirect non-LAN TCP and UDP traffic to port. (usually used with '--dns') - + WiFi hotspot options: --ap Create WiFi access point -p, --password WiFi password --qr Show WiFi QR code in terminal - + --hidden Hide access point (not broadcast SSID) --no-virt Do not create virtual interface Using this you can't use same wlan interface @@ -350,12 +351,12 @@ Options: (defaults to /etc/hostapd/hostapd.accept) --hostapd-debug 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 capabilities (default: [HT40+]) --vht_capab VHT capabilities - + --no-haveged Do not run haveged automatically when needed Instance managing: diff --git a/lnxrouter b/lnxrouter index a8bdde3..d6eb8b1 100755 --- a/lnxrouter +++ b/lnxrouter @@ -67,6 +67,7 @@ Options: -d DNS server will take into account /etc/hosts -e DNS server will take into account additional hosts file + --dns-nocache DNS server no cache --mac Set MAC address --random-mac Use random MAC address @@ -156,6 +157,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 @@ -322,6 +324,10 @@ parse_user_options(){ ADDN_HOSTS="$1" shift ;; + --dns-nocache) + shift + DNS_NOCACHE=1 + ;; --isolate-clients) shift @@ -1822,6 +1828,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} From 9e1d985623e92a507c6eba93e0bfddb25e3e6f01 Mon Sep 17 00:00:00 2001 From: garywill Date: Sun, 3 Apr 2022 18:05:05 +0800 Subject: [PATCH 4/9] move 'qrencode' from readme dependency to cli usage note --- README.md | 3 +-- lnxrouter | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 63aab3e..a144074 100644 --- a/README.md +++ b/README.md @@ -331,7 +331,7 @@ Options: Create WiFi access point -p, --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) --no-virt Do not create virtual interface @@ -420,7 +420,6 @@ I'm currently not packaging for any distro. If you do, open a PR and add the lin - iw - iwconfig (you only need this if 'iw' can not recognize your adapter) - haveged (optional) - - qrencode (optional) ## TODO diff --git a/lnxrouter b/lnxrouter index d6eb8b1..7e5fda1 100755 --- a/lnxrouter +++ b/lnxrouter @@ -81,7 +81,7 @@ Options: Create WiFi access point -p, --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) --no-virt Do not create virtual interface From 0061d4f481983999c812206e0f227b5d72581b92 Mon Sep 17 00:00:00 2001 From: 0x07CB <83157348+0x07CB@users.noreply.github.com> Date: Sun, 28 Aug 2022 00:42:28 +0200 Subject: [PATCH 5/9] first update --- exemples/services/lnxrouter-wifi2eth.service | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 exemples/services/lnxrouter-wifi2eth.service diff --git a/exemples/services/lnxrouter-wifi2eth.service b/exemples/services/lnxrouter-wifi2eth.service new file mode 100644 index 0000000..9baf8c1 --- /dev/null +++ b/exemples/services/lnxrouter-wifi2eth.service @@ -0,0 +1,14 @@ +[Unit] +Description=Linux Router (WiFi 2 Ethernet) +After=network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +Restart=always +RestartSec=5 +User=nadege +ExecStart=/usr/bin/bash -c /usr/bin/lnxrouter -i eth0 -o wlan0 --random-mac + +[Install] +WantedBy=multi-user.target \ No newline at end of file From ceae3afe4b604abed2e7f917b6d8c6148247ecd4 Mon Sep 17 00:00:00 2001 From: 0x07CB <83157348+0x07CB@users.noreply.github.com> Date: Sun, 28 Aug 2022 00:52:34 +0200 Subject: [PATCH 6/9] first update --- exemples/services/lnxrouter-wifi2eth.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exemples/services/lnxrouter-wifi2eth.service b/exemples/services/lnxrouter-wifi2eth.service index 9baf8c1..34513d0 100644 --- a/exemples/services/lnxrouter-wifi2eth.service +++ b/exemples/services/lnxrouter-wifi2eth.service @@ -7,8 +7,8 @@ StartLimitIntervalSec=0 Type=simple Restart=always RestartSec=5 -User=nadege -ExecStart=/usr/bin/bash -c /usr/bin/lnxrouter -i eth0 -o wlan0 --random-mac +User=spongebob +ExecStart=/usr/bin/lnxrouter -i eth0 -o wlan0 --random-mac [Install] WantedBy=multi-user.target \ No newline at end of file From 38d8608f2abacb51f4505d8a20a247e12f21a73b Mon Sep 17 00:00:00 2001 From: 0x07CB <83157348+0x07CB@users.noreply.github.com> Date: Sun, 28 Aug 2022 05:44:08 +0200 Subject: [PATCH 7/9] Update lnxrouter-wifi2eth.service --- exemples/services/lnxrouter-wifi2eth.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exemples/services/lnxrouter-wifi2eth.service b/exemples/services/lnxrouter-wifi2eth.service index 34513d0..2a024af 100644 --- a/exemples/services/lnxrouter-wifi2eth.service +++ b/exemples/services/lnxrouter-wifi2eth.service @@ -7,8 +7,8 @@ StartLimitIntervalSec=0 Type=simple Restart=always RestartSec=5 -User=spongebob +User=root ExecStart=/usr/bin/lnxrouter -i eth0 -o wlan0 --random-mac [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target From d74b471b73265d4524ce299252ac407f2430ff1d Mon Sep 17 00:00:00 2001 From: rick sanchez Date: Fri, 2 Sep 2022 17:38:20 +0200 Subject: [PATCH 8/9] update : creation of an first install.sh script --- install.sh | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..f406857 --- /dev/null +++ b/install.sh @@ -0,0 +1,109 @@ +#!/bin/bash +# This script will install the dependencies for the project +# Author: Rick Sanchez +# Date: 2/9/2022 + +linux_install_with_package_manager() { + # if the OS is debian/ubuntu use apt-get to install $1 + if [ -f /etc/debian_version ]; then + sudo apt-get install -y $1 + # elif the OS is archlinux use pacman to install $1 + elif [ -f /etc/arch-release ]; then + sudo pacman -S --noconfirm $1 + # elif the OS is redhat/fedora use yum to install $1 + elif [ -f /etc/redhat-release ]; then + sudo yum install -y $1 + else + echo "OS not supported" + exit 1 + fi +} + +linux_update_package_manager(){ + if [ -f /etc/debian_version ]; then + sudo apt-get update + elif [ -f /etc/arch-release ]; then + sudo pacman -Syu + elif [ -f /etc/redhat-release ]; then + sudo yum update + else + echo "OS not supported" + exit 1 + fi +} + +# update the packager appropriately for the OS and architecture +if [ "$(uname)" == "Darwin" ]; then + export PACKAGER="macosx" +elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + export PACKAGER="linux" +fi + +# update the architecture appropriately for the OS and architecture +if [ "$(uname -m)" == "x86_64" ]; then + export ARCH="amd64" +elif [ "$(uname -m)" == "i686" ]; then + export ARCH="386" +fi + +# if the var $PACKAGER is not set, exit with an error +if [ -z "$PACKAGER" ]; then + echo "Unable to determine the packager for this OS and architecture." + exit 1 +else +# else call the appropriate package manager to install + if [[ "$PACKAGER" == "linux" ]]; then + echo 'linux package manager update...' + linux_update_package_manager + echo 'linux package manager install...' + linux_install_with_package_manager python3 + elif [[ "$PACKAGER" == "macosx" ]]; then + if [ -f /usr/local/bin/brew ]; then + echo "Homebrew is already installed so brew update and brew upgrade" + echo "Homebrew installation skipped." + brew update + brew install python@3.9 pipenv + else + echo "Homebrew is not installed. Installation of homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + echo "Now installing, brew update and install python@3.9 and pipenv..." + brew update + brew install python@3.9 pipenv + fi + fi +fi + +# function to install packages with the appropriate package manager, linux, mac, fedora, etc. +function install_packages() { + if [ "$(uname)" == "Darwin" ]; then + brew install $1 + elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then + #detect linux branch based + linux_install_with_package_manager $1 + elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then + echo "Windows" + else + echo "Unknown OS" + fi +} + +# install the packages +install_packages hostapd haveged dnsmasq qrencode + +# make the /opt/lnxrouter directory +sudo mkdir -p /opt/lnxrouter + +# make the /opt/lnxrouter/bin directory +sudo mkdir -p /opt/lnxrouter/bin + +# copy the lnxrouter.sh script to /opt/lnxrouter/bin +sudo cp lnxrouter.sh /opt/lnxrouter/bin + +# change the permissions on the lnxrouter.sh script +sudo chmod 755 /opt/lnxrouter/bin/lnxrouter.sh + +# create symbolic link to the lnxrouter.sh script +sudo ln -s /opt/lnxrouter/bin/lnxrouter.sh /usr/local/bin/lnxrouter + +# display "It's done!" in yellow +echo -e "\e[33mIt's done!\e[0m" From a09a253938be9e3f89c414bd80dadf803622bfd7 Mon Sep 17 00:00:00 2001 From: 0x07cb <83157348+0x07CB@users.noreply.github.com> Date: Fri, 2 Sep 2022 17:51:41 +0200 Subject: [PATCH 9/9] update of the install.sh script to fix errors --- install.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index f406857..3e2c861 100644 --- a/install.sh +++ b/install.sh @@ -88,7 +88,10 @@ function install_packages() { } # install the packages -install_packages hostapd haveged dnsmasq qrencode +install_packages hostapd +install_packages haveged +install_packages dnsmasq +install_packages qrencode # make the /opt/lnxrouter directory sudo mkdir -p /opt/lnxrouter @@ -96,14 +99,15 @@ sudo mkdir -p /opt/lnxrouter # make the /opt/lnxrouter/bin directory sudo mkdir -p /opt/lnxrouter/bin -# copy the lnxrouter.sh script to /opt/lnxrouter/bin -sudo cp lnxrouter.sh /opt/lnxrouter/bin +# copy the lnxrouter script to /opt/lnxrouter/bin +sudo cp lnxrouter /opt/lnxrouter/bin/lnxrouter -# change the permissions on the lnxrouter.sh script -sudo chmod 755 /opt/lnxrouter/bin/lnxrouter.sh +# change the permissions on the lnxrouter script +sudo chown -R $USER:$USER /opt/lnxrouter/ +sudo chmod a+x /opt/lnxrouter/bin/lnxrouter # create symbolic link to the lnxrouter.sh script -sudo ln -s /opt/lnxrouter/bin/lnxrouter.sh /usr/local/bin/lnxrouter +sudo ln -s /opt/lnxrouter/bin/lnxrouter /usr/bin/lnxrouter # display "It's done!" in yellow echo -e "\e[33mIt's done!\e[0m"