Linux-router
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.
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 🛠️ | 🍻 Buy me a coffee ❤️
Features
Basic features:
- Create a NATed sub-network
- Provide Internet
- DHCP server (and RA)
- Specify what DNS the DHCP server assigns to clients
- DNS server
- Specify upstream DNS (kind of a plain DNS proxy)
- IPv6 (behind NATed LAN, like IPv4)
- Creating WiFi hotspot:
- Wifi 3/4/5/6
- 2.4GHz, 5GHz
- Channel selecting
- Choose encryptions: WPA2/WPA, WPA2, WPA, No encryption
- Create AP on the same interface you are getting Internet (Need hardware support. Usually require same channel)
- Transparent proxy (redsocks)
- Transparent DNS proxy (hijack port 53 packets)
- Detect and prevent interference from following Linux system daemons:
- NetworkManager (handle interface (un)managed status)
- firewalld (use temporary
trusted zone)
- Instances managing. You can run multiple instances, to create different sub-networks.
For many other features, see below CLI usage
Useful in these situations
Internet----(eth0/wlan0)-Linux-(wlanX)AP
|--client
|--client
Internet
WiFi AP(no DHCP) |
|----(wlan1)-Linux-(eth0/wlan0)------
| (DHCP)
|--client
|--client
Internet
Switch |
|---(eth1)-Linux-(eth0/wlan0)--------
|--client
|--client
Internet----(eth0/wlan0)-Linux-(eth1)------Another PC
Internet----(eth0/wlan0)-Linux-(virtual interface)-----VM/container
Install
1-file-script. Release on Linux-router repo on Github. 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
| Linux distro |
|
| Any |
download 1-file-script and run without installation |
Dependencies
- bash
- procps or procps-ng
- iproute2
- dnsmasq
- iptables (or nftables with
iptables-nft translation linked)
- WiFi hotspot dependencies
- hostapd
- iw (or iwconfig, when iw can not recognize adapter)
- haveged (optional)
- crda and wireless-regdb (optional)
Usage
Provide Internet to an interface
sudo lnxrouter -i eth1
no matter which interface (other than eth1) you're getting Internet from.
Create WiFi hotspot
sudo lnxrouter --ap wlan0 MyAccessPoint -p MyPassPhrase
no matter which interface you're getting Internet from (even from wlan0). Will create virtual Interface x0wlan0 for hotspot.
Provide an interface's Internet to another interface
Clients access Internet through only isp5
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:
- Stop serving local DNS
- Tell clients which DNS to use (ISP5's DNS. Or, a safe public DNS, like above example)
Create LAN without providing Internet
sudo lnxrouter -n -i eth1
sudo lnxrouter -n --ap wlan0 MyAccessPoint -p MyPassPhrase
Internet for LXC
Create a bridge
sudo brctl addbr lxcbr5
In LXC container config
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxcbr5
lxc.network.hwaddr = xx:xx:xx:xx:xx:xx
sudo lnxrouter -i lxcbr5
Transparent proxy
All clients' Internet traffic go through, for example, Tor (notice this example is NOT an anonymity use)
sudo lnxrouter -i eth1 --tp 9040 --dns 9053 -g 192.168.55.1 -6 --p6 fd00:5:6:7::
In torrc
TransPort 192.168.55.1:9040
DNSPort 192.168.55.1:9053
TransPort [fd00:5:6:7::1]:9040
DNSPort [fd00:5:6:7::1]:9053
Warn: Tor's anonymity relies on a purpose-made browser. Using Tor like this (sharing Tor's network to LAN clients) will NOT ensure anonymity.
Although we use Tor as example here, Linux-router does NOT ensure nor is NOT aiming at anonymity.
Clients-in-sandbox network
To not give our infomation to clients. Clients can still access Internet.
sudo lnxrouter -i eth1 \
--tp 9040 --dns 9053 \
--random-mac \
--ban-priv \
--catch-dns --log-dns # optional
Linux-router comes with no warranty. Use on your own risk
Use as transparent proxy for LXD
Create a bridge
sudo brctl addbr lxdbr5
Create and add a new LXD profile overriding container's eth0
lxc profile create profile5
lxc profile edit profile5
### profile content ###
config: {}
description: ""
devices:
eth0:
name: eth0
nictype: bridged
parent: lxdbr5
type: nic
name: profile5
lxc profile add <container> profile5
sudo lnxrouter -i lxdbr5 --tp 9040 --dns 9053
To remove that new profile from container
lxc profile remove <container> profile5
To not use profile
Add new eth0 to container overriding default eth0
lxc config device add <container> eth0 nic name=eth0 nictype=bridged parent=lxdbr5
To remove the customized eth0 to restore default eth0
lxc config device remove <container> eth0
Use as transparent proxy for VirtualBox
In VirtualBox's global settings, create a host-only network vboxnet5 with DHCP disabled.
sudo lnxrouter -i vboxnet5 --tp 9040 --dns 9053
Use as transparent proxy for firejail
Create a bridge
sudo brctl addbr firejail5
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's /etc/resolv.conf doesn't obtain DNS from DHCP, so we need to assign.
nscd is domain name cache service, which shouldn't be accessed from in jail here.
CLI usage and other features