DHCP Server Setting the Server IP Address

Ask questions about Arch Linux ARM. Please search before making a new topic.

DHCP Server Setting the Server IP Address

Postby jawj » Wed Jun 29, 2016 11:48 pm

Hi Everyone,

I am new to Arch and have been struggling with this networking issue for some time now. Here is the situation:

I am running Arch Linux Arm on a Raspberry Pi 3. I intend to use it as a hub to connect wireless devices to so that each device (and the RPi) can communicate with each other.

I have installed hostapd and dhcpd, enabled them in systemctl (sudo systemctl enable hostapd dhcpd4). The RPi allows devices to connect to it and gives IP addresses out correctly. Note that i don't want to share the internet connection on eth0 with this network on the wlan0, just create a local network for devices to talk to each other on (and the server).

My issue is: i cannot figure out how to statically set the IP address of the server so that i am able to communicate from the server to the devices (i've tried googling this many different ways but it just comes up with guides to setting up dhcpd). My problem is solved by manually setting "ip addr add 33.3.3.1/24 broadcast 33.3.3.255 dev wlan0", but i want to automate this on boot. I have attempted to use netctl to statically set the IP of wlan0, but it does not work. I don't think this is the right use case for netctl, i am not connecting to the network using the ssid/password as it is already connected from my understanding. I have also tried doing this in a service, but again, it only works if i restart the service.

My config files for service, hostpd and dhcpd are as follows:
hostapd:
$this->bbcode_second_pass_code('', 'interface=wlan0
hw_mode=g
channel=11
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
ignore_broadcast_ssid=0
ssid=rpiAP
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
wpa_passphrase=****
')

dhcpd:
$this->bbcode_second_pass_code('', '
authoritative;
default-lease-time 600;
max-lease-time 7200;

subnet 33.3.3.0 netmask 255.255.255.0 {
interface wlan0;
local-address 33.3.3.1;
range 33.3.3.10 33.3.3.245;
# option domain-name-servers 8.8.8.8, 8.8.4.4;
option routers 33.3.3.1;
option broadcast-address 33.3.3.255;
option subnet-mask 255.255.255.0;
}
subnet 192.168.0.0 netmask 255.255.255.0 {
interface eth0;
}
')

AP.service in /etc/systemd/system:
$this->bbcode_second_pass_code('', '
[Unit]
Description=AP
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-wlan0.device
After=sys-subsystem-net-devices-wlan0.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/ip link set dev wlan0 up
ExecStart=/sbin/ip addr add 33.3.3.1/24 broadcast 33.3.3.255 dev wlan0
ExecStop=/sbin/ip addr flush dev wlan0
ExecStop=/sbin/ip link set dev wlan0 down
[Install]
WantedBy=multi-user.target
')


The output of "sudo systemctl status hostapd dhcpd4":
$this->bbcode_second_pass_code('', '
* hostapd.service - Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Loaded: loaded (/usr/lib/systemd/system/hostapd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2016-06-30 00:19:35 AEST; 7s ago
Main PID: 873 (hostapd)
Tasks: 1 (limit: 512)
CGroup: /system.slice/hostapd.service
`-873 /usr/bin/hostapd /etc/hostapd/hostapd.conf
Jun 30 00:19:35 alarmpi systemd[1]: Started Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator.
Jun 30 00:19:35 alarmpi hostapd[873]: Configuration file: /etc/hostapd/hostapd.conf
Jun 30 00:19:35 alarmpi hostapd[873]: Failed to create interface mon.wlan0: -95 (Operation not supported)
Jun 30 00:19:35 alarmpi hostapd[873]: wlan0: Could not connect to kernel driver
Jun 30 00:19:35 alarmpi hostapd[873]: Using interface wlan0 with hwaddr b8:27:eb:7c:c4:ec and ssid "rpiAP"
Jun 30 00:19:35 alarmpi hostapd[873]: wlan0: interface state UNINITIALIZED->ENABLED
Jun 30 00:19:35 alarmpi hostapd[873]: wlan0: AP-ENABLED
* dhcpd4.service - IPv4 DHCP server
Loaded: loaded (/usr/lib/systemd/system/dhcpd4.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2016-06-30 00:19:35 AEST; 8s ago
Process: 875 ExecStart=/usr/bin/dhcpd -4 -q -cf /etc/dhcpd.conf -pf /run/dhcpd4.pid (code=exited, status=0/SUCCESS)
Main PID: 877 (dhcpd)
Tasks: 1 (limit: 512)
CGroup: /system.slice/dhcpd4.service
`-877 /usr/bin/dhcpd -4 -q -cf /etc/dhcpd.conf -pf /run/dhcpd4.pid
Jun 30 00:19:35 alarmpi systemd[1]: Starting IPv4 DHCP server...
Jun 30 00:19:35 alarmpi dhcpd[875]: Source compiled to use binary-leases
Jun 30 00:19:35 alarmpi dhcpd[875]: Wrote 7 leases to leases file.
Jun 30 00:19:35 alarmpi dhcpd[875]: wlan0 missing an interface address
Jun 30 00:19:35 alarmpi dhcpd[877]: Server starting service.
Jun 30 00:19:35 alarmpi systemd[1]: Started IPv4 DHCP server.
Jun 30 00:19:38 alarmpi dhcpd[877]: DHCPDISCOVER from b8:27:eb:7c:c4:ec (alarmpi) via wlan0
Jun 30 00:19:39 alarmpi dhcpd[877]: DHCPOFFER on 33.3.3.10 to b8:27:eb:7c:c4:ec (alarmpi) via wlan0
Jun 30 00:19:40 alarmpi dhcpd[877]: DHCPDISCOVER from b8:27:eb:7c:c4:ec (alarmpi) via wlan0
Jun 30 00:19:40 alarmpi dhcpd[877]: DHCPOFFER on 33.3.3.10 to b8:27:eb:7c:c4:ec (alarmpi) via wlan0
Jun 30 00:19:44 alarmpi dhcpd[877]: DHCPDISCOVER from b8:27:eb:7c:c4:ec (alarmpi) via wlan0
Jun 30 00:19:44 alarmpi dhcpd[877]: DHCPOFFER on 33.3.3.10 to b8:27:eb:7c:c4:ec (alarmpi) via wlan0
')

I have a feeling it's got to do with the dhcpd offering 33.3.3.10 to wlan0 (the server), which it attempts to do 3 times with no success. I also think i need to remove "option routers 33.3.3.1;" from dhcpd.conf as i have read that it is used for get the gateway to the internet (which this network doesn't have).

Any help will be much appreciated. Thanks in advance, i've been struggling with this for weeks now but i think it's a bit beyond me to figure out!

-Jawj

edit: code tags
Last edited by jawj on Thu Jun 30, 2016 2:00 pm, edited 2 times in total.
jawj
 
Posts: 6
Joined: Wed Jun 29, 2016 11:36 pm

Re: DHCP Server Setting the Server IP Address

Postby moonman » Thu Jun 30, 2016 12:21 am

Please use code tags
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3388
Joined: Sat Jan 15, 2011 3:36 am

Re: DHCP Server Setting the Server IP Address

Postby jawj » Thu Jun 30, 2016 1:57 pm

$this->bbcode_second_pass_quote('moonman', 'P')lease use code tags


Sorry about that! I edited it, hopefully its all good now. Like I said, I'm new :P
jawj
 
Posts: 6
Joined: Wed Jun 29, 2016 11:36 pm

Re: DHCP Server Setting the Server IP Address

Postby WarheadsSE » Thu Jun 30, 2016 2:45 pm

What are you using now to configure the IP of the host?
Core Developer
Remember: Arch Linux ARM is entirely community donation supported!
WarheadsSE
Developer
 
Posts: 6807
Joined: Mon Oct 18, 2010 2:12 pm

Re: DHCP Server Setting the Server IP Address

Postby jawj » Fri Jul 01, 2016 10:47 am

$this->bbcode_second_pass_quote('WarheadsSE', 'W')hat are you using now to configure the IP of the host?


At the moment I am manually setting it. But I'd like it to be automated, so I've tried using that AP.service config file to run it as a service at startup using systemctl enable. Problem is, it doesn't work every time.

Plus I'm concerned about the dhcpd service trying to offer an IP address to the host in the set range (I assume this will go away once the IP address is set).

I know and have read that Arch uses netctl to set the IP statically, but I can't seem to get the config file correct. And there doesn't seem to be an example in the examples folder.

That aside, when I run networkctl it says that wlan0 is "configuring" even after I have manually set it with ip addr add.

I sure this is a newbie thing that I haven't done (or have done) because I'm so used to windows.
jawj
 
Posts: 6
Joined: Wed Jun 29, 2016 11:36 pm

Re: DHCP Server Setting the Server IP Address

Postby cmsigler » Fri Jul 01, 2016 12:34 pm

Hi,

Not sure if this will help as this relates to my wired network interfaces. On my ALARM systems I use systemd-networkd as that's the default setup. I've modified eth0.network to set up my IPv6 addresses and it WFM. I found the Arch systemd-networkd wiki page pretty easy to follow. HTH :)

Clemmitt
- Raspberry Pi 3
- Odroid-C2
- Raspberry Pi Zero
cmsigler
 
Posts: 37
Joined: Wed May 25, 2016 6:01 pm

Re: DHCP Server Setting the Server IP Address

Postby jawj » Sat Jul 02, 2016 2:13 am

$this->bbcode_second_pass_quote('cmsigler', 'H')i,

Not sure if this will help as this relates to my wired network interfaces. On my ALARM systems I use systemd-networkd as that's the default setup. I've modified eth0.network to set up my IPv6 addresses and it WFM. I found the Arch systemd-networkd wiki page pretty easy to follow. HTH :)

Clemmitt


Hi Clemmitt, thanks for the reply.

Yes, i have tried to use the systemd-networkd approach before. As far as i've read, the configuration file should work, but i can't seem to get it to work.

This is my config file:
$this->bbcode_second_pass_code('', 'alarm@alarmpi ~ $ cat /etc/systemd/network/wlan0.network
[Match]
Name=wlan0
Host=alarmpi

[Network]
Address=33.3.3.1/24
Gateway=33.3.3.1
')

This is the output of systemctl status systemd-networkd.service:
$this->bbcode_second_pass_code('', '* systemd-networkd.service - Network Service
Loaded: loaded (/usr/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2016-07-02 12:19:06 AEST; 21min ago
Docs: man:systemd-networkd.service(8)
Main PID: 262 (systemd-network)
Status: "Processing requests..."
Tasks: 1 (limit: 512)
CGroup: /system.slice/systemd-networkd.service
`-262 /usr/lib/systemd/systemd-networkd

Jul 02 12:19:06 alarmpi systemd[1]: Started Network Service.
Jul 02 12:19:06 alarmpi systemd-networkd[262]: wlan0: IPv6 enabled for interface: Success
Jul 02 12:19:06 alarmpi systemd-networkd[262]: eth0: IPv6 enabled for interface: Success
Jul 02 12:19:06 alarmpi systemd-networkd[262]: lo: Configured
Jul 02 12:19:07 alarmpi systemd-networkd[262]: wlan0: Gained carrier
Jul 02 12:19:07 alarmpi systemd-networkd[262]: eth0: Gained carrier
Jul 02 12:19:09 alarmpi systemd-networkd[262]: wlan0: Gained IPv6LL
Jul 02 12:19:09 alarmpi systemd-networkd[262]: eth0: Gained IPv6LL
Jul 02 12:19:11 alarmpi systemd-networkd[262]: eth0: DHCPv4 address 192.168.0.25/24 via 192.168.0.1
Jul 02 12:19:22 alarmpi systemd-networkd[262]: eth0: Configured
')

This is the output of ip addr:
$this->bbcode_second_pass_code('', '3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether b8:27:eb:7c:c4:ec brd ff:ff:ff:ff:ff:ff
inet6 fe80::ba27:ebff:fe7c:c4ec/64 scope link
valid_lft forever preferred_lft forever
')

As it states in that guide:

"If the wireless adapter has a static IP address, the configuration is the same (except for the interface name) as in a wired adapter."

And the wired adapter is as such:
$this->bbcode_second_pass_code('', '/etc/systemd/network/wired.network
[Match]
Name=enp1s0

[Network]
Address=10.1.10.9/24
Gateway=10.1.10.1')

and further down the guide, it says:

"Tip: you can put the Address= and Gateway= keys in the [Network] section as a short-hand if Address= contains only an Address key and Gateway= section contains only a Gateway key"

Which confirms why the Address= and Gateway= go under the [Network] section and not the [Address] section.

Just with general networking and setting up ip addresses, should i not give a "gateway" to the gateway? In my dhcpd config file, i have also listed the "option routers" with the host ip address, but in the documentation it mentions that the "option routers" gives the clients the address of the gateway to the internet... which is not what this setup is about. I'm just a bit confused really.
jawj
 
Posts: 6
Joined: Wed Jun 29, 2016 11:36 pm
Top

Re: DHCP Server Setting the Server IP Address

Postby cmsigler » Sat Jul 02, 2016 12:04 pm

Hi,

$this->bbcode_second_pass_code('', '
alarm@alarmpi ~ $ cat /etc/systemd/network/wlan0.network
[Match]
Name=wlan0
Host=alarmpi

[Network]
Address=33.3.3.1/24
Gateway=33.3.3.1
')
This may seem too simple to work -- and it may not fix the problem -- but...

Your "Gateway=" should not be identical to your "Address=", even though you intend the wireless network segment to be an isolated LAN with no upstream routing. This may cause weirdness in your IPv4 routing table. Give that a quick try and see if it makes any difference. HTH

P.S.: FYI, to conform to standards make your wireless network "10.3.3.x/24" instead of using "33" as the leading dotted quad. If you never route your LAN upstream there won't be an address clash, but just to be technically correct, which is the best kind of correct :D

Clemmitt
- Raspberry Pi 3
- Odroid-C2
- Raspberry Pi Zero
cmsigler
 
Posts: 37
Joined: Wed May 25, 2016 6:01 pm

Re: DHCP Server Setting the Server IP Address

Postby jawj » Tue Jul 05, 2016 7:23 am

$this->bbcode_second_pass_quote('cmsigler', 'H')i,

$this->bbcode_second_pass_code('', '
alarm@alarmpi ~ $ cat /etc/systemd/network/wlan0.network
[Match]
Name=wlan0
Host=alarmpi

[Network]
Address=33.3.3.1/24
Gateway=33.3.3.1
')
This may seem too simple to work -- and it may not fix the problem -- but...

Your "Gateway=" should not be identical to your "Address=", even though you intend the wireless network segment to be an isolated LAN with no upstream routing. This may cause weirdness in your IPv4 routing table. Give that a quick try and see if it makes any difference. HTH

P.S.: FYI, to conform to standards make your wireless network "10.3.3.x/24" instead of using "33" as the leading dotted quad. If you never route your LAN upstream there won't be an address clash, but just to be technically correct, which is the best kind of correct :D

Clemmitt


Thanks heaps Clemmitt.

I figured it out! So basically I've tried a few more different things to try and get it to work using systemd-networkd. The problem was from a rogue config file that was there by default in /etc/systemd/network/any0.network. It seems this was redefining the address as dhcp. Once I removed this, it worked straight away and gave my wlan0 a static IP. It did cause eth0 to lose it's internet connection though (arp command ran slow and after looking this up, it had something to do with the DNS). I restarted the pi and it seemed to have fixed the DNS issue. Maybe it had something to do with what you were talking about in terms of the gateway being the same as the address. I'll remove it just to be safe.

I hope all my other settings for the dhcp server are all good. I mean any device that connects to the server gets given an IP address so it should be all sweet. I'm still not 100% confident in my knowledge of networks and dns's and gateways and things like that, but I'm pretty sure it's all good now.

Thanks again bro
jawj
 
Posts: 6
Joined: Wed Jun 29, 2016 11:36 pm
Top

Re: DHCP Server Setting the Server IP Address

Postby cmsigler » Tue Jul 05, 2016 11:59 am

Hi,

Glad things are working better :) FWIW I have no idea where that any0.network file would come from.

I just realized I didn't say you can simply remove the "Gateway=" line from the wlan0.network file. Since any devices connecting over the wlan0 interface and wireless segment are LAN-only they don't need a default route so there is no gateway for wlan0.

The questions I have are, will your RPi3 complain when systemd-networkd configures wlan0 without "Gateway=", and will dhcpd on the RPi3 or the devices that connect to it complain if there is no gateway for DHCP to assign their default route. So, YMMV as I haven't tried this set-up myself....

Clemmitt
- Raspberry Pi 3
- Odroid-C2
- Raspberry Pi Zero
cmsigler
 
Posts: 37
Joined: Wed May 25, 2016 6:01 pm

Next

Return to User Questions

Who is online

Users browsing this forum: No registered users and 5 guests