LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2022, 11:58 AM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,612

Rep: Reputation: 180Reputation: 180
How to config WiFi hot-spot for LAN


I'm trying to figure out a setup I've been working on for some time. I'm using /etc/rc.d/rc.inet1.conf, not rc.networkmanager. I have the following LAN config:

ROUTER - wired, 192.168.0.1
HOTSPOT - wireless, IP 192.168.43.1

HOSTA - wlan0 connected via wireless, IP 192.168.43.66. eth0, wired, IP 192.168.0.17, netmask, 255.255.0.0, gateway 192.168.43.1
/etc/resolv.conf = nameserver 192.168.43.1

HOSTB - eth0, wired. IP 192.168.0.15. Gateway?

HOSTA works just fine, as one would supposed. I'd like HOSTB to connect to the Internet, obviously routing through HOSTA.

My issues is that ROUTER is down for the time being due to ISP maintenace. HOSTA has a wireless interface. HOSTB does not. furthermore, ROUTER's WAN IP is that of the domain name for the mail server hosted on HOSTB. When ROUTER sputters to life every so often, HOSTB can at least collect email.

So, I'd like to have HOSTA connecting to the Internet via HOTSPOT, which it does. I'd also like HOSTA and HOSTB to be able to connect via the wired net 192.168.0.0/24.

Can this be done?

I'm thinking that I need something like the following on HOSTA
Code:
iptables --table nat --append POSTROUTING --out-interface wlan0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT
So far, I've tried setting the above IP tables rule. I've hard-coded HOSTB (no DHCP) to 192.168.0.15, 255.255.0.0 with gateway = 192.168.0.17 and resolv.conf also set to 192.168.0.17.

This didn't work. Furthermore, with HOSTA set to:
Code:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.17  netmask 255.255.0.0  broadcast 192.168.255.255

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.43.66  netmask 255.255.255.0  broadcast 192.168.43.255
I can't connect to the Internet. Pinging yahoo.com gives:
Code:
# ping yahoo.com
PING yahoo.com (74.6.231.21) 56(84) bytes of data.
From 192.168.0.17 (192.168.0.17) icmp_seq=1 Destination Host Unreachable
From 192.168.0.17 (192.168.0.17) icmp_seq=2 Destination Host Unreachable
with /etc/resolv.conf set to 192.168.43.1, I don't get why it's trying to connect via the 192.168.0.17 interface. Why is it not using 192.168.43.1?

Any suggestions? Possibly a 2nd network card in HOSTB?

Last edited by mfoley; 04-25-2022 at 12:01 PM.
 
Old 04-29-2022, 03:38 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,455

Rep: Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353Reputation: 2353
You'd need a dhcp server, surely?

Personally, I think the whole idea is crazy. But that's just me. Your router is still your line out. Why not use your mobile as a wifi hotspot if you just want to collect email?

If you ask a network question, better include a sketch. I've no clue what your wifi route is to the 'wifi hotspot,' or why you need it.
 
Old 05-26-2022, 12:52 AM   #3
WindowMaker
LQ Newbie
 
Registered: Apr 2022
Distribution: Debian
Posts: 12

Rep: Reputation: 1
Arrow Emergency tethering of the entire LAN to a Wi-Fi AP

@business_kid is right about having a diagram would help getting your question answered much more quickly; since having to imagine all that from description alone is cumbersome and error-prone. But regarding the scenario, I have personally been in about the same network situation as you described before; so I don't think that "the whole idea is crazy" at all.

From your description, I figured that your "normal" network situation looks like this:
Code:
+---------+
| Hotspot |-----------------------------------------------------> Internet
+---------+                                                       via ISP 1
(localnet) 192.168.43.1/24

 _--^^--_   wlan0
   _--_     192.168.43.66/24
+---------+                                 +--------+
| Host A  |---------------------------------| Router |----------> Internet
+---------+ eth0                 (localnet) +--------+            via ISP 2
            192.168.0.17/16  192.168.0.1/16      |
                                                 |
+---------+                                      |
| Host B  |--------------------------------------+
+---------+ eth0
            192.168.0.15/16
But one day, your connection to ISP 2 went kaput, and you were left with:
Code:
+---------+
| Hotspot |-----------------------------------------------------> Internet
+---------+                                                       via ISP 1
(localnet) 192.168.43.1/24

 _--^^--_   wlan0
   _--_     192.168.43.66/24
+---------+                                 +--------+
| Host A  |---------------------------------| Router |
+---------+ eth0                 (localnet) +--------+
            192.168.0.17/16  192.168.0.1/16      |
                                                 |
+---------+                                      |
| Host B  |--------------------------------------+
+---------+ eth0
            192.168.0.15/16
And in this emergency situation, Host A was still able to get to the Internet; but you would like Host B to have Internet access too, by having Host A share its connection; hence what you tried on your original post.

