Last active
December 28, 2019 11:55
-
-
Save jomix/9be61ccfe9186b68df5a7ad9932093f3 to your computer and use it in GitHub Desktop.
Access Diskstation from Raspberry Pi (or How to set up dhcpd on raspi eth)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Raspberry Pi has wlan (wireless) and eth0 (ethernet) network interfaces | |
The following will set 10.0.0.1 IP to eth0 | |
The diskstation should typically get assigned 10.0.0.10 from dhcp | |
# assign a static address to eth0 | |
sudo vim /etc/dhcpcd.conf | |
interface eth0 | |
static ip_address=10.0.0.1/24 | |
# now that we have our static IP address set up, we can install and configure a DHCP server | |
sudo apt-get install isc-dhcp-server | |
sudo service isc-dhcp-server stop | |
sudo vi /etc/default/isc-dhcp-server | |
# edit the INTERFACES environment variable so that the DHCP server only listens on the wired interface | |
INTERFACESv4="eth0" | |
# start isc-dhcp-server on boot | |
sudo cp /run/systemd/generator.late/isc-dhcp-server.service /etc/systemd/system | |
sudo vi /etc/systemd/system/isc-dhcp-server.service | |
Edit the [Service] section: | |
Restart=on-failure | |
add RestartSec=5 to instruct systemd to wait 5 seconds before restarting a failed service. | |
Add the [Install] section which is missing, and add the follow line to it: | |
WantedBy=multi-user.target | |
sudo systemctl daemon-reload | |
sudo systemctl disable isc-dhcp-server | |
sudo systemctl enable isc-dhcp-server | |
systemctl status isc-dhcp-server | |
sudo vi /etc/dhcp/dhcpd.conf | |
# insert the following and replace with correct MAC address of your device | |
subnet 10.0.0.0 netmask 255.0.0.0 { | |
range 10.0.0.10 10.0.0.200; | |
option routers 10.0.0.1; | |
default-lease-time 86400; | |
max-lease-time 172800; | |
host diskstation { | |
hardware ethernet XX:11:22:33:44:55; | |
fixed-address 10.0.0.10; | |
} | |
# option domain-name-servers ns1.internal.example.org; | |
# option domain-name "internal.example.org"; | |
# option broadcast-address 10.5.5.31; | |
} | |
#reboot the raspberry pi, reboot the diskstation | |
# show dhcp leases | |
cat /var/lib/dhcp/dhcpd.leases | |
#show isc dhcp service log | |
systemctl status isc-dhcp-server.service | |
# following methods can detect IP addresses is up for specified ip range on specified network interface | |
nmap -e eth0 -sn 10.0.0.1-254 | |
ping -I eth0 10.0.0.10 | |
for ip in 10.0.0.{10..100}; do ping -I eth0 -c 1 -t 1 $ip > /dev/null && echo "${ip} is up"; done | |
ping 10.0.0.10 | |
# check admin page is accessible | |
curl -vsL --insecure https://10.0.0.10:5001 2>&1 | grep DiskStation | |
# to access the diskstation from another client in the network: | |
# configure a local forward in your .ssh/config | |
LocalForward 15002 10.0.0.10:5001 | |
#finally be sure to https when accessing dashboard | |
https://localhost:15002/ | |
# setup IP masquerading. masquerade traffic coming from the 10.0.0/24 subnet (the -s option) to the wlan0 network interface (the -o option). | |
sudo iptables -t nat -A POSTROUTING -s 10.0.0/24 -o wlan0 -j MASQUERADE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment