How can I set ip addres for wlan adapter using systemd?

by Ken   Last Updated September 16, 2019 13:01 PM

I would like to set up my Ubuntu18.04 box for WiFi access point using hostapd. I could succeeded the goal if I manually set up wlan adapter, but I couldn't automatically bring it up when reboot. So I would like to bring WiFi access point up automatically when reboot.

The name of wlan adapter is wlp2s0.

$ sudo lshw -class network -short
H/W path               Device      Class          Description
==========================================================
/0/100/13/0            enp1s0        network        RTL8111/8168/8411 PCI Express Gigabit Ethernet Controll
/0/100/13.3/0          wlp2s0        network        Dual Band Wireless-AC 3168NGW [Stone Peak]

The configuration of hostapd is as follows.

/etc/hostapd/hostapd.conf

interface=wlp2s0
hw_mode=g
channel=10
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK  
rsn_pairwise=CCMP
ssid=ssid
wpa_passphrase=passphrase

Need to set up DHCP server to distribute ip address for WiFi client hosts. Here is my configuration file for isc-dhcp-server.

/etc/dhcp/dhcpd.conf

ddns-update-style none;
authoritative;

subnet 192.168.11.0 netmask 255.255.255.0 {
  range 192.168.11.10 192.168.11.100;
  option routers 192.168.11.1;
  option subnet-mask 255.255.255.0;
  option domain-name-servers 10.0.0.1;
}

I could successfully bring DHCP server up if manually set ip address of wlan adapter.

$ sudo ip address add 192.168.11.1/24 dev wlp2s0
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 98:ee:cb:7b:44:31 brd ff:ff:ff:ff:ff:ff
    inet 10.0.11.1/8 brd 10.255.255.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::9aee:cbff:fe7b:4431/64 scope link 
       valid_lft forever preferred_lft forever
3: wlp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether f8:63:3f:79:5e:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.1/24 scope global wlp2s0
       valid_lft forever preferred_lft forever

I obtained the result below if I omit to set ip address for wlan adapter,

$ sudo systemctl restart isc-dhcp-server
$ sudo systemctl status isc-dhcp-server
‚óŹ isc-dhcp-server.service - ISC DHCP IPv4 server
   Loaded: loaded (/lib/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-09-16 18:39:11 JST; 56s ago
     Docs: man:dhcpd(8)
  Process: 12287 ExecStart=/bin/sh -ec      CONFIG_FILE=/etc/dhcp/dhcpd.conf;      if [ -f /etc/ltsp/dhcpd.conf ]; then CONFI
 Main PID: 12287 (code=exited, status=1/FAILURE)

Sep 16 18:39:11 goediy dhcpd[12287]: 
Sep 16 18:39:11 goediy dhcpd[12287]: Not configured to listen on any interfaces!
Sep 16 18:39:11 goediy dhcpd[12287]: 
Sep 16 18:39:11 goediy dhcpd[12287]: If you think you have received this message due to a bug rather
Sep 16 18:39:11 goediy dhcpd[12287]: than a configuration issue please read the section on submitting
Sep 16 18:39:11 goediy dhcpd[12287]: bugs on either our web page at www.isc.org or in the README file
Sep 16 18:39:11 goediy dhcpd[12287]: before submitting a bug.  These pages explain the proper
Sep 16 18:39:11 goediy dhcpd[12287]: process and the information we find helpful for debugging..
Sep 16 18:39:11 goediy dhcpd[12287]: 
Sep 16 18:39:11 goediy dhcpd[12287]: exiting.

I added configuration file for systemd-networkd, bcause I think wlan interface wlp2s0 needed to be set ip address of network 192.168.11.0/24 before starting DHCP server.

/etc/systemd/network/10-wlp2s0-static.network

[Match]
Name=wlp2s0

[Network]
Address=192.168.11.1/24

But the settings above is ignored. I couln't get wlp2s0 to be set ip address as expected when I restarted systemd-networkd.

$ sudo systemctl restart systemd-networkd
$ sudo systemctl status systemd-networkd
$ ip a 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 98:ee:cb:7b:44:31 brd ff:ff:ff:ff:ff:ff
    inet 10.0.11.1/8 brd 10.255.255.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::9aee:cbff:fe7b:4431/64 scope link 
       valid_lft forever preferred_lft forever
3: wlp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether f8:63:3f:79:5e:0a brd ff:ff:ff:ff:ff:ff
$ sudo networkctl -a
IDX LINK             TYPE               OPERATIONAL SETUP     
  1 lo               loopback           carrier     unmanaged 
  2 enp1s0           ether              routable    unmanaged 
  3 wlp2s0           wlan               no-carrier  configuring

Does anyone know how to set ip address to wlp2s0 or another solution to get work DHCP server?



Related Questions




udhcpd instance reports address already in use

Updated March 26, 2017 21:01 PM