0

I have a raspberry pi 2 with a lan interface (eth0) and wan interface (wlan0)- usb wifi adapter. My OS is raspbian. I want to use my raspberry as a wifi AP. So, it is necessary to have a ics-dhcp-server running on my wlan0.

I want to have a shared local network, so PCs and wi-fi clients can see each other. So:

  • PC's are connected to router's (192.168.254.4) lan with wired connection and they have static ip in range 192.168.254.1 - 192.168.254.99 (except 192.168.254.4). The Raspberry Pi LAN ip is 192.168.254.97.
  • Wi-FI clients are connected to my raspberry pi and should have ip in range of 192.168.254.201 - 192.168.254.250. The Raspberry Pi wlan ip is 192.168.254.200.

An internet goes from lan to wlan using MASQERADE.

My configs are:

cat /etc/dhcp/dhcpd.conf:

subnet 192.168.254.0 netmask 255.255.255.0 {
interface wlan0;
    range 192.168.254.201 192.168.254.250;
    option broadcast-address 192.168.254.255;
        option routers 192.168.254.200;
    default-lease-time 600;
    max-lease-time 7200;
    option domain-name "local";
    option domain-name-servers 8.8.8.8, 8.8.4.4, 64.6.64.6, 64.6.65.6;
host wlan0 {
fixed-address 192.168.254.200;
}
}

cat /etc/default/isc-dhcp-server:

INTERFACESv4="wlan0"

cat /etc/dnsmasq.conf

interface=wlan0
dhcp-range=192.168.254.201,192.168.254.250,255.255.255.0,24h

cat /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.254.97
static routers=192.168.254.4
# 192.168.254.4 
static domain_name_servers=192.168.254.4
static domain_search=

interface wlan0
static ip_address=192.168.254.200/24
nohook wpa_supplicant
static routers=
static domain_name_servers=
static domain_search=

With this configs i get errors when trying to start isc-dhcp-server:

Multiple interfaces match the same subnet: eth0 wlan0
 Multiple interfaces match the same shared network: eth0 wlan0
 Can't bind to dhcp address: Address already in use

Where is the mistake in my configs?

2 Answers 2

0

The first mistake is having multiple interfaces in the same subnet. The second mistake is that you're heavily mixing up what a router does (masquerading, serving DHCP) and what an access point does (giving access to the same subnet). In a sense, they actually do opposite things.

  • A router connects two whole networks. It does not connect two halves of the same network – after all, if a host is "is in the same subnet", that literally means that it's accessible without going through a router.

    So if you want to use the Raspberry Pi as a router (with MASQUERADE or without), then the two interfaces have to use different network numbers – it can't be the same 192.168.254.0/24 on both sides.

    But you said "I want to have a shared local network", so you don't actually want to use your Raspberry Pi as a router – you want to use it as an access point.

  • An access point is not a router, it's a bridge. An access point does not need to serve DHCP, because it simply forwards the DHCP requests to the previous router that you already have. It also doesn't need to 'MASQUERADE' anything, because it only deals with a single network anyway.

    If you want both Wi-Fi and Ethernet to be in a single subnet for an AP, they have to be explicitly bridged together. Once bridged, eth0 and wlan0 will stop having IP addresses of their own – only the bridge itself, "br0", will need an address.

    (An access point can serve DHCP – but only if your main router doesn't. Remember, you wanted a single shared network, and there needs to be only one DHCP server across the entire network.)

So if you want to set up an AP, there are existing articles about "raspbian bridge", specifically https://www.raspberrypi.org/documentation/configuration/wireless/access-point-bridged.md will also work on Raspbian.

(But not https://www.raspberrypi.org/forums/viewtopic.php?t=132674 – that's high up in Google results, but it actually tells you how to set up a router, not a bridge. Ignore that page.)

But in short, what you should do is:

  1. Remove the 'MASQUERADE' firewall rule (it only applies to routers, not to bridges);

  2. Remove both 'interface eth0' and 'interface wlan0' from your dhcpcd.conf;

  3. Configure /etc/systemd/network/br0.netdev to create the bridge through systemd-networkd:

    [NetDev]
    Name=br0
    Kind=bridge
    

    Don't forget to systemctl enable systemd-networkd.

  4. Similarly, configure systemd-networkd to set eth0 as a member of br0. (Only eth0 – hostapd itself will handle wlan0.)

  5. Assign an IP address to br0, either through systemd-networkd or dhcpcd (doesn't matter).

  6. Tell hostapd to put wlan0 in the bridge as well:

    interface=wlan0
    bridge=br0
    

    (This has to be done via hostapd because wlan0 only becomes bridgeable when it's actually switched to "access point" mode.)

0

Thanks for the answer.

I've done this steps:

  1. Removed firewall rule MASQUERADE

  2. Removed interface eth0 and wlan0 from /etc/dhcpcd.conf

  3. created /etc/systemd/network/br0.netdev with:

    [NetDev]

    Name=br0

    Kind=bridge

  4. created /etc/systemd/network/br0-slave.network with:

    [Match]

    Name=eth0

    [Network]

    Bridge=br0

  5. created /etc/systemd/network/br0.network with:

    [Match] Name=br0

    [Network]

    Address=192.168.254.106/24

    Gateway=192.168.254.4

    DNS=192.168.254.4

  6. my /etc/hostapd/hostapd.conf now is:

    interface=wlan0

    #country=RU

    bridge=br0

    driver=nl80211

    #driver=ath9k_htc

    #driver=mt7601u

    ssid=somename

    hw_mode=g

    channel=7

    wmm_enabled=0

    macaddr_acl=0

    auth_algs=1

    ignore_broadcast_ssid=0

    wpa=2

    wpa_passphrase=somepass

    wpa_key_mgmt=WPA-PSK

    wpa_pairwise=TKIP

    rsn_pairwise=CCMP

    logger_syslog=-1

  7. Also i've added a "killall wpa_supplicant" in my /etc/rc.local, so now it is:

    rfkill unblock wifi

    killall wpa_supplicant

    exit 0

And rebooted. Now i have a working AP with internet, but when i try to connect to any server/site with my Raspberry, there is no connection (can't do apt-get install ... or ping google.com - host is unreachable). Also i can see old ip address on my eth0 (192.168.254.105) though it is commented in my /etc/dhcpcd.conf. Where else i can find my old eth0 ip address for deleting it?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .