This commit is contained in:
0x07CB 2022-09-03 02:18:38 +00:00 committed by GitHub
commit a15043cfd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 160 additions and 13 deletions

View File

@ -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*
@ -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 <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
@ -317,21 +317,22 @@ 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:
--ap <wifi interface> <SSID>
Create WiFi access point
-p, --password <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
Using this you can't use same wlan interface
@ -350,12 +351,12 @@ 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
Instance managing:
@ -397,6 +398,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
@ -409,7 +420,6 @@ On exit of a linux-router instance, script **will do cleanup**, i.e. undo most c
- iw
- iwconfig (you only need this if 'iw' can not recognize your adapter)
- haveged (optional)
- qrencode (optional)
## TODO

View File

@ -0,0 +1,14 @@
[Unit]
Description=Linux Router (WiFi 2 Ethernet)
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=5
User=root
ExecStart=/usr/bin/lnxrouter -i eth0 -o wlan0 --random-mac
[Install]
WantedBy=multi-user.target

113
install.sh Normal file
View File

@ -0,0 +1,113 @@
#!/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
install_packages haveged
install_packages dnsmasq
install_packages 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 script to /opt/lnxrouter/bin
sudo cp lnxrouter /opt/lnxrouter/bin/lnxrouter
# 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 /usr/bin/lnxrouter
# display "It's done!" in yellow
echo -e "\e[33mIt's done!\e[0m"

View File

@ -67,6 +67,7 @@ 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
@ -80,7 +81,7 @@ Options:
Create WiFi access point
-p, --password <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
@ -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
@ -1828,6 +1834,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}