I am trying to access a server through a device by connecting to a laptop WiFi Hotspot
But when I create the WiFi Hotspot like this:
nmcli con add type wifi ifname wlp1s0 con-name Hotspot autoconnect yes ssid Hotspot
nmcli con modify Hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify Hotspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hotspot wifi-sec.psk "1234567890"
nmcli con up Hotspot
And then connect the device (a phone, for example) to the Hotspot it gets the IP 10.42.0.XXX
, therefore I acces to a docker container (with port 8080 exposed) inside the PC by typing 10.42.0.1:8080
. I get the NGINX welcom page as expected, but I would like to use the range 192.168.x.x/24
.
So I run the following commands in between the other ones:
nmcli con modify Hotspot ipv4.addresses 192.168.5.0/24
nmcli con modify Hotspot ipv4.gateway 192.168.5.1
But this way it doesn't work as expected.
I realized that without setting the IP range I have the following config:
$ ifconfig wlp1s0 && route -n
wlp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.42.0.1 netmask 255.255.255.0 broadcast 10.42.0.255
inet6 fe80::30ab:dc89:3b7d:e101 prefixlen 64 scopeid 0x20<link>
ether a8:93:4a:9b:be:f1 txqueuelen 1000 (Ethernet)
RX packets 21617 bytes 11699951 (11.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14221 bytes 2157291 (2.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.42.0.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp1s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 docker0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 br-179cb5c6e48f
But if I set the IP range:
$ ifconfig wlp1s0 && route -n
wlp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.5.0 netmask 255.255.255.0 broadcast 192.168.5.255
inet6 fe80::d001:c40e:19c3:7b5b prefixlen 64 scopeid 0x20<link>
ether a8:93:4a:9b:be:f1 txqueuelen 1000 (Ethernet)
RX packets 21617 bytes 11699951 (11.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14276 bytes 2165964 (2.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.5.1 0.0.0.0 UG 20600 0 0 wlp1s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 docker0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 docker-bridge
192.168.5.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp1s0
So I thought that if changed the differences manually (set the interface IP and the route) it would work again. So I runned:
nmcli con add type wifi ifname wlp1s0 con-name Hotspot autoconnect yes ssid Hotspot
nmcli con modify Hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
// New commands
nmcli con modify Hotspot ipv4.addresses 192.168.5.0/24
nmcli con modify Hotspot ipv4.gateway 192.168.5.1
///////////////
nmcli con modify Hotspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hotspot wifi-sec.psk "1234567890"
nmcli con up Hotspot
// New commands
sudo ifconfig wlp1s0 192.168.5.1 netmask 255.255.255.0
sudo route add -net 192.168.5.0/24 dev wlp1s0
///////////////
So I end up with the same config that worked but using 192.168.x.x
wlp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.5.1 netmask 255.255.255.0 broadcast 192.168.5.255
inet6 fe80::1f9f:4fbf:1b61:1da7 prefixlen 64 scopeid 0x20<link>
ether a8:93:4a:9b:be:f1 txqueuelen 1000 (Ethernet)
RX packets 21617 bytes 11699951 (11.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14413 bytes 2188200 (2.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 docker0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 docker-bridge
192.168.5.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp1s0
But this way I can't even connect to the Hotspot!
On another hand if I set the IP addres throug the nm-connection-edit
gui, the devices can connect to the hotspot but they don't even appear in the arp table and no listening service can be accessed.
What I am missing?
iptables dosn't change so I don't have to modify it.
Thanks.