mirror of
https://github.com/garywill/linux-router.git
synced 2025-12-30 10:48:28 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
200b6d4451 | ||
|
|
2ea1dfd5b7 | ||
|
|
204756cffb | ||
|
|
e1ccfac40c |
47
README.md
47
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*
|
||||
|
||||
@@ -138,7 +138,7 @@ sudo lnxrouter -i lxcbr5
|
||||
|
||||
### Transparent proxy
|
||||
|
||||
All clients' Internet traffic go through, for example, Tor (notice this example is NOT an anonymity use)
|
||||
All clients' Internet traffic go through, for example, Tor
|
||||
|
||||
<details>
|
||||
|
||||
@@ -155,10 +155,6 @@ 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
|
||||
@@ -177,7 +173,7 @@ sudo lnxrouter -i eth1 \
|
||||
|
||||
</details>
|
||||
|
||||
> Linux-router comes with no warranty. Use on your own risk
|
||||
> This script comes with no warrenty. Use on your own risk
|
||||
|
||||
### Use as transparent proxy for LXD
|
||||
|
||||
@@ -288,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
|
||||
@@ -321,27 +317,25 @@ 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(not tested) traffic to
|
||||
port. (usually used with '--dns')
|
||||
|
||||
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 (need qrencode)
|
||||
|
||||
--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
|
||||
for both Internet and AP
|
||||
--virt-name <name> Set name of virtual interface
|
||||
-c <channel> Channel number (default: 1)
|
||||
--country <code> Set two-letter country code for regularity
|
||||
(example: US)
|
||||
@@ -356,12 +350,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:
|
||||
@@ -403,16 +397,6 @@ 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
|
||||
@@ -425,6 +409,7 @@ 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
|
||||
|
||||
|
||||
141
lnxrouter
141
lnxrouter
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=0.6.7
|
||||
VERSION=0.6.6
|
||||
PROGNAME="$(basename $0)"
|
||||
|
||||
export LC_ALL=C
|
||||
@@ -67,27 +67,25 @@ 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(not tested) traffic to
|
||||
port. (usually used with '--dns')
|
||||
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 (need qrencode)
|
||||
--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
|
||||
for both Internet and AP
|
||||
--virt-name <name> Set name of virtual interface
|
||||
-c <channel> Channel number (default: 1)
|
||||
--country <code> Set two-letter country code for regularity
|
||||
(example: US)
|
||||
@@ -158,7 +156,6 @@ 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
|
||||
@@ -198,7 +195,6 @@ 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
|
||||
|
||||
@@ -326,10 +322,6 @@ parse_user_options(){
|
||||
ADDN_HOSTS="$1"
|
||||
shift
|
||||
;;
|
||||
--dns-nocache)
|
||||
shift
|
||||
DNS_NOCACHE=1
|
||||
;;
|
||||
|
||||
--isolate-clients)
|
||||
shift
|
||||
@@ -407,11 +399,6 @@ parse_user_options(){
|
||||
shift
|
||||
NO_VIRT=1
|
||||
;;
|
||||
--virt-name)
|
||||
shift
|
||||
VIRT_NAME="$1"
|
||||
shift
|
||||
;;
|
||||
|
||||
--country)
|
||||
shift
|
||||
@@ -518,10 +505,6 @@ 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
|
||||
@@ -668,19 +651,20 @@ get_interface_pci_info() { # pci id / model / virtual
|
||||
# TODO current driver
|
||||
}
|
||||
|
||||
|
||||
alloc_new_vface_name() { # only for wifi
|
||||
local i=0
|
||||
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}"
|
||||
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
|
||||
}
|
||||
|
||||
dealloc_vface_name() {
|
||||
@@ -1037,7 +1021,7 @@ allow_dhcp() {
|
||||
# TODO: use 'DNAT' instead of '--to-ports' to support other IP
|
||||
start_redsocks() {
|
||||
echo
|
||||
echo "iptables: transparent proxy non-LAN TCP and UDP(not tested) traffic to port ${TP_PORT}"
|
||||
echo "iptables: transparent proxy non-LAN TCP/UDP traffic to port ${TP_PORT}"
|
||||
if [[ $NO4 -eq 0 ]]; then
|
||||
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
|
||||
@@ -1223,7 +1207,7 @@ cleanup() {
|
||||
#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
|
||||
@@ -1585,18 +1569,6 @@ 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() {
|
||||
@@ -1642,6 +1614,10 @@ decide_ip_addresses() {
|
||||
}
|
||||
|
||||
prepare_wifi_interface() {
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
echo "Trying to set power_save off ..."
|
||||
if [[ $USE_IWCONFIG -eq 0 ]]; then
|
||||
iw dev ${WIFI_IFACE} set power_save off
|
||||
fi
|
||||
@@ -1664,7 +1640,9 @@ prepare_wifi_interface() {
|
||||
echo
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
sleep 6
|
||||
echo; echo; echo;
|
||||
echo "Creating a virtual WiFi interface... "
|
||||
VWIFI_IFACE=$(alloc_new_vface_name)
|
||||
if iw dev ${WIFI_IFACE} interface add ${VWIFI_IFACE} type __ap; then
|
||||
@@ -1674,13 +1652,7 @@ prepare_wifi_interface() {
|
||||
echo "${VWIFI_IFACE} created"
|
||||
else
|
||||
VWIFI_IFACE=
|
||||
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
|
||||
die "Failed creating virtual WiFi interface. Maybe your WiFi adapter does not fully support virtual interfaces. Try again with '--no-virt'"
|
||||
fi
|
||||
|
||||
AP_IFACE=${VWIFI_IFACE}
|
||||
@@ -1856,10 +1828,6 @@ 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}
|
||||
@@ -1989,6 +1957,8 @@ phead
|
||||
phead2
|
||||
echo
|
||||
|
||||
echo " ============ In dev branch for issue #12 ==========="
|
||||
|
||||
echo "PID: $$"
|
||||
|
||||
TARGET_IFACE="$(decide_target_interface)" || exit 1 # judge wired (-i CONN_IFACE) or wireless hotspot (--ap $WIFI_IFACE)
|
||||
@@ -2012,10 +1982,33 @@ init_trap
|
||||
|
||||
init_conf_dirs # CONFDIR , COMMON_CONFDIR . make dir
|
||||
|
||||
echo -e "\nDistro:"
|
||||
cat /etc/os-release
|
||||
|
||||
echo -e "\nKernel:"
|
||||
uname -a
|
||||
echo
|
||||
|
||||
echo "setting NM log level: nmcli general logging level TRACE domains ALL"
|
||||
nmcli general logging level TRACE domains ALL
|
||||
|
||||
echo "Logging journalctl -f"
|
||||
journalctl -f &
|
||||
echo $! > $CONFDIR/journalctl.pid
|
||||
|
||||
echo "Logging dmesg -W"
|
||||
dmesg -W &
|
||||
echo $! > $CONFDIR/dmesg.pid
|
||||
|
||||
echo "Logging wpa_supplicant.log"
|
||||
tail -f /var/log/wpa_supplicant.log &
|
||||
echo $! > $CONFDIR/wpa_supplicant_log.pid
|
||||
|
||||
[[ $WIFI_IFACE ]] && prepare_wifi_interface # this will create virtual ap interface (if needed) and set VWIFI_IFACE and AP_IFACE (if success)
|
||||
|
||||
SUBNET_IFACE="$(decide_subnet_interface)" # SUBNET_IFACE can be TARGET_IFACE (wired) or AP_IFACE (ap) .this is after prepare_wifi_interface()
|
||||
echo "$SUBNET_IFACE" > "$CONFDIR/subn_iface"
|
||||
ip addr show dev ${SUBNET_IFACE}
|
||||
|
||||
# if virtual wifi interface, will be destroyed, so only need to save status when not
|
||||
[[ -z $VWIFI_IFACE ]] && backup_interface_status
|
||||
@@ -2035,6 +2028,10 @@ fi
|
||||
#===================================================
|
||||
#===================================================
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
ip addr show dev ${SUBNET_IFACE}
|
||||
echo "Trying to set NM unmanage ..."
|
||||
# set interface unmanaged by networkManager
|
||||
if [[ $NM_RUNNING -eq 1 ]] && nm_knows $TARGET_IFACE; then # if nm knows target iface, should know subnet iface too. but need to wait until nm finds subnet iface (waiting code is in nm_set_unmanaged()
|
||||
nm_set_unmanaged ${SUBNET_IFACE} # will write NM_UNM_LIST
|
||||
@@ -2043,19 +2040,47 @@ fi
|
||||
[[ $NO_DNSMASQ -eq 0 ]] && write_dnsmasq_conf
|
||||
#===========================
|
||||
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
ip addr show dev ${SUBNET_IFACE}
|
||||
echo "Trying to set ${SUBNET_IFACE} down ..."
|
||||
# initialize subnet interface
|
||||
# take subnet interface down first
|
||||
ip link set down dev ${SUBNET_IFACE} || die "Failed setting ${SUBNET_IFACE} down"
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
ip addr show dev ${SUBNET_IFACE}
|
||||
echo "Trying to flush ${SUBNET_IFACE} ..."
|
||||
# flush old IPs of subnet interface
|
||||
ip addr flush ${SUBNET_IFACE} || die "Failed flush ${SUBNET_IFACE} IP"
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
ip addr show dev ${SUBNET_IFACE}
|
||||
dealwith_mac # setting MAC should be after setting NM unmanaged
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
ip addr show dev ${SUBNET_IFACE}
|
||||
echo "Trying to check and do rfkill unblock ..."
|
||||
[[ $WIFI_IFACE ]] && check_rfkill_unblock_wifi
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
ip addr show dev ${SUBNET_IFACE}
|
||||
echo "Trying to bring interface ${SUBNET_IFACE} up ..."
|
||||
# bring subnet interface up
|
||||
ip link set up dev ${SUBNET_IFACE} || die "Failed bringing ${SUBNET_IFACE} up"
|
||||
|
||||
sleep 1
|
||||
echo; echo; echo;
|
||||
echo "Finished test. Exiting ..."
|
||||
clean_exit
|
||||
exit
|
||||
|
||||
|
||||
# hostapd , haveged
|
||||
[[ $WIFI_IFACE ]] && run_wifi_ap_processes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user