mirror of
https://github.com/garywill/linux-router.git
synced 2025-12-30 18:58:28 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
200b6d4451 | ||
|
|
2ea1dfd5b7 | ||
|
|
f6995bc30c | ||
|
|
204756cffb | ||
|
|
e1ccfac40c | ||
|
|
f8cbf5eded |
19
README.md
19
README.md
@@ -4,7 +4,7 @@ Set Linux as router in one command. Able to provide Internet, or create WiFi hot
|
|||||||
|
|
||||||
It wraps `iptables`, `dnsmasq` etc. stuff. Use in one command, restore in one command or by `control-c` (or even by closing terminal window).
|
It wraps `iptables`, `dnsmasq` etc. stuff. Use in one command, restore in one command or by `control-c` (or even by closing terminal window).
|
||||||
|
|
||||||
[More tools and projects 🛠️](https://garywill.github.io) | [🍻 Buy me a coffee ❤️](https://github.com/garywill/receiving/blob/master/receiving_methods.md)
|
[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
|
## Features
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ Basic features:
|
|||||||
- Create AP on the same interface you are getting Internet (usually require same channel)
|
- Create AP on the same interface you are getting Internet (usually require same channel)
|
||||||
- Transparent proxy (redsocks)
|
- Transparent proxy (redsocks)
|
||||||
- Transparent DNS proxy (hijack port 53 packets)
|
- Transparent DNS proxy (hijack port 53 packets)
|
||||||
- Compatible with NetworkManager (automatically set interface as unmanaged)
|
- Detect NetworkManager and make sure it won't interfere (handle interface (un)managed status)
|
||||||
- You can run many instances, to create many different networks. Has instances managing feature.
|
- You can run many instances, to create many different networks. Has instances managing feature.
|
||||||
|
|
||||||
**For many other features, see below [CLI usage](#cli-usage-and-other-features)**
|
**For many other features, see below [CLI usage](#cli-usage-and-other-features)**
|
||||||
@@ -388,11 +388,11 @@ Options:
|
|||||||
|
|
||||||
## What changes are done to Linux system
|
## What changes are done to Linux system
|
||||||
|
|
||||||
On exit of a linux-router instance, script **will do cleanup**, i.e. undo most changes to system. Though, **some** changes will **not** be undone, which are:
|
On exit of a linux-router instance, script **will do cleanup**, i.e. undo most changes to system. Though, **some** changes (if needed) will **not** be undone, which are:
|
||||||
|
|
||||||
1. `/proc/sys/net/ipv4/ip_forward = 1` and `/proc/sys/net/ipv6/conf/all/forwarding = 1`
|
1. `/proc/sys/net/ipv4/ip_forward = 1` and `/proc/sys/net/ipv6/conf/all/forwarding = 1`
|
||||||
2. dnsmasq (if used) in Apparmor complain mode
|
2. dnsmasq in Apparmor complain mode
|
||||||
3. hostapd (if used) in Apparmor complain mode
|
3. hostapd in Apparmor complain mode
|
||||||
4. Kernel module `nf_nat_pptp` loaded
|
4. Kernel module `nf_nat_pptp` loaded
|
||||||
5. The wifi device which is used to create hotspot is `rfkill unblock`ed
|
5. The wifi device which is used to create hotspot is `rfkill unblock`ed
|
||||||
6. WiFi country code, if user assigns
|
6. WiFi country code, if user assigns
|
||||||
@@ -413,16 +413,15 @@ On exit of a linux-router instance, script **will do cleanup**, i.e. undo most c
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
<details>
|
Sooner is better:
|
||||||
|
- Detect firewalld and make sure it won't interfere our interface
|
||||||
|
|
||||||
- Compatibility with firewalld
|
Future:
|
||||||
- WPA3
|
- WPA3
|
||||||
- Global IPv6
|
- Global IPv6
|
||||||
- Explictly ban forwarding if not needed
|
- Explictly ban forwarding if not needed
|
||||||
- Bring bridging method back
|
- Bring bridging method back
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
linux-router is LGPL licensed
|
linux-router is LGPL licensed
|
||||||
@@ -486,7 +485,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
Visit [**my homepage** 🏡](https://garywill.github.io) to see **more tools and projects** 🛠️.
|
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))
|
> [❤️ 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 (^_^ ) 🍻
|
> 🥂 ( ^\_^) o自自o (^_^ ) 🍻
|
||||||
|
|
||||||
|
|||||||
104
lnxrouter
104
lnxrouter
@@ -626,6 +626,32 @@ get_interface_mac() {
|
|||||||
cat "/sys/class/net/${1}/address"
|
cat "/sys/class/net/${1}/address"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_interface_pci_info() { # pci id / model / virtual
|
||||||
|
is_interface "$1" || return
|
||||||
|
|
||||||
|
local device_path
|
||||||
|
local pci_id
|
||||||
|
local pci_full
|
||||||
|
|
||||||
|
device_path="$(readlink -f /sys/class/net/$1)"
|
||||||
|
|
||||||
|
if [[ "$device_path" == "/sys/devices/pci"* ]]; then
|
||||||
|
pci_id="$(echo $device_path | sed 's/\//\n/g' | tail -n 3 |sed -n 1p)"
|
||||||
|
|
||||||
|
if which lspci >/dev/null 2>&1 ; then
|
||||||
|
pci_full="$( lspci -D -nn | grep -E "^$pci_id " )"
|
||||||
|
echo " PCI: $pci_full"
|
||||||
|
else
|
||||||
|
echo " PCI: $pci_id"
|
||||||
|
fi
|
||||||
|
elif [[ "$device_path" == *"/virtual/"* ]]; then
|
||||||
|
echo " virtual interface"
|
||||||
|
fi
|
||||||
|
# TODO usb
|
||||||
|
# TODO current driver
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
alloc_new_vface_name() { # only for wifi
|
alloc_new_vface_name() { # only for wifi
|
||||||
local i=0
|
local i=0
|
||||||
local v_iface_name=
|
local v_iface_name=
|
||||||
@@ -1158,7 +1184,7 @@ _cleanup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clean_iptables() {
|
clean_iptables() {
|
||||||
bash $CONFDIR/undo_iptables.sh
|
[[ -f $CONFDIR/undo_iptables.sh ]] && bash $CONFDIR/undo_iptables.sh
|
||||||
|
|
||||||
[[ -f $CONFDIR/undo_iptables_2.sh ]] && bash $CONFDIR/undo_iptables_2.sh
|
[[ -f $CONFDIR/undo_iptables_2.sh ]] && bash $CONFDIR/undo_iptables_2.sh
|
||||||
}
|
}
|
||||||
@@ -1173,10 +1199,10 @@ cleanup() {
|
|||||||
clean_iptables > /dev/null
|
clean_iptables > /dev/null
|
||||||
_cleanup 2> /dev/null
|
_cleanup 2> /dev/null
|
||||||
|
|
||||||
pgid=$(ps opgid= $$ |awk '{print $1}' )
|
#pgid=$(ps opgid= $$ |awk '{print $1}' )
|
||||||
echo "Killing PGID $pgid ..."
|
#echo "Killing PGID $pgid ..."
|
||||||
kill -15 -$pgid
|
#kill -15 -$pgid
|
||||||
sleep 1
|
#sleep 1
|
||||||
echo "Cleaning up done"
|
echo "Cleaning up done"
|
||||||
#kill -9 -$pgid
|
#kill -9 -$pgid
|
||||||
}
|
}
|
||||||
@@ -1588,6 +1614,10 @@ decide_ip_addresses() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepare_wifi_interface() {
|
prepare_wifi_interface() {
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
echo; echo; echo;
|
||||||
|
echo "Trying to set power_save off ..."
|
||||||
if [[ $USE_IWCONFIG -eq 0 ]]; then
|
if [[ $USE_IWCONFIG -eq 0 ]]; then
|
||||||
iw dev ${WIFI_IFACE} set power_save off
|
iw dev ${WIFI_IFACE} set power_save off
|
||||||
fi
|
fi
|
||||||
@@ -1611,6 +1641,8 @@ prepare_wifi_interface() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
sleep 6
|
||||||
|
echo; echo; echo;
|
||||||
echo "Creating a virtual WiFi interface... "
|
echo "Creating a virtual WiFi interface... "
|
||||||
VWIFI_IFACE=$(alloc_new_vface_name)
|
VWIFI_IFACE=$(alloc_new_vface_name)
|
||||||
if iw dev ${WIFI_IFACE} interface add ${VWIFI_IFACE} type __ap; then
|
if iw dev ${WIFI_IFACE} interface add ${VWIFI_IFACE} type __ap; then
|
||||||
@@ -1925,11 +1957,12 @@ phead
|
|||||||
phead2
|
phead2
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
echo " ============ In dev branch for issue #12 ==========="
|
||||||
|
|
||||||
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)"
|
||||||
# TODO: show interface type, device model and pci/usb id (hwdata pci.ids), current driver
|
|
||||||
|
|
||||||
if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then
|
if [[ "$MAC_USE_RANDOM" -eq 1 ]] ; then
|
||||||
NEW_MACADDR="$(generate_random_mac)"
|
NEW_MACADDR="$(generate_random_mac)"
|
||||||
@@ -1949,10 +1982,33 @@ init_trap
|
|||||||
|
|
||||||
init_conf_dirs # CONFDIR , COMMON_CONFDIR . make dir
|
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)
|
[[ $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()
|
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"
|
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
|
# if virtual wifi interface, will be destroyed, so only need to save status when not
|
||||||
[[ -z $VWIFI_IFACE ]] && backup_interface_status
|
[[ -z $VWIFI_IFACE ]] && backup_interface_status
|
||||||
@@ -1972,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
|
# 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()
|
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
|
nm_set_unmanaged ${SUBNET_IFACE} # will write NM_UNM_LIST
|
||||||
@@ -1980,19 +2040,47 @@ fi
|
|||||||
[[ $NO_DNSMASQ -eq 0 ]] && write_dnsmasq_conf
|
[[ $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
|
# initialize subnet interface
|
||||||
# take subnet interface down first
|
# take subnet interface down first
|
||||||
ip link set down dev ${SUBNET_IFACE} || die "Failed setting ${SUBNET_IFACE} down"
|
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
|
# flush old IPs of subnet interface
|
||||||
ip addr flush ${SUBNET_IFACE} || die "Failed flush ${SUBNET_IFACE} IP"
|
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
|
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
|
[[ $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
|
# bring subnet interface up
|
||||||
ip link set up dev ${SUBNET_IFACE} || die "Failed bringing ${SUBNET_IFACE} 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
|
# hostapd , haveged
|
||||||
[[ $WIFI_IFACE ]] && run_wifi_ap_processes
|
[[ $WIFI_IFACE ]] && run_wifi_ap_processes
|
||||||
|
|
||||||
@@ -2065,7 +2153,7 @@ fi
|
|||||||
[[ $NO_DNSMASQ -eq 0 ]] && ( allow_dhcp ; start_dnsmasq )
|
[[ $NO_DNSMASQ -eq 0 ]] && ( allow_dhcp ; start_dnsmasq )
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "== Setting up completed, now linux-router is working =="
|
echo "== Setting up completed, now linux-router should be working =="
|
||||||
|
|
||||||
#============================================================
|
#============================================================
|
||||||
#============================================================
|
#============================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user