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 boot_scripts.sh 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 boot_scripts.sh will then call either am335x_evm.sh or omap3_beagle.sh depending on the type of the board. On the BeagleBone Black this would be the am335x_evm.sh script.

Now to enable static IP configuration you have to comment out all lines in am335x_evm.sh (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  
 #fi  
 #if [ ! -f /etc/udhcpd.conf ] ; then  
 #  echo "start   192.168.7.1" > /etc/udhcpd.conf  
 #  echo "end    192.168.7.1" >> /etc/udhcpd.conf  
 #  echo "interface usb0" >> /etc/udhcpd.conf  
 #  echo "max_leases 1" >> /etc/udhcpd.conf  
 #  echo "option subnet 255.255.255.252" >> /etc/udhcpd.conf  
 #fi  
 #/etc/init.d/udhcpd restart  
 #/sbin/ifconfig usb0 192.168.7.2 netmask 255.255.255.252  
 #/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  
 #fi  
 #if [ ! "x${wlan0_addr}" = "x" ] ; then  
 #  echo "The IP Address for wlan0 is: ${wlan0_addr}" >> /etc/issue  
 #fi  
 #if [ ! "x${usb0_addr}" = "x" ] ; then  
 #  echo "The IP Address for usb0 is: ${usb0_addr}" >> /etc/issue  
 #fi  


Then create /etc/systemd/system/ifup\@.service with the following contents:
 [Unit]  
 Description=ifup for %I  
 After=local-fs.target  
 [Service]  
 ExecStart=/sbin/ifup --allow=auto %I  
 ExecStop=/sbin/ifdown %I  
 RemainAfterExit=true  
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 10.42.0.252  a
   netmask 255.255.255.0  
   network 10.42.0.0  
   gateway 10.42.0.1  
   dns-nameservers 10.42.0.1  
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