You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-21Lines changed: 28 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Linux-router
2
2
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.
4
4
5
5
It wraps `iptables`, `dnsmasq` etc. stuff. Use in one command, restore in one command or by `control-c` (or even by closing terminal window).
6
6
@@ -12,17 +12,19 @@ Basic features:
12
12
13
13
- Create a NATed sub-network
14
14
- 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)
18
19
- IPv6 (behind NATed LAN, like IPv4)
19
-
- Creating Wifi hotspot:
20
+
- Creating WiFi hotspot:
20
21
- Channel selecting
21
22
- Choose encryptions: WPA2/WPA, WPA2, WPA, No encryption
22
23
- Create AP on the same interface you are getting Internet (usually require same channel)
23
24
- Transparent proxy (redsocks)
24
25
- Transparent DNS proxy (hijack port 53 packets)
25
26
- Compatible with NetworkManager (automatically set interface as unmanaged)
27
+
- You can run many instances, to create many different networks. Has instances managing feature.
26
28
27
29
**For many other features, see below [CLI usage](#cli-usage-and-other-features)**
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
+
259
265
</details>
260
266
261
267
### CLI usage and other features
@@ -271,7 +277,7 @@ Options:
271
277
272
278
-i <interface> Interface to make NATed sub-network,
273
279
and to provide Internet to
274
-
(To create Wifi hotspot use '--ap' instead)
280
+
(To create WiFi hotspot use '--ap' instead)
275
281
-o <interface> Specify an inteface to provide Internet from.
276
282
(See Notice 1)
277
283
(Note using this with default DNS option may leak
@@ -319,12 +325,12 @@ Options:
319
325
redirect non-LAN TCP and UDP traffic to port.
320
326
(usually used with '--dns')
321
327
322
-
Wifi hotspot options:
328
+
WiFi hotspot options:
323
329
--ap <wifi interface> <SSID>
324
-
Create Wifi access point
330
+
Create WiFi access point
325
331
-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
328
334
329
335
--hidden Hide access point (not broadcast SSID)
330
336
--no-virt Do not create virtual interface
@@ -339,8 +345,8 @@ Options:
339
345
(default: 2)
340
346
--psk Use 64 hex digits pre-shared-key instead of
341
347
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
344
350
(defaults to /etc/hostapd/hostapd.accept)
345
351
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
346
352
--isolate-clients Disable wifi communication between clients
@@ -373,9 +379,9 @@ Options:
373
379
```
374
380
Notice 1: This script assume your host's default policy won't forward
375
381
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
379
385
```
380
386
381
387
</details>
@@ -389,7 +395,7 @@ On exit of a linux-router instance, script **will do cleanup**, i.e. undo most c
389
395
3. hostapd (if used) in Apparmor complain mode
390
396
4. Kernel module `nf_nat_pptp` loaded
391
397
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
393
399
394
400
## Dependencies
395
401
@@ -409,6 +415,7 @@ On exit of a linux-router instance, script **will do cleanup**, i.e. undo most c
409
415
410
416
<details>
411
417
418
+
- Compatibility with firewalld
412
419
- WPA3
413
420
- Global IPv6
414
421
- Explictly ban forwarding if not needed
@@ -479,10 +486,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
479
486
480
487
Visit [**my homepage** 🏡](https://garywill.github.io) to see **more tools and projects** 🛠️.
481
488
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))
483
490
>
484
491
> 🥂 ( ^\_^) o自自o (^_^ ) 🍻
485
492
486
493
🤝 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.
487
494
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!
-i <interface> Interface to make NATed sub-network,
29
29
and to provide Internet to
30
-
(To create Wifi hotspot use '--ap' instead)
30
+
(To create WiFi hotspot use '--ap' instead)
31
31
-o <interface> Specify an inteface to provide Internet from.
32
32
(See Notice 1)
33
33
(Note using this with default DNS option may leak
@@ -75,12 +75,12 @@ Options:
75
75
redirect non-LAN TCP and UDP traffic to port.
76
76
(usually used with '--dns')
77
77
78
-
Wifi hotspot options:
78
+
WiFi hotspot options:
79
79
--ap <wifi interface> <SSID>
80
-
Create Wifi access point
80
+
Create WiFi access point
81
81
-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
84
84
85
85
--hidden Hide access point (not broadcast SSID)
86
86
--no-virt Do not create virtual interface
@@ -95,8 +95,8 @@ Options:
95
95
(default: 2)
96
96
--psk Use 64 hex digits pre-shared-key instead of
97
97
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
100
100
(defaults to /etc/hostapd/hostapd.accept)
101
101
--hostapd-debug <level> 1 or 2. Passes -d or -dd to hostapd
102
102
--isolate-clients Disable wifi communication between clients
@@ -121,9 +121,9 @@ Options:
121
121
122
122
Notice 1: This script assume your host's default policy won't forward
123
123
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
127
127
128
128
Examples:
129
129
$PROGNAME -i eth1
@@ -231,16 +231,10 @@ parse_user_options(){
231
231
shift
232
232
INTERNET_IFACE="$1"
233
233
shift
234
-
echo""
235
-
echo"WARN: Since you're using in this mode, make sure you've read Notice 1">&2
236
-
echo""
237
234
;;
238
235
-n)
239
236
shift
240
237
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""
244
238
;;
245
239
--ban-priv)
246
240
shift
@@ -266,9 +260,6 @@ parse_user_options(){
266
260
--no4)
267
261
shift
268
262
NO4=1
269
-
echo""
270
-
echo"WARN: Since you're using in this mode, make sure you've read Notice 1">&2
271
-
echo""
272
263
;;
273
264
--p6)
274
265
shift
@@ -1097,7 +1088,7 @@ backup_interface_status() {
1097
1088
1098
1089
backup_ipv6_bits
1099
1090
1100
-
# TODO : backup ip and others
1091
+
# TODO : ? backup ip and others???
1101
1092
1102
1093
# nm managing status is saved when nm_set_unmanaged()
1103
1094
}
@@ -1178,11 +1169,12 @@ cleanup() {
1178
1169
echo
1179
1170
echo"Doing cleanup.. "
1180
1171
kill_processes
1181
-
echo"Cleanning up iptables .."
1172
+
echo"Undoing iptables changes .."
1182
1173
clean_iptables > /dev/null
1183
1174
_cleanup 2> /dev/null
1184
1175
1185
1176
pgid=$(ps opgid= $$|awk '{print $1}')
1177
+
echo"Killing PGID $pgid ..."
1186
1178
kill -15 -$pgid
1187
1179
sleep 1
1188
1180
echo"Cleaning up done"
@@ -1446,7 +1438,7 @@ check_other_functions(){
1446
1438
1447
1439
##### root test ##### NOTE above don't require root ##########
1448
1440
if [[ $(id -u)-ne 0 ]];then
1449
-
echo"You must run it as root.">&2
1441
+
echo"ERROR: Need root to continue">&2
1450
1442
exit 1
1451
1443
fi
1452
1444
###### NOTE below require root ##########
@@ -1730,7 +1722,7 @@ write_hostapd_conf() {
1730
1722
rsn_pairwise=CCMP
1731
1723
EOF
1732
1724
else
1733
-
echo"WARN: Wifi is not protected by password">&2
1725
+
echo"WARN: WiFi is not protected by password">&2
1734
1726
fi
1735
1727
chmod 600 "$CONFDIR/hostapd.conf"
1736
1728
}
@@ -2016,26 +2008,33 @@ fi
2016
2008
2017
2009
check_iptables
2018
2010
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
+
2020
2015
# enable Internet sharing
2021
2016
if [[ "$SHARE_METHOD"=="none" ]];then
2022
2017
2023
2018
echo"No Internet sharing"
2024
2019
2020
+
echo -e "\nWARN: Since you're using in this mode (no Internet share), make sure you've read Notice 1\n">&2
2021
+
2025
2022
[[ "$BANLAN"-eq 1 ]] && start_ban_lan
2026
2023
2027
2024
elif [[ "$SHARE_METHOD"=="nat" ]];then
2028
2025
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
+
2029
2028
[[ "$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
2030
2029
2031
2030
start_nat
2032
2031
2033
2032
[[ "$BANLAN"-eq 1 ]] && start_ban_lan
2034
2033
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
2036
2035
2037
2036
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
2039
2038
fi
2040
2039
2041
2040
# to enable clients to establish PPTP connections we must
0 commit comments