Mittwoch, 4. März 2015

Setting a static network address on the BeagleBone

After several unsuccessful attempts using connman and network-manager I've finally managed to boot the beagle board with a static IP address. First step was to remove wicd, connman and network-manager from the BeagleBone. I've tried to set the IP address using the nmcli tool to configure the network-manager but unfortunately the version installed on the BeagleBone didn't support the modification of connections. I then tried to create a configuration file for the usb0 ethernet but network-manager somehow ignored it.

When the BeagleBone boots systemd will execute the boot_scripts.service script which in turn will call the script in /etc/init.d/.  I have no idea where the boot_scripts.service is located, but my guess is that systemd converts old InitV scripts it finds in /etc/rc*.d  to systemd services. But that would not explain why ifup\@.service, which will be shown later, gets executed. The will then call either or depending on the type of the board. On the BeagleBone Black this would be the script.

Now to enable static IP configuration you have to comment out all lines in (located in /opt/scripts/boot/) which will set the IP address and start the udhcp server like this:
 #sed -i -e 's:DHCPD_ENABLED="no":#DHCPD_ENABLED="no":g' /etc/default/udhcpd  
 ##Distro default...  
 #deb_udhcpd=$(cat /etc/udhcpd.conf | grep Sample || true)  
 #if [ "${deb_udhcpd}" ] ; then  
 #  mv /etc/udhcpd.conf /etc/udhcpd.conf.bak  
 #if [ ! -f /etc/udhcpd.conf ] ; then  
 #  echo "start" > /etc/udhcpd.conf  
 #  echo "end" >> /etc/udhcpd.conf  
 #  echo "interface usb0" >> /etc/udhcpd.conf  
 #  echo "max_leases 1" >> /etc/udhcpd.conf  
 #  echo "option subnet" >> /etc/udhcpd.conf  
 #/etc/init.d/udhcpd restart  
 #/sbin/ifconfig usb0 netmask  
 #/usr/sbin/udhcpd -S /etc/udhcpd.conf  
 #eth0_addr=$(ip addr list eth0 |grep "inet " |cut -d' ' -f6|cut -d/ -f1)  
 #usb0_addr=$(ip addr list usb0 |grep "inet " |cut -d' ' -f6|cut -d/ -f1)  
 #wlan0_addr=$(ip addr list wlan0 |grep "inet " |cut -d' ' -f6|cut -d/ -f1)  
 #sed -i -e '/Address/d' /etc/issue  
 i#f [ ! "x${eth0_addr}" = "x" ] ; then  
 #  echo "The IP Address for eth0 is: ${eth0_addr}" >> /etc/issue  
 #if [ ! "x${wlan0_addr}" = "x" ] ; then  
 #  echo "The IP Address for wlan0 is: ${wlan0_addr}" >> /etc/issue  
 #if [ ! "x${usb0_addr}" = "x" ] ; then  
 #  echo "The IP Address for usb0 is: ${usb0_addr}" >> /etc/issue  

Then create /etc/systemd/system/ifup\@.service with the following contents:
 Description=ifup for %I  
 ExecStart=/sbin/ifup --allow=auto %I  
 ExecStop=/sbin/ifdown %I  
The strange thing is that you don't have to enable this service. Just create the file and it will be called for the interfaces automatically. If anyone knows why then please let me know!

Now you have to configure your interface in /etc/network/interfaces. Here is my example configuration for the usb0 network interface:
 auto usb0  
 allow-hotplug usb0  
 iface usb0 inet static  
   address  a
You need to have auto usb0 in your configuration because the service script will only start interfaces with this attribute.

Restart you BeagleBone and hopefully it works for you also.

Keine Kommentare:

Kommentar veröffentlichen