Skip to content

Commit 15a2e0c

Browse files
committed
0.6.6
1 parent 083cd42 commit 15a2e0c

File tree

2 files changed

+54
-48
lines changed

2 files changed

+54
-48
lines changed

README.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Linux-router
22

3-
Set Linux as router in one command. Able to Provide Internet, or create Wifi hotspot. Support transparent proxy (redsocks). Also useful for routing VM/containers.
3+
Set Linux as router in one command. Able to provide Internet, or create WiFi hotspot. Support transparent proxy (redsocks). Also useful for routing VM/containers.
44

55
It wraps `iptables`, `dnsmasq` etc. stuff. Use in one command, restore in one command or by `control-c` (or even by closing terminal window).
66

@@ -12,17 +12,19 @@ Basic features:
1212

1313
- Create a NATed sub-network
1414
- Provide Internet
15-
- DHCP server (and RA) + DNS server
16-
- Configuring what DNS the DHCP server offers to clients
17-
- Configuring upstream DNS for local DNS server (kind of a DNS proxy)
15+
- DHCP server (and RA)
16+
- Specify what DNS the DHCP server assigns to clients
17+
- DNS server
18+
- Specify upstream DNS (kind of a plain DNS proxy)
1819
- IPv6 (behind NATed LAN, like IPv4)
19-
- Creating Wifi hotspot:
20+
- Creating WiFi hotspot:
2021
- Channel selecting
2122
- Choose encryptions: WPA2/WPA, WPA2, WPA, No encryption
2223
- Create AP on the same interface you are getting Internet (usually require same channel)
2324
- Transparent proxy (redsocks)
2425
- Transparent DNS proxy (hijack port 53 packets)
2526
- Compatible with NetworkManager (automatically set interface as unmanaged)
27+
- You can run many instances, to create many different networks. Has instances managing feature.
2628

2729
**For many other features, see below [CLI usage](#cli-usage-and-other-features)**
2830

@@ -36,7 +38,7 @@ Internet----(eth0/wlan0)-Linux-(wlanX)AP
3638

3739
```
3840
Internet
39-
Wifi AP(no DHCP) |
41+
WiFi AP(no DHCP) |
4042
|----(wlan1)-Linux-(eth0/wlan0)------
4143
| (DHCP)
4244
|--client
@@ -69,7 +71,7 @@ sudo lnxrouter -i eth1
6971

7072
no matter which interface (other than `eth1`) you're getting Internet from.
7173

72-
### Create Wifi hotspot
74+
### Create WiFi hotspot
7375

7476
```
7577
sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase
@@ -253,9 +255,13 @@ sudo brctl addbr firejail5
253255

254256
```
255257
sudo lnxrouter -i firejail5 -g 192.168.55.1 --tp 9040 --dns 9053
256-
firejail --net=firejail5 --dns=192.168.55.1 --blacklist=/var/run/nscd # nscd is cache service, which shouldn't be accessed in jail here
258+
firejail --net=firejail5 --dns=192.168.55.1 --blacklist=/var/run/nscd
257259
```
258260

261+
Firejail's `/etc/resolv.conf` doesn't obtain DNS from DHCP, so we need to assign.
262+
263+
nscd is domain name cache service, which shouldn't be accessed from in jail here.
264+
259265
</details>
260266

261267
### CLI usage and other features
@@ -271,7 +277,7 @@ Options:
271277
272278
-i <interface> Interface to make NATed sub-network,
273279
and to provide Internet to
274-
(To create Wifi hotspot use '--ap' instead)
280+
(To create WiFi hotspot use '--ap' instead)
275281
-o <interface> Specify an inteface to provide Internet from.
276282
(See Notice 1)
277283
(Note using this with default DNS option may leak
@@ -319,12 +325,12 @@ Options:
319325
redirect non-LAN TCP and UDP traffic to port.
320326
(usually used with '--dns')
321327
322-
Wifi hotspot options:
328+
WiFi hotspot options:
323329
--ap <wifi interface> <SSID>
324-
Create Wifi access point
330+
Create WiFi access point
325331
-p, --password <password>
326-
Wifi password
327-
--qr Show Wifi QR code in terminal
332+
WiFi password
333+
--qr Show WiFi QR code in terminal
328334
329335
--hidden Hide access point (not broadcast SSID)
330336
--no-virt Do not create virtual interface
@@ -339,8 +345,8 @@ Options:
339345
(default: 2)
340346
--psk Use 64 hex digits pre-shared-key instead of
341347
passphrase
342-
--mac-filter Enable Wifi hotspot MAC address filtering
343-
--mac-filter-accept Location of Wifi hotspot MAC address filter list
348+
--mac-filter Enable WiFi hotspot MAC address filtering
349+
--mac-filter-accept Location of WiFi hotspot MAC address filter list
344350
(defaults to /etc/hostapd/hostapd.accept)
345351
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
346352
--isolate-clients Disable wifi communication between clients
@@ -373,9 +379,9 @@ Options:
373379
```
374380
Notice 1: This script assume your host's default policy won't forward
375381
packets, so the script won't explictly ban forwarding in any
376-
mode. In some unexpected case may cause unwanted packets
377-
leakage between 2 networks, which you should be aware of if you
378-
want isolated network
382+
mode. In some unexpected case (eg. mistaken configurations) may
383+
cause unwanted packets leakage between 2 networks, which you
384+
should be aware of if you want isolated network
379385
```
380386

381387
</details>
@@ -389,7 +395,7 @@ On exit of a linux-router instance, script **will do cleanup**, i.e. undo most c
389395
3. hostapd (if used) in Apparmor complain mode
390396
4. Kernel module `nf_nat_pptp` loaded
391397
5. The wifi device which is used to create hotspot is `rfkill unblock`ed
392-
6. Wifi country code, if user specified
398+
6. WiFi country code, if user assigns
393399

394400
## Dependencies
395401

@@ -409,6 +415,7 @@ On exit of a linux-router instance, script **will do cleanup**, i.e. undo most c
409415

410416
<details>
411417

418+
- Compatibility with firewalld
412419
- WPA3
413420
- Global IPv6
414421
- Explictly ban forwarding if not needed
@@ -479,10 +486,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
479486

480487
Visit [**my homepage** 🏡](https://garywill.github.io) to see **more tools and projects** 🛠️.
481488

482-
> [❤️ 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))
489+
> [❤️ 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))
483490
>
484491
> 🥂 ( ^\_^) o自自o (^_^ ) 🍻
485492
486493
🤝 Bisides, thank [create_ap](https://github.com/oblique/create_ap) by [oblique](https://github.com/oblique). This script was forked from create\_ap. Now they are quite different. (See `history` branch for how I modified create_ap). 🤝 Also thank those who contributed to that project.
487494

488-
👨‍💻 You can be contributor, too! 🍃 There're some TO-DOs listed, at both above and in the code file. Also some unfulfilled enhancements in the Issues. Your name can be here!
495+
👨‍💻 You can be contributor, too! 🍃 There're some TO-DOs listed, at both [above](#todo) and [in the code file](https://github.com/garywill/linux-router/search?q=TODO&type=code). 🍃 Also some [unfulfilled enhancements in the Issues](https://github.com/garywill/linux-router/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement). Your name can be here!

lnxrouter

100644100755
Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
VERSION=0.6.5
3+
VERSION=0.6.6
44
PROGNAME="$(basename $0)"
55

66
export LC_ALL=C
@@ -27,7 +27,7 @@ Options:
2727
2828
-i <interface> Interface to make NATed sub-network,
2929
and to provide Internet to
30-
(To create Wifi hotspot use '--ap' instead)
30+
(To create WiFi hotspot use '--ap' instead)
3131
-o <interface> Specify an inteface to provide Internet from.
3232
(See Notice 1)
3333
(Note using this with default DNS option may leak
@@ -75,12 +75,12 @@ Options:
7575
redirect non-LAN TCP and UDP traffic to port.
7676
(usually used with '--dns')
7777
78-
Wifi hotspot options:
78+
WiFi hotspot options:
7979
--ap <wifi interface> <SSID>
80-
Create Wifi access point
80+
Create WiFi access point
8181
-p, --password <password>
82-
Wifi password
83-
--qr Show Wifi QR code in terminal
82+
WiFi password
83+
--qr Show WiFi QR code in terminal
8484
8585
--hidden Hide access point (not broadcast SSID)
8686
--no-virt Do not create virtual interface
@@ -95,8 +95,8 @@ Options:
9595
(default: 2)
9696
--psk Use 64 hex digits pre-shared-key instead of
9797
passphrase
98-
--mac-filter Enable Wifi hotspot MAC address filtering
99-
--mac-filter-accept Location of Wifi hotspot MAC address filter list
98+
--mac-filter Enable WiFi hotspot MAC address filtering
99+
--mac-filter-accept Location of WiFi hotspot MAC address filter list
100100
(defaults to /etc/hostapd/hostapd.accept)
101101
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
102102
--isolate-clients Disable wifi communication between clients
@@ -121,9 +121,9 @@ Options:
121121
122122
Notice 1: This script assume your host's default policy won't forward
123123
packets, so the script won't explictly ban forwarding in any
124-
mode. In some unexpected case may cause unwanted packets
125-
leakage between 2 networks, which you should be aware of if you
126-
want isolated network
124+
mode. In some unexpected case (eg. mistaken configurations) may
125+
cause unwanted packets leakage between 2 networks, which you
126+
should be aware of if you want isolated network
127127
128128
Examples:
129129
$PROGNAME -i eth1
@@ -231,16 +231,10 @@ parse_user_options(){
231231
shift
232232
INTERNET_IFACE="$1"
233233
shift
234-
echo ""
235-
echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
236-
echo ""
237234
;;
238235
-n)
239236
shift
240237
SHARE_METHOD=none
241-
echo ""
242-
echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
243-
echo ""
244238
;;
245239
--ban-priv)
246240
shift
@@ -266,9 +260,6 @@ parse_user_options(){
266260
--no4)
267261
shift
268262
NO4=1
269-
echo ""
270-
echo "WARN: Since you're using in this mode, make sure you've read Notice 1" >&2
271-
echo ""
272263
;;
273264
--p6)
274265
shift
@@ -1097,7 +1088,7 @@ backup_interface_status() {
10971088

10981089
backup_ipv6_bits
10991090

1100-
# TODO : backup ip and others
1091+
# TODO : ? backup ip and others???
11011092

11021093
# nm managing status is saved when nm_set_unmanaged()
11031094
}
@@ -1178,11 +1169,12 @@ cleanup() {
11781169
echo
11791170
echo "Doing cleanup.. "
11801171
kill_processes
1181-
echo "Cleanning up iptables .."
1172+
echo "Undoing iptables changes .."
11821173
clean_iptables > /dev/null
11831174
_cleanup 2> /dev/null
11841175

11851176
pgid=$(ps opgid= $$ |awk '{print $1}' )
1177+
echo "Killing PGID $pgid ..."
11861178
kill -15 -$pgid
11871179
sleep 1
11881180
echo "Cleaning up done"
@@ -1446,7 +1438,7 @@ check_other_functions(){
14461438

14471439
##### root test ##### NOTE above don't require root ##########
14481440
if [[ $(id -u) -ne 0 ]]; then
1449-
echo "You must run it as root." >&2
1441+
echo "ERROR: Need root to continue" >&2
14501442
exit 1
14511443
fi
14521444
###### NOTE below require root ##########
@@ -1730,7 +1722,7 @@ write_hostapd_conf() {
17301722
rsn_pairwise=CCMP
17311723
EOF
17321724
else
1733-
echo "WARN: Wifi is not protected by password" >&2
1725+
echo "WARN: WiFi is not protected by password" >&2
17341726
fi
17351727
chmod 600 "$CONFDIR/hostapd.conf"
17361728
}
@@ -2016,26 +2008,33 @@ fi
20162008

20172009
check_iptables
20182010

2019-
echo "Not showing all iptables operations."
2011+
echo "NOTICE: Not showing all operations done to iptables rules"
2012+
2013+
[[ "$NO4" -eq 1 ]] && echo -e "\nWARN: Since you're using in this mode (no IPv4 Internet), make sure you've read Notice 1\n" >&2
2014+
20202015
# enable Internet sharing
20212016
if [[ "$SHARE_METHOD" == "none" ]]; then
20222017

20232018
echo "No Internet sharing"
20242019

2020+
echo -e "\nWARN: Since you're using in this mode (no Internet share), make sure you've read Notice 1\n" >&2
2021+
20252022
[[ "$BANLAN" -eq 1 ]] && start_ban_lan
20262023

20272024
elif [[ "$SHARE_METHOD" == "nat" ]]; then
20282025

2026+
[[ "$INTERNET_IFACE" ]] && echo -e "\nWARN: Since you're using in this mode (specify Internet interface), make sure you've read Notice 1\n" >&2
2027+
20292028
[[ "$INTERNET_IFACE" && "$dnsmasq_NO_DNS" -eq 0 ]] && echo -e "\nWARN: You specified Internet interface but this host is providing local DNS. In some unexpected case (eg. mistaken configurations), queries may leak to other interfaces, which you should be aware of.\n" >&2
20302029

20312030
start_nat
20322031

20332032
[[ "$BANLAN" -eq 1 ]] && start_ban_lan
20342033

2035-
echo 1 > "/proc/sys/net/ipv4/ip_forward" || die "Failed enabling system ipv4 forwarding"
2034+
echo 1 > "/proc/sys/net/ipv4/ip_forward" || die "Failed enabling system ipv4 forwarding" # TODO maybe uneeded in '--no4' mode
20362035

20372036
if [[ $IPV6 -eq 1 ]]; then
2038-
echo 1 > "/proc/sys/net/ipv6/conf/all/forwarding" || die "Failed enabling system ipv6 forwarding"
2037+
echo 1 > "/proc/sys/net/ipv6/conf/all/forwarding" || die "Failed enabling system ipv6 forwarding" # TODO if '-o' used, set only 2 interfaces' bits
20392038
fi
20402039

20412040
# to enable clients to establish PPTP connections we must

0 commit comments

Comments
 (0)