toketin
Posts: 3
Joined: Mon Jun 16, 2014 10:44 pm

Rpi3 as Router with 4g dongle usb

Mon Aug 26, 2019 6:30 pm

Hi, following the guide wrote by a reddit user (https://filippobuletto.github.io/home-r ... escription) and this one (https://thepi.io/how-to-use-your-raspbe ... ess-point/) I've setup up the Rpi3 (under Raspbian) to act as wifi access point and I succesfully use it to share the 4g connection (usb0).

Since my goal is to use the pi as router i would like also to connect an host through its ethernet interface, but i'm not able to do this because i can't get an IP address by the DHCP server (Dnsmasq). I've tried to the way to use a bridge interface between eth0 and wlan0, but with this one i can't get an IP via wifi.

This are my related config files:

Code: Select all

/etc/hostapd/hostapd.conf:
interface=wlan0
#bridge=br0 --> commented because with bridge mode I can't get an IP address when connecting to this wifi, even if the bridge interface is up following the guide linked above.
country_code=it
driver=nl80211
ssid=MySSID
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=MyPasswd
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
ieee80211n=1          # 802.11n support
wmm_enabled=1         # QoS support
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

Code: Select all

/etc/network/interfaces:
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0

Code: Select all

/etc/dhcpcd.conf (last lines)
interface usb0
        static ip_address=192.168.0.163/24
        static routers=192.168.0.1
        static domain_name_servers=127.0.0.1
interface wlan0
        static ip_address=192.168.1.1/24
        static routers=192.168.1.1
        static domain_name_servers=127.0.0.1
denyinterfaces eth0
denyinterfaces wlan0

Code: Select all

/etc/dnsmasq.conf:
interface=wlan0
dhcp-range=192.168.1.20,192.168.1.254,255.255.255.0,24h
So just without using the bridge mode under hostapd I can connect to the Rpi wifi. What should I do in order to get the Rpi working both side wifi and ethernet as a router?


Thanks

Marco

epoch1970
Posts: 5203
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Rpi3 as Router with 4g dongle usb

Mon Aug 26, 2019 7:22 pm

In hostapd.conf, activate bridge=br0
In dhcpcd.conf:
- rename the line “interface wlan0” to “interface br0”
- remove the 2 “denyinterfaces” lines
- at the beginning of the file, before any interfaces block, add the line “denyinterfaces eth0 wlan0”
In dnsmsaq.conf, change “interface=wlan0” to “interface=br0”

You’ll need to reboot networking or preferably the whole machine after the changes to test it out.

(There is an official documentation for AP mode on raspberrypi.org, you could have used it. The thepio document you’ve linked is especially poor. I wish people would stop visiting that page written by someone visibly more interested in ad revenue than in networking.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

toketin
Posts: 3
Joined: Mon Jun 16, 2014 10:44 pm

Re: Rpi3 as Router with 4g dongle usb

Mon Aug 26, 2019 10:34 pm

Hi, thanks for your reply now I can connect to wifi getting the right IP but usb0 (internet key) doesn't work anymore on rpi side. I mean that I can't exit to internet and ping anymore. Is there any issue with packet's routing?

Edit: maybe it's due to a conflict on the gateway IPs, this is an ouput of ip route list:

Code: Select all

pi@raspberrypi:~ $ ip route list
default via 192.168.1.1 dev br0 src 192.168.1.1 metric 204 
default via 192.168.0.1 dev usb0 proto dhcp src 192.168.0.152 metric 205 
192.168.0.0/24 dev usb0 proto dhcp scope link src 192.168.0.152 metric 205 
192.168.1.0/24 dev br0 proto dhcp scope link src 192.168.1.1 metric 204

Return to “Networking and servers”