But here comes the first confusing part:
Quote:
Originally Posted by mfoley View Post
I'd like HOSTB to connect to the Internet, obviously routing through HOSTA.
Quote:
Originally Posted by mfoley View Post
When ROUTER sputters to life every so often, HOSTB can at least collect email.
I found that it is very unlikely (at least in typical small home & office configuration) that ISP 2-side maintenance would make the Router itself become completely unavailable for localnet LAN use. And even if that was true, it would be nigh impossible to do both things you wished to do at the same time in that case anyway; without additional hardware that is.

So I suspect that by "ROUTER is down for the time being due to ISP maintenace" and "ROUTER sputters to life every so often"; you didn't actually mean the Router itself, but you meant the connection between the Router and ISP 2-- and the Router (hardware) itself was actually fine.

The second confusing part is:
Quote:
Originally Posted by mfoley View Post
Pinging yahoo.com gives:
Code:
# ping yahoo.com
PING yahoo.com (74.6.231.21) 56(84) bytes of data.
From 192.168.0.17 (192.168.0.17) icmp_seq=1 Destination Host Unreachable
From 192.168.0.17 (192.168.0.17) icmp_seq=2 Destination Host Unreachable
with /etc/resolv.conf set to 192.168.43.1, I don't get why it's trying to connect via the 192.168.0.17 interface. Why is it not using 192.168.43.1?
Was what you quoted being `ping` running on Host A itself? Or was it a `ping` running on Host B? From the flow of your description, I'm going to assume that was running on Host A.

-----

If there was one glaring thing that looked very suspicious here however, it would be the subnet masks.

You shown that you configured Host A to use one 255.255.0.0 subnet, and another 255.255.255.0 subnet, but with the same prefix (192.168.x.x); so they overlapped and clashed:
  • 192.168.0.17 netmask 255.255.0.0: means subnet address range of 192.168.0.0 ~ 192.168.255.255
  • 192.168.43.66 netmask 255.255.255.0: means subnet address range of 192.168.43.0 ~ 192.168.43.255
^ See that both address ranges overlap?

So when Host A tried to send something to the Internet (which it had to send via default gateway 192.168.43.1) it got confused as it saw gateway address belonging to both ranges, and it happened to choose the first one to send the data to: through `eth0`. Obviously, it was the opposite way from the one that actually went to the Internet; so you didn't get to the Internet that day.

^ That's likely the reason why you got an ICMP error reported from 192.168.0.17 (eth0) side; because Host A had sent ARP probe out on `eth0`, and didn't find any host with 192.168.43.1 address.

So the first part of the fix is you have to configure Host A's `eth0` interface to use a subnet mask of 255.255.255.0 , rather than 255.255.0.0 that you have used. If things gone according to the plan, Host A would be able to access the Internet again after applying this step.

Once the Internet access on Host A got restored, then you should at least re-confirm the proper connectivity between Host A and Host B once before continuing, by running `ping 192.168.0.17` on Host B. If that succeeded, then you could proceed to the connection sharing part.

On the connection sharing side of Host A, I could see following issues:
  1. Linux kernel wouldn't do inter-host routing by default; you have to enable certain specific sysctl configuration first.
  2. Once you did that, the `iptables --append FORWARD --in-interface eth0 -j ACCEPT` is usually unnecessary.
  3. When NAT'ing (i.e. `-j MASQUERADE`), you should also specify who (i.e. which source addresses) you're going to perform NAT for as well; to prevent it from applying NAT to wrong kinds of traffic.
So as the second part of the fix, I would suggest replacing your set of Host A configuration commands with the following:
Code:
sysctl -w net.ipv4.ip_forward=1
iptables --table nat --append POSTROUTING --source 192.168.0.0/24 --out-interface wlan0 -j MASQUERADE
On the Host B side, I saw following issue:
  1. Host A doesn't run a DNS server; so you have to make Host B use Hotspot's DNS server directly.
  2. Host B used 255.255.0.0 subnet mask; which prevents it from being able to use Hotspot's DNS server.
So the third and last part of the fix, I would suggest that you apply the following changes to Host B to:
  • Use static IP address 192.168.0.15, subnet mask 255.255.255.0 (there are three 255s), default gateway 192.168.0.17 (i.e. Host A's `eth0` side).
  • Make its `resolv.conf` to point to 192.168.43.1 (i.e. the Hotspot).
Once applied, you would have to test IP-level Internet connectivity first, without relying on DNS: by having Host B ping some known Internet host IP address, like running `ping 8.8.8.8` . If that succeeded, then you can test it in combination with DNS lookup, by running something like `ping gnu.org` there.

If these all went well, then you should be able to access the Internet from Host B now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Hot not-Spot-bot spot: The code behind Xiaomi's CyberDog? Ubuntu LXer Syndicated Linux News 0 12-04-2021 01:06 PM
Trying to add a WiFi hot spot to my LAN - routing issue I think. taylorkh Linux - Networking 6 12-18-2017 11:51 AM
Hot Spot Login Troubles dutch1918 Linux - Networking 3 04-02-2006 08:37 AM
Cursor hot spot won't stay put! markhall Linux - General 4 05-09-2003 08:26 AM
Wi-Fi Hot Spot software greenranger Linux - Networking 0 03-17-2003 10:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration