Compare commits

..

No commits in common. "3d3a63d53b54672fb775714397e3497bccba899f" and "9790d3117bdb6f955bb0e598dd33e5259d603c19" have entirely different histories.

2 changed files with 47 additions and 48 deletions

View File

@ -66,7 +66,7 @@ Internet----(eth0/wlan0)-Linux-(virtual interface)-----VM/container
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. 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 > 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 | | | Linux distro | |
| ------------ | ---------------------------------------------------------------------------------------------------------- | | ------------ | ---------------------------------------------------------------------------------------------------------- |
@ -91,7 +91,7 @@ I'm currently not packaging for any distro. If you do, open a PR and add the lin
### Provide Internet to an interface ### Provide Internet to an interface
```bash ```
sudo lnxrouter -i eth1 sudo lnxrouter -i eth1
``` ```
@ -99,7 +99,7 @@ no matter which interface (other than `eth1`) you're getting Internet from.
### Create WiFi hotspot ### Create WiFi hotspot
```bash ```
sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase
``` ```
@ -111,14 +111,14 @@ Clients access Internet through only `isp5`
<details> <details>
```bash ```
sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [2606:4700:4700::1111] sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [2606:4700:4700::1111]
``` ```
> In this case of usage, it's recommended to: > In this case of usage, it's recommended to:
> >
> 1. Stop serving local DNS > 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* > Also, read *Notice 1*
@ -128,11 +128,8 @@ sudo lnxrouter -i eth1 -o isp5 --no-dns --dhcp-dns 1.1.1.1 -6 --dhcp-dns6 [26
<details> <details>
```bash
sudo lnxrouter -n -i eth1
``` ```
sudo lnxrouter -n -i eth1
```bash
sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase
``` ```
@ -146,7 +143,7 @@ sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase
Create a bridge Create a bridge
```bash ```
sudo brctl addbr lxcbr5 sudo brctl addbr lxcbr5
``` ```
@ -159,7 +156,7 @@ lxc.network.link = lxcbr5
lxc.network.hwaddr = xx:xx:xx:xx:xx:xx lxc.network.hwaddr = xx:xx:xx:xx:xx:xx
``` ```
```bash ```
sudo lnxrouter -i lxcbr5 sudo lnxrouter -i lxcbr5
``` ```
@ -171,7 +168,7 @@ All clients' Internet traffic go through, for example, Tor (notice this example
<details> <details>
```bash ```
sudo lnxrouter -i eth1 --tp 9040 --dns 9053 -g 192.168.55.1 -6 --p6 fd00:5:6:7:: sudo lnxrouter -i eth1 --tp 9040 --dns 9053 -g 192.168.55.1 -6 --p6 fd00:5:6:7::
``` ```
@ -196,7 +193,7 @@ To not give our infomation to clients. Clients can still access Internet.
<details> <details>
```bash ```
sudo lnxrouter -i eth1 \ sudo lnxrouter -i eth1 \
--tp 9040 --dns 9053 \ --tp 9040 --dns 9053 \
--random-mac \ --random-mac \
@ -214,13 +211,13 @@ sudo lnxrouter -i eth1 \
Create a bridge Create a bridge
```bash ```
sudo brctl addbr lxdbr5 sudo brctl addbr lxdbr5
``` ```
Create and add a new LXD profile overriding container's `eth0` Create and add a new LXD profile overriding container's `eth0`
```bash ```
lxc profile create profile5 lxc profile create profile5
lxc profile edit profile5 lxc profile edit profile5
@ -238,13 +235,13 @@ name: profile5
lxc profile add <container> profile5 lxc profile add <container> profile5
``` ```
```bash ```
sudo lnxrouter -i lxdbr5 --tp 9040 --dns 9053 sudo lnxrouter -i lxdbr5 --tp 9040 --dns 9053
``` ```
To remove that new profile from container To remove that new profile from container
```bash ```
lxc profile remove <container> profile5 lxc profile remove <container> profile5
``` ```
@ -252,13 +249,13 @@ lxc profile remove <container> profile5
Add new `eth0` to container overriding default `eth0` Add new `eth0` to container overriding default `eth0`
```bash ```
lxc config device add <container> eth0 nic name=eth0 nictype=bridged parent=lxdbr5 lxc config device add <container> eth0 nic name=eth0 nictype=bridged parent=lxdbr5
``` ```
To remove the customized `eth0` to restore default `eth0` To remove the customized `eth0` to restore default `eth0`
```bash ```
lxc config device remove <container> eth0 lxc config device remove <container> eth0
``` ```
@ -270,7 +267,7 @@ lxc config device remove <container> eth0
In VirtualBox's global settings, create a host-only network `vboxnet5` with DHCP disabled. In VirtualBox's global settings, create a host-only network `vboxnet5` with DHCP disabled.
```bash ```
sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053 sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053
``` ```
@ -282,11 +279,11 @@ sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053
Create a bridge Create a bridge
```bash ```
sudo brctl addbr firejail5 sudo brctl addbr firejail5
``` ```
```bash ```
sudo lnxrouter -i firejail5 -g 192.168.55.1 --tp 9040 --dns 9053 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 firejail --net=firejail5 --dns=192.168.55.1 --blacklist=/var/run/nscd
``` ```

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
VERSION=0.7.3 VERSION=0.7.1
PROGNAME="$(basename "$0")" PROGNAME="$(basename "$0")"
export LC_ALL=C export LC_ALL=C
@ -630,7 +630,11 @@ can_transmit_to_channel() {
CHANNEL_NUM=$2 CHANNEL_NUM=$2
if [[ $USE_IWCONFIG -eq 0 ]]; then if [[ $USE_IWCONFIG -eq 0 ]]; then
CHANNEL_INFO=$(get_adapter_info "${IFACE}" | grep -E " [0-9]+(\.[0-9]+){0,1} MHz \[${CHANNEL_NUM}\]") if [[ $FREQ_BAND == 2.4 ]]; then
CHANNEL_INFO=$(get_adapter_info "${IFACE}" | grep " 24[0-9][0-9] MHz \[${CHANNEL_NUM}\]")
else
CHANNEL_INFO=$(get_adapter_info "${IFACE}" | grep " \(49[0-9][0-9]\|5[0-9]\{3\}\) MHz \[${CHANNEL_NUM}\]")
fi
[[ -z "${CHANNEL_INFO}" ]] && return 1 [[ -z "${CHANNEL_INFO}" ]] && return 1
[[ "${CHANNEL_INFO}" == *no\ IR* ]] && return 1 [[ "${CHANNEL_INFO}" == *no\ IR* ]] && return 1
[[ "${CHANNEL_INFO}" == *disabled* ]] && return 1 [[ "${CHANNEL_INFO}" == *disabled* ]] && return 1
@ -661,6 +665,9 @@ ieee80211_frequency_to_channel() {
fi fi
} }
is_5ghz_frequency() {
[[ $1 =~ ^(49[0-9]{2})|(5[0-9]{3})$ ]]
}
is_interface_wifi_connected() { is_interface_wifi_connected() {
if [[ $USE_IWCONFIG -eq 0 ]]; then if [[ $USE_IWCONFIG -eq 0 ]]; then
@ -684,40 +691,36 @@ get_interface_mac() {
cat "/sys/class/net/${1}/address" cat "/sys/class/net/${1}/address"
} }
show_interface_pci_info() { # pci id / model / virtual get_interface_pci_info() { # pci id / model / virtual
is_interface "$1" || return is_interface "$1" || return
local device_path local device_path
local bus_id="" local pci_id
local device_type_and_bus_id="unknown" local pci_full
local driver=""
local device_fullname="" local pci_path
local driver
device_path="$(readlink -f /sys/class/net/$1)" device_path="$(readlink -f /sys/class/net/$1)"
pci_path=$device_path/../..
if [[ "$device_path" == "/sys/devices/pci"* ]]; then if [[ "$device_path" == "/sys/devices/pci"* ]]; then
local pci_path pci_id="$(echo "$device_path" | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)"
pci_path=$device_path/../.. if which lspci >/dev/null 2>&1 ; then
pci_full="$( lspci -D -nn -s "$pci_id" )"
echo -n " PCI: $pci_full"
else
echo -n " PCI: $pci_id"
fi
elif [[ "$device_path" == *"/virtual/"* ]]; then
echo " virtual interface"
fi
if [[ -d "$pci_path/driver" ]] ; then if [[ -d "$pci_path/driver" ]] ; then
driver=$(readlink -f "$pci_path/driver" | sed 's/\//\n/g' | tail -n 1) driver=$(readlink -f "$pci_path/driver" | sed 's/\//\n/g' | tail -n 1)
echo -n " System-already-loaded driver: $driver"
fi fi
bus_id="$(echo "$device_path" | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)"
device_type_and_bus_id="PCI: $bus_id"
if which lspci >/dev/null 2>&1 ; then
device_fullname="$( lspci -D -nn -s "$bus_id" | awk '{$1="" ; print $0}' )"
fi
elif [[ "$device_path" == *"/virtual/"* ]]; then
device_type_and_bus_id="virtual interface"
fi
echo "$device_type_and_bus_id"
[[ -n "$driver" ]] && echo "System-already-loaded driver: $driver"
[[ -n "$device_fullname" ]] && echo "$device_fullname"
echo "" echo ""
# TODO usb # TODO usb
} }
@ -1697,7 +1700,7 @@ prepare_wifi_interface() {
# TODO move this to check_wifi_settings() ? # TODO move this to check_wifi_settings() ?
if is_interface_wifi_connected "${WIFI_IFACE}"; then if is_interface_wifi_connected "${WIFI_IFACE}"; then
WIFI_IFACE_FREQ=$(iw dev "${WIFI_IFACE}" link | grep -i freq | awk '{print $2}' | sed 's/\.00*$//g') # NOTE we assume integer currently, which can be right, or wrong in the future WIFI_IFACE_FREQ=$(iw dev "${WIFI_IFACE}" link | grep -i freq | awk '{print $2}')
WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel "${WIFI_IFACE_FREQ}") WIFI_IFACE_CHANNEL=$(ieee80211_frequency_to_channel "${WIFI_IFACE_FREQ}")
echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)" echo "${WIFI_IFACE} already working in channel ${WIFI_IFACE_CHANNEL} (${WIFI_IFACE_FREQ} MHz)"
@ -2078,8 +2081,7 @@ echo
echo "PID: $$" echo "PID: $$"
TARGET_IFACE="$(decide_target_interface)" || exit 1 # judge wired (-i CONN_IFACE) or wireless hotspot (--ap $WIFI_IFACE) 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")) " echo "Target interface is ${TARGET_IFACE} ($(get_interface_mac "$TARGET_IFACE")) $(get_interface_pci_info "$TARGET_IFACE")"
show_interface_pci_info "$TARGET_IFACE"
if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then
NEW_MACADDR="$(generate_random_mac)" NEW_MACADDR="$(generate_random_mac)"