WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Use TC as a kind of router???  (Read 723 times)

Offline Richard Cranium

  • Newbie
  • *
  • Posts: 35
Use TC as a kind of router???
« on: August 26, 2024, 04:50:59 PM »
Not sure if I'm posting this in the right section , but possibly a silly question ..   is it possible to configure TC to act as a router? meaning , share internet connection : 

internet--> eth0, eth0 splits to eth1 --> machine 1 , eth2 --> machine 2, etc etc

is that doable??   and then set up a file sharing service?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11570
Re: Use TC as a kind of router???
« Reply #1 on: August 26, 2024, 05:45:19 PM »
Hi Richard Cranium
... is it possible to configure TC to act as a router? ...
Yes, it is. Is it worth the effort? Probably not. I've picked up 4, 6, and 8 port
routers for $5 each at garage sales. If you want to build a 4 port router, you
need 4 network cards for the ports plus a fifth network port for the internet
connection.

If I were to attempt this (which I wouldn't), I would google:
linux open source router
and use one of the existing router projects out there.

Quote
... set up a file sharing service?
File sharing is easier. There's  samba3.tcz  to share files with Windows.
If you install  cifs-utils.tcz  on your Linux machines, they can access it too.

There is  nfs-utils.tcz  if you only want to share with Linux.

Offline CNK

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 278
Re: Use TC as a kind of router???
« Reply #2 on: August 26, 2024, 08:05:11 PM »
Hi Richard Cranium
... is it possible to configure TC to act as a router? ...
Yes, it is. Is it worth the effort? Probably not. I've picked up 4, 6, and 8 port
routers for $5 each at garage sales. If you want to build a 4 port router, you
need 4 network cards for the ports plus a fifth network port for the internet
connection.

Actually those home routers generally have an Ethernet switch built in, rather than individual network interfaces for each Ethernet port. You can get small Ethernet switch devices that are separate and could be connected to the computer you run TC on. You might still need two Ethernet ports if your modem connects to one and the switch connects to the other. Some motherboards and SBCs have dual Ethernet ports. USB Ethernet adapters are also an option, at least if you don't need maximum network speed.

Old SOHO Ethernet switches can be as cheap as old routers, especially if you only need 100Mbit speed, but they're not as easily found as home routers.

If I were to attempt this (which I wouldn't), I would google:
linux open source router
and use one of the existing router projects out there.

I run OpenWRT on an old home router myself. OpenWRT supports the MIPS or ARM SoCs in many cheap routers, which TC doesn't, so you can use the cheap 2nd hand routers like Rich is talking about. There are tons of router models though so it can still be hard to find one that's supported.

Offline gadget42

  • Hero Member
  • *****
  • Posts: 765
The fluctuation theorem has long been known for a sudden switch of the Hamiltonian of a classical system Z54 . For a quantum system with a Hamiltonian changing from... https://forum.tinycorelinux.net/index.php/topic,25972.msg166580.html#msg166580

Offline neonix

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 391
Re: Use TC as a kind of router???
« Reply #4 on: September 03, 2024, 11:37:43 AM »
Using TC as software for router is very good idea.

1. More RAM than commercial routers, more sophisticated services.
2. Less probability of backdoor (if you update OS regularly)
2a) you can login only with mouse, keyboard and monitor
2b) you can compile your own software if you can
3. Almost unlimited LAN ports if you use USB-RJ45 adapters. Or optic fiber adapters.
4. Less susceptible for DDOS.

Disadvantages:
Lack of html interface
Biger power consuption
No autorun when there is problem with electricty
Risc of absolate certifiacates
Commmercial routers can worki in high temp and high humidity
Bigger risc for failure if moving parts are used  (ash, spiders, ants)

BTW. What are most popular services for this type router shoud have?

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1494
Re: Use TC as a kind of router???
« Reply #5 on: September 03, 2024, 12:42:41 PM »
For several years I've been using a laptop running TCL x86_64 as a wireless router in my home. AP is created by hostapd. DHCP server is dnsmasq. The amount of fun and learning I've gotten from this machine is off the charts. TCL works perfectly as a router OS.
« Last Edit: September 03, 2024, 12:45:52 PM by GNUser »

Offline CentralWare

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 760
Re: Use TC as a kind of router???
« Reply #6 on: September 06, 2024, 12:26:04 AM »
For supported hardware based routers: https://freshtomato.org or WRT
For x86/64 you need at very least two Ethernet ports (one in, one out)
For Arm (RasPi for example) a second Ethernet via USB (one in, one out)
** You could get away with a single Ethernet, but the speed would be 1/2 or less as
     you would be sharing it both inbound (eth0) and outbound (eth0:0)

Using IPTables or other similar firewall software, you set up forwarding and blocking rules
https://webmin.com can be used for a web interface to configure the firewall remotely

Example data only - not endorsements

Offline neonix

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 391
Re: Use TC as a kind of router???
« Reply #7 on: September 21, 2024, 07:08:49 AM »
I would like to boot my computer from pxe, and have NAS hard drive on router side, not on computer side. It takes a lot of  time to configure everything, but if we have hard drive version of TC with NAS support out-of-the-box it would be very innovative solution in Linix distributions world. Hard drive could have compressed file system, and extensions could be compressed with differnt algorithms like LZMA2, paq9, lzo.

Offline neonix

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 391
Re: Use TC as a kind of router???
« Reply #8 on: September 29, 2024, 10:02:43 AM »
For several years I've been using a laptop running TCL x86_64 as a wireless router in my home. AP is created by hostapd. DHCP server is dnsmasq. The amount of fun and learning I've gotten from this machine is off the charts. TCL works perfectly as a router OS.
You could share your knowlage with TC forumites.

    [Edit]: Added missing  ]  to closing quote tag.  Rich
« Last Edit: September 29, 2024, 10:39:34 AM by Rich »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1494
Re: Use TC as a kind of router???
« Reply #9 on: September 29, 2024, 06:08:07 PM »
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  :

Code: [Select]
$ 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.)

Code: [Select]
$ 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:

Code: [Select]
#!/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:
Code: [Select]
$ chmod a+x /home/tc/.local/bin/create-ap
3. Run the script. For example:
Code: [Select]
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 :)
« Last Edit: September 29, 2024, 06:38:43 PM by GNUser »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1494
Re: Use TC as a kind of router???
« Reply #10 on: September 29, 2024, 10:15:19 PM »
If you're going to buy a wifi usb adapter for this purpose, I highly recommend checking out morrownr's github pages, particularly these two:

https://github.com/morrownr/USB-WiFi/blob/main/home/The_Short_List.md
https://github.com/morrownr/USB-WiFi/blob/main/home/Performance_Comparison.md