Page 1 of 1

how not to need to do "sudo service isc-dhcp-server restart" each time i reboot

Posted: Thu Apr 26, 2018 6:18 pm
by loliveira
Hi, and the first time I write here, and now I'm starting to use my raspberry pi 3.

I followed a tutorial to create a wifi network with my pi 3, but every time I reboot it I need to run the "sudo service isc-dhcp-server restart" command for DHCp to work again. If anyone can help me solve this problem.

DHCP Error Occurs When I Restart
"
pi @ raspberrypi: ~ $ sudo service isc-dhcp-server status
● isc-dhcp-server.service - LSB: DHCP server
Loaded: loaded (/etc/init.d/isc-dhcp-server; generated; vendor preset: enable
Active: failed (Result: exit-code) since Thu 2018-04-26 18:15:09 UTC; 1min 26
Docs: man: systemd-sysv-generator (8)
Process: 546 ExecStart = / etc / init.d / isc-dhcp-server start (code = exited, status =

Apr 26 18:15:06 raspberrypi systemd [1]: Starting LSB: DHCP server ...
Apr 26 18:15:07 raspberrypi isc-dhcp-server [546]: Launching IPv4 server only.
Apr 26 18:15:07 raspberrypi dhcpd [596]: Wrote 2 leases to leases file.
Apr 26 18:15:09 raspberrypi isc-dhcp-server [546]: Starting ISC DHCPv4 server: dh
Apr 26 18:15:09 raspberrypi isc-dhcp-server [546]: failed!
Apr 26 18:15:09 raspberrypi systemd [1]: isc-dhcp-server.service: Control process
Apr 26 18:15:09 raspberrypi systemd [1]: Failed to start LSB: DHCP server.
Apr 26 18:15:09 raspberrypi systemd [1]: isc-dhcp-server.service: Unit entered fa
Apr 26 18:15:09 raspberrypi systemd [1]: isc-dhcp-server.service: Failed with res
lines 1-15 / 15 (END) ... skipping ...
● isc-dhcp-server.service - LSB: DHCP server
Loaded: loaded (/etc/init.d/isc-dhcp-server; generated; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2018-04-26 18:15:09 UTC; 1min ago
Docs: man: systemd-sysv-generator (8)
Process: 546 ExecStart = / etc / init.d / isc-dhcp-server start (code = exited, status = 1 / FAILURE)

Apr 26 18:15:06 raspberrypi systemd [1]: Starting LSB: DHCP server ...
Apr 26 18:15:07 raspberrypi isc-dhcp-server [546]: Launching IPv4 server only.
Apr 26 18:15:07 raspberrypi dhcpd [596]: Wrote 2 leases to leases file.
Apr 26 18:15:09 raspberrypi isc-dhcp-server [546]: Starting ISC DHCPv4 server: dhcpdcheck syslog for diagnostics. failed
Apr 26 18:15:09 raspberrypi isc-dhcp-server [546]: failed!
Apr 26 18:15:09 raspberrypi systemd [1]: isc-dhcp-server.service: Control process exited, code = exited status = 1
Apr 26 18:15:09 raspberrypi systemd [1]: Failed to start LSB: DHCP server.
Apr 26 18:15:09 raspberrypi systemd [1]: isc-dhcp-server.service: Unit entered failed state.
Apr 26 18:15:09 raspberrypi systemd [1]: isc-dhcp-server.service: Failed with result 'exit-code'.
"

Below is the tutorial I used

1 - Start the installations:
sudo apt-get update
sudo apt-get install hostapd isc-dhcp-server
sudo apt-get install iptables-persistent

2 - Edit /etc/dhcp/dhcpd.conf
sudo nano /etc/dhcp/dhcpd.conf

3 - Find the lines that say
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

And change to
#option domain-name "example.org";
#option domain-name-servers ns1.example.org, ns2.example.org;
(putting # at the beginning)


4 - Find the lines that say
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative; And change to
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

(Take the authoritative #)

5 - At the end of the file add the lines
subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
To save and close the nano, CTRL + X -> Y -> ENTER
(Same procedure at all steps)

6 - Edit the file / etc / default / isc-dhcp-server
sudo nano / etc / default / isc-dhcp-server

Find INTERFACESv4 = "" and upgrade to INTERFACESv4 = "wlan0"
(close saving)



Run

sudo ifconfig wlan0 down

7 - Edit the file /etc/dhcpcd.conf
sudo nano /etc/dhcpcd.conf

At the end of the file add the lines
interface wlan0
static ip_address = 192.168.42.1 / 24
static routers = 192.168.42.1
static domain_name_servers = 192.168.42.1 8.8.8.8
static domain_search =
noipv6
(close saving)

Run
sudo ifconfig wlan0 192.168.42.1

8 - Edit the file /etc/hostapd/hostapd.conf and include all the text below

sudo nano /etc/hostapd/hostapd.conf
(the file is empty) NOTE THE SSID AND PASSWORD CONFIGURATION

interface = wlan0
# driver = rtl871xdrv
ssid = NOMEDAREDE (* change to the desired network name)
country_code = US
hw_mode = g
channel = 6
macaddr_acl = 0
auth_algs = 1
ignore_broadcast_ssid = 0
wpa = 2
wpa_passphrase = PASSWORD (* change to the desired password)
wpa_key_mgmt = WPA-PSK
wpa_pairwise = CCMP
wpa_group_rekey = 86400
ieee80211n = 1
wme_enabled = 1

(close saving)

9 - Edit the file / etc / default / hostapd
sudo nano / etc / default / hostapd

Find line # DAEMON_CONF = "" and edit for DAEMON_CONF = "/ etc / hostapd / hostapd.conf"
(take the # too)
(Close saving)

10 - Edit the file /etc/init.d/hostapd
sudo nano /etc/init.d/hostapd

Locate DAEMON_CONF = and change to DAEMON_CONF = / etc / hostapd / hostapd.conf
(Close Saving)

11 - Edit the file /etc/sysctl.conf
sudo nano /etc/sysctl.conf
Locate line # net.ipv4.ip_forward = 1 and get # from start
(close saving)



12 - Execute the following commands one by one (enter in each of them)
sudo sh -c "echo 1> / proc / sys / net / ipv4 / ip_forward"
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED, ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
sudo sh -c "iptables-save" /etc/iptables/rules.v4 "sudo / usr / sbin / hostapd /etc/hostapd/hostapd.conf

*** IN THIS POINT THE NETWORK IS ALREADY VISIBLE BUT IT IS NOT STILL TO BE ***

sudo mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~ /

13 - RESTART THE RASPBERRY PI with the command
sudo reboot

14 - RESET THE SERVICES WITH THE COMMANDS BELOW
sudo service hostapd start

sudo service isc-dhcp-server start

sudo update-rc.d hostapd enable

sudo update-rc.d isc-dhcp-server enable

15 - Check to see if everything is working (it will say in the terminal):
sudo service isc-dhcp-server status
sudo service hostapd status