You could share your knowlage with TC forumites.
Hi neonix and forumites. I'll be happy to share.
You need two network interfaces on the machine you want to use as wireless router. A typical setup is a wired internet connection (eth0) and a wifi usb adapter that will serve as access point (wlan1). If you don't have a wifi usb adapter, you can alternatively use your machine's internal wireless card (wlan0) as access point. Note that the access point's range will most likely be much better if you use a wifi usb adapter.
The wireless device you intend to use as access point (whether wlan1 or wlan0) needs to show up in the output of ifconfig -a . If it doesn't, you need to fix that by loading the necessary driver and firmware. Using a wireless device that has an in-kernel driver (i.e., a device whose driver is included in the wireless-KERNEL.tcz extension) will save you many headaches.
Once you've determined that your wireless device appears in the output of ifconfig -a , the only other thing to check is that it supports AP (access point) mode. To find out, check the output of iw list :
$ tce-load -wi iw
$ iw list
Wiphy phy1
...
Supported interface modes:
* IBSS
* managed
* AP <-- this is what you need
* AP/VLAN
* monitor
* P2P-client
* P2P-GO
* outside context of a BSS
Assuming everything above checks out, let's create a TCL-powered wireless router in 3 easy steps
1. Load the necessary extensions:
(These are all available in the TCL15 x86_64 repository. I haven't checked other TCL versions and architectures.)
$ tce-load -wi iproute2 iptables dnsmasq hostapd
2. Create this script somewhere in your PATH. I will create it at /home/tc/.local/bin/create-ap:
#!/bin/sh
# create-ap v1.0 (29Sept2024)
# Bruno "GNUser" Dantas (GPLv3)
# Purpose: Turn a GNU/Linux system into a wireless router
# Dependencies: iproute2 iptables dnsmasq hostapd
# Syntax: $ sudo create-ap <lan_if> <wan_if> <ssid> <passphrase>
# Example usage: $ sudo create-ap wlan1 eth0 TCLRocks TopSecret123
# To turn off the hotspot: $ sudo pkill hostapd; sudo pkill dnsmasq
# user variables:
lan_if="$1"
wan_if="$2"
ssid="$3"
password="$4"
ip_stem=192.168.50
channel=6
#dns_server=1.1.1.1
main()
{
prevent_nm_interference
setup_kernel
setup_nat
setup_dhcp
setup_ap
}
prevent_nm_interference()
{
nmcli dev set "$lan_if" managed no >/dev/null 2>&1
}
setup_kernel()
{
echo 1 >/proc/sys/net/ipv4/conf/"$wan_if"/forwarding
echo 1 >/proc/sys/net/ipv4/ip_forward
}
setup_nat()
{
iptables -t nat -A POSTROUTING -o "$wan_if" -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i "$lan_if" -o "$wan_if" -j ACCEPT
}
setup_dhcp()
{
# first, bring up $lan_if and give it a suitable ip address:
if ip link set "$lan_if" up; then
ip addr add $ip_stem.1/24 dev "$lan_if"
else
echo "$lan_if does not exist or cannot be brought up. Make sure necessary driver +/- firmware is installed." >&2
exit 1
fi
# create dnsmasq config file:
echo "
dhcp-leasefile=/tmp/dnsmasq.leases
dhcp-range=$ip_stem.100,$ip_stem.200,255.255.255.0,24h
#dhcp-option-force=option:dns-server,$dns_server
" >/tmp/dnsmasq.conf
# start dnsmasq (with care not to clash with any dnsmasq instances that might already be running):
dnsmasq --interface="$lan_if" --bind-interfaces --except-interface=lo -C /tmp/dnsmasq.conf
}
setup_ap()
{
# create hostapd config file:
echo "
ssid=$ssid
interface=$lan_if
driver=nl80211
channel=$channel
ignore_broadcast_ssid=0
hw_mode=g
auth_algs=1
wpa=2
wpa_passphrase=$password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
# N
ieee80211n=1
wmm_enabled=1
" >/tmp/hostapd.conf
# start hostapd:
hostapd /tmp/hostapd.conf &
}
main
Don't forget to make the script executable:
$ chmod a+x /home/tc/.local/bin/create-ap
3. Run the script. For example:
sudo create-ap wlan1 eth0 TCLRocks TopSecret123
Now your various wifi-equipped devices can connect to the wifi hotspot with SSID "TCLRocks" using the password "TopSecret123".
Any questions, just let me know