Hi,
Ref: Programming eMMC with USB for OSD335x (AM335x System in Package) | Octavo Systems
Section 4.2.3: Setup DHCP Server on Host Computer
I understand the dhcp-restart script is suppose to add the name of the new interface to the INTERFACES variable of the /etc/default/isc-dhcp-server configuration file. In my case, I found that the name was not being added to the isc-dhcp-server file because the ‘sed’ command was failing.
# how to duplicate
# open a terminal
# check current the INTERFACES lines in isc-dhcp-server file
cat /etc/default/isc-dhcp-server
# snippet from result
...
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4=""
INTERFACESv6=""
# manually run the sed command
# replace '$IFACE' with 'test' (no single quotes)
sudo sed -i "/INTERFACES/ s#"$# test"#g" /etc/default/isc-dhcp-server
sed: -e expression #1, char 16: unterminated `s' command
# the command fails with unterminated 's' command
# Here is my fix
# replace the '#' terminator character(s) with ':'
# escape the two inside " double quote characters by adding '\' in front
sudo sed -i "/INTERFACES/ s#"$# test"#g" /etc/default/isc-dhcp-server
# command should execute without error
# now recheck current the INTERFACES lines in isc-dhcp-server file
cat /etc/default/isc-dhcp-server
# snippet from new result
...
INTERFACESv4=" test"
INTERFACESv6=" test"
Adding ’ test’ to the isc-dhcp-server file shouldn’t cause a problem, but you should edit the file and delete the ’ test’ entries.
Here is my complete dhcp-restart script. You can uncomment the echo commands to help debug the problem.
#!/bin/sh
#
# Modify the /etc/default/isc-dhcp-server init script to include the new RNDIS network
# interfaces in dhcp server configuration. It will then restart the dhcp server
# Static network interfaces that should not be modified
# *** Add any other static network interfaces on your host computer ***
if [ "$IFACE" = "gpd0" ] || [ "$IFACE" = "enp1s0" ] || [ "$IFACE" = "eno1" ] || [ "$IFACE" = "lo" ]; then
:
else
echo "New IFACE '"$IFACE"' found." >> /tmp/dhcp-restart.log
# set IP address of the interface
# ifconfig $IFACE 192.168.0.1 netmask 255.255.255.0
ip addr add 192.168.11.1/24 dev $IFACE
echo "Check isc-dhcp-server file for IFACE '"$IFACE"'" >> /tmp/dhcp-restart.log
if grep -q "$IFACE" /etc/default/isc-dhcp-server
then
echo "'"$IFACE"' is present - nothing to do." >> /tmp/dhcp-restart.log
:
else
echo "Attempting to add '"$IFACE"' to isc-dhcp-server" >> /tmp/dhcp-restart.log
sed -i "/INTERFACES/ s:\"$: $IFACE\":g" /etc/default/isc-dhcp-server
if [ $? = 0 ]; then
echo " successful" >> /tmp/dhcp-restart.log
else
echo " failed!" >> /tmp/dhcp-restart.log
fi;
fi;
fi;
systemctl restart isc-dhcp-server