fix bug when no default entry in routing table

This commit is contained in:
garywill 2020-12-24 20:36:09 +08:00
parent 4991674aec
commit fd542732ce
2 changed files with 19 additions and 14 deletions

View File

@ -217,9 +217,9 @@ Options:
-g <ip> Set this host's IPv4 address, netmask is 24 -g <ip> Set this host's IPv4 address, netmask is 24
-6 Enable IPv6 (NAT) -6 Enable IPv6 (NAT)
--no4 Disable IPv4 Internet (not forwarding IPv4). --no4 Disable IPv4 Internet (not forwarding IPv4)
Usually used with '-6' (See Notice 1). Usually used with '-6'
(See Notice 1)
--p6 <prefix> Set IPv6 prefix (length 64) (example: fd00:1:2:3::) --p6 <prefix> Set IPv6 prefix (length 64) (example: fd00:1:2:3::)
--dns <ip>|<port>|<ip:port> --dns <ip>|<port>|<ip:port>
@ -317,10 +317,15 @@ Wifi hotspot:
## TODO ## TODO
- Option to randomize MAC - Option to randomize MAC
- Explictly ban forwarding if not needed
## Donate ## Donate
[Buy me a coffee](https://github.com/garywill/receiving/blob/master/receiving_methods.md), or just give a star! [Buy me a coffee](https://github.com/garywill/receiving/blob/master/receiving_methods.md) , this project took me lots of time!
^_^o自自o^_^
No? Okay, or just give me a star!
## Thanks ## Thanks

20
lnxrouter Executable file → Normal file
View File

@ -30,9 +30,9 @@ Options:
-g <ip> Set this host's IPv4 address, netmask is 24 -g <ip> Set this host's IPv4 address, netmask is 24
-6 Enable IPv6 (NAT) -6 Enable IPv6 (NAT)
--no4 Disable IPv4 Internet (not forwarding IPv4). --no4 Disable IPv4 Internet (not forwarding IPv4)
Usually used with '-6' (See Notice 1). Usually used with '-6'
(See Notice 1)
--p6 <prefix> Set IPv6 prefix (length 64) (example: fd00:1:2:3::) --p6 <prefix> Set IPv6 prefix (length 64) (example: fd00:1:2:3::)
--dns <ip>|<port>|<ip:port> --dns <ip>|<port>|<ip:port>
@ -196,14 +196,14 @@ while [[ -n "$1" ]]; do
INTERNET_IFACE="$1" INTERNET_IFACE="$1"
shift shift
echo "" echo ""
echo "Since you're using in this mode, make sure you've read Notice 1" >&2 echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
echo "" echo ""
;; ;;
-n) -n)
shift shift
SHARE_METHOD=none SHARE_METHOD=none
echo "" echo ""
echo "Since you're using in this mode, make sure you've read Notice 1" >&2 echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
echo "" echo ""
;; ;;
--ban-priv) --ban-priv)
@ -230,7 +230,7 @@ while [[ -n "$1" ]]; do
shift shift
NO4=1 NO4=1
echo "" echo ""
echo "Since you're using in this mode, make sure you've read Notice 1" >&2 echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
echo "" echo ""
;; ;;
--p6) --p6)
@ -624,15 +624,15 @@ get_new_macaddr() {
is_ip4_range_available() { is_ip4_range_available() {
( ip -4 address | grep "inet 192\.168\.$1\." > /dev/null 2>&1 ) && return 1 ( ip -4 address | grep "inet 192\.168\.$1\." > /dev/null 2>&1 ) && return 1
( ip -4 route | grep "^192\.168\.$1\." > /dev/null 2>&1 ) && return 1 ( ip -4 route | grep "^192\.168\.$1\." > /dev/null 2>&1 ) && return 1
( ip -4 route get 192.168.$1.0 | grep "\bvia\b" > /dev/null 2>&1 ) && \ ( ip -4 route get 192.168.$1.0 2>&1 | grep -E "\bvia\b|\bunreachable\b" > /dev/null 2>&1 ) && \
( ip -4 route get 192.168.$1.255 | grep "\bvia\b" > /dev/null 2>&1 ) && return 0 ( ip -4 route get 192.168.$1.255 2>&1 | grep -E "\bvia\b|\bunreachable\b" > /dev/null 2>&1 ) && return 0
return 1 return 1
} }
is_ip6_range_available() { is_ip6_range_available() {
( ip -6 address | grep -i "inet6 fd$1:$2$3:$4$5:$6$7:" > /dev/null 2>&1 ) && return 1 ( ip -6 address | grep -i "inet6 fd$1:$2$3:$4$5:$6$7:" > /dev/null 2>&1 ) && return 1
( ip -6 route | grep -i "^fd$1:$2$3:$4$5:$6$7:" > /dev/null 2>&1 ) && return 1 ( ip -6 route | grep -i "^fd$1:$2$3:$4$5:$6$7:" > /dev/null 2>&1 ) && return 1
( ip -6 route get fd$1:$2$3:$4$5:$6$7:: | grep "\bvia\b" > /dev/null 2>&1 ) && \ ( ip -6 route get fd$1:$2$3:$4$5:$6$7:: 2>&1 | grep -E "\bvia\b|\bunreachable\b" > /dev/null 2>&1 ) && \
( ip -6 route get fd$1:$2$3:$4$5:$6$7:ffff:ffff:ffff:ffff | grep "\bvia\b" > /dev/null 2>&1 ) && return 0 ( ip -6 route get fd$1:$2$3:$4$5:$6$7:ffff:ffff:ffff:ffff 2>&1 | grep -E "\bvia\b|\bunreachable\b" > /dev/null 2>&1 ) && return 0
return 1 return 1
} }