Beaglebone Linux 101: Assigning a Static IP Address with Connman

My article on configuring Angstrom Linux included instructions for setting a static IP address. Sometime after posting that article, I realized that the instructions work great unless you happen to reboot. Then, the settings reverted to the default of using a DHCP server.

Ooops!

It turns out that this sleight-of-hand is the work, aptly enough, of a package named Connman.

This newfangled connection manager is, in some ways, a good fit for the Beaglebone, since it was designed to run on memory-constrained embedded Linux systems. It was originally developed for use on 2 Linux platforms that have struggled, Meego and Moblin, but we won’t hold that against it.

However, Connman presents one big problem for Beaglebone users: it’s rather difficult to configure from the command line.

It doesn’t come with a command line configuration tool, but it does provide some well documented APIs that command line applications can use. As such, the best command line interface right now can be found in a package intended to test that the APIs are working correctly: connman-tests.

To install the package:

opkg install connman-tests

This will install a set of Python scripts in /usr/lib/connman/test.

To check your current configuration:

cd /usr/lib/connman/test/
./get-services

The output should look like the following:

[ /net/connman/service/ethernet_405fc276b749_cable ]
 IPv6.Configuration = { Method=auto Privacy=disabled }
 AutoConnect = false
 Proxy.Configuration = { }
 Name = Wired
 Nameservers = [ 206.47.244.104 206.47.199.155 ]
 Provider = { }
 Favorite = true
 Domains.Configuration = [ ]
 State = online
 Proxy = { Method=direct }
 Nameservers.Configuration = [ ]
 LoginRequired = 0
 IPv6 = { }
 Domains = [ lan ]
 Ethernet = { Interface=eth0 MTU=1500 Method=auto 
Address=xx:xx:xx:xx:xx:xx }
 Security = [ ]
 IPv4.Configuration = { Method=dhcp }
 Type = ethernet
 Immutable = false
 IPv4 = { Netmask=255.255.255.0 Gateway=192.168.1.1 
Method=dhcp Address=192.168.1.161 }

The important thing to note here is the service ID at the top of the output, in my case  ethernet_405fc276b749_cable.  (Dumb name for an ethernet cable, if you ask me.)

You can also get the DNS nameserver and gateway IP addresses from this output, if you don’t already know them.

To change the configuration, you use 2 other scripts, set-ipv4-method and set-nameservers.

The syntax for set-ipv4-method is:

./set-ipv4-method <service> [off|dhcp|manual <address> [netmask] [gateway]]

The service parm is that long string that appears at the top of the output from the get-services script.

So, to set the Beaglebone to use a static IP address of 192.168.1.2, with a gateway of 192.168.1.1, I entered:

./set-ipv4-method ethernet_405fc276b749_cable manual 
192.168.1.2 255.255.255.0 192.168.1.1

To set the DNS nameservers, use set-nameservers.  The syntax is:

./set-nameservers <service> [nameserver*]

In my case, I entered

./set-nameservers ethernet_405fc276b749_cable 206.47.244.104 
206.47.199.155

That’s it: after entering those 2 commands, you’ll be running with the new network settings, no reboot required. (Though, if you plan to blog about it, a reboot is definitely recommended!)

This entry was posted in Gadgets and tagged , . Bookmark the permalink.

19 Responses to Beaglebone Linux 101: Assigning a Static IP Address with Connman

  1. Pingback: Beaglebone Linux 101: Configuring Angstrom Linux | GigaMegaBlog

  2. Edouard says:

    Thanks for those blog entries, you are doing a really great job!

  3. Kate says:

    What is when i want to use more IP addresses?
    For example (/etc/network/interfaces)
    iface eth0 inet dhcp

    auto eth0:1
    iface eth0:1 inet static
    address xxx.xxx.1.1
    netmask 255.255.255.0

  4. Martin Jakobsen says:

    Hi Dan, these articles are great help for a Linux newbie like me, keep up the good work, you rock! :-)

  5. Sam says:

    Hello, first of all, thank you very much for your very useful posts, they are helping us very much.

    We are developing an application that needs half duplex serial communication from some UART port, we are trying UART1 and UART2 on the BeagleBone RevA3. We are using ubuntu for arm.
    We need to use the RTS pin to toggle the direction port of the half duplex communication. We’ve tried to enable the RTS on both UARTs with this configuration of pins:

    For UART1:
    root@omap:/sys/kernel/debug/omap_mux# cat uart1_txd
    name: uart1_txd.uart1_txd (0x44e10984/0x984 = 0x0000), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE0
    signals: uart1_txd | mmc2_sdwp | NA | i2c1_scl | NA | pr1_uart0_txd_mux1 | NA | gpio0_15
    root@omap:/sys/kernel/debug/omap_mux# cat uart1_rxd
    name: uart1_rxd.uart1_rxd (0x44e10980/0x980 = 0x0030), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE0
    signals: uart1_rxd | mmc1_sdwp | NA | i2c1_sda | NA | pr1_uart0_rxd_mux1 | NA | gpio0_14
    root@omap:/sys/kernel/debug/omap_mux# cat uart1_rtsn
    name: uart1_rtsn.uart1_rtsn (0x44e1097c/0x97c = 0x0030), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE0
    signals: uart1_rtsn | NA | d_can0_rx | i2c2_scl | spi1_cs1 | NA | NA | gpio0_13
    root@omap:/sys/kernel/debug/omap_mux# cat uart1_ctsn
    name: uart1_ctsn.uart1_ctsn (0x44e10978/0x978 = 0x0000), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE0
    signals: uart1_ctsn | NA | d_can0_tx | i2c2_sda | spi1_cs0 | NA | NA | gpio0_12

    For UART2:
    root@omap:/sys/kernel/debug/omap_mux# cat spi0_d0
    name: spi0_d0.uart2_txd (0x44e10954/0x954 = 0x0001), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE1
    signals: spi0_d0 | uart2_txd | i2c2_scl | NA | NA | NA | NA | gpio0_3
    root@omap:/sys/kernel/debug/omap_mux# cat spi0_sclk
    name: spi0_sclk.uart2_rxd (0x44e10950/0x950 = 0x0031), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE1
    signals: spi0_sclk | uart2_rxd | i2c2_sda | NA | NA | NA | NA | gpio0_2
    root@omap:/sys/kernel/debug/omap_mux# cat lcd_data9
    name: lcd_data9.uart2_rtsn (0x44e108c4/0x8c4 = 0x002e), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE6
    signals: lcd_data9 | gpmc_a13 | NA | mcasp0_fsx | NA | NA | uart2_rtsn | gpio2_15
    root@omap:/sys/kernel/debug/omap_mux# cat lcd_data8
    name: lcd_data8.uart2_ctsn (0x44e108c0/0x8c0 = 0x0006), b NA, t NA
    mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE6
    signals: lcd_data8 | gpmc_a12 | NA | mcasp0_aclkx | NA | NA | uart2_ctsn | gpio2_14

    We aren’t seeing anything in the RTS pin of any of the 2 ports. (But the communication works).

    Thank you very much, we look forward for any help on this issue. We’ve posted this on the BeagleBone google group but it’s still pending moderation.

  6. David says:

    I used this information to generate a script to set static IP address on my BeagleBone
    #! /bin/sh
    # manual
    IPADD=”192.168.13.205″
    NETMASK=”255.255.255.0″
    GATEWY=”192.168.13.254″
    NAMESRV=”192.168.13.254″
    CABLE=`/usr/lib/connman/test/get-services | grep “/net” | awk ‘{ split( $2 , a , “/” )} { print a[5] }’`
    echo ”

    /usr/lib/connman/test/set-ipv4-method $CABLE manual $IPADD $NETMASK $GATEWY
    echo ”

    /usr/lib/connman/test/set-nameservers $CABLE $NAMESRV
    echo ”

    echo “ETH Cable : ” $CABLE
    echo “IP Address : ” $IPADD
    echo “Net Mask : ” $NETMASK
    echo “Gate way : ” $GATEWY
    echo “Name Server : ” $NAMESRV
    echo ”


    /usr/lib/connman/test/get-services

    It seems to work except that the name server is in set in /etc/resolv.conf. when I look at the contents it only has the loop back IP set. Is this a bug in connman?

  7. Camilo Moncayo says:

    OHH!!!! thanks a lot.
    Well, now I have a static IP, but i have the same error, I can’t enter to the CLOUD9 until after I reboot the BeagleBone. If I don’t reboot after turn on or halt the BeagleBone I can’t enter to the CLOUD9.
    It’s to weird but when I reboot the beaglebone I can enter to the CLOUD9. What i could do?
    thanks in advanced

    • dwatts says:

      Camilo,

      Sorry, I didn’t have this problem, so I don’t have a good idea of what would cause it.

      You can get the status of the Cloud9 service with this command:

      # systemctl status cloud9.service

      If cloud9 failed to start, this will give the error message.

      If cloud9 isn’t running, you can try starting it manually:

      # systemctl start cloud9.service

      If you haven’t installed the latest packages yet, or updated to the latest kernel (3.2.11+ now), you should give that a try. I had a problem with a different node.js service, bone101, which was fixed after an “opkg update” in February, but I still don’t know what caused the problem.

      You should try asking in the Beagleboard Google Group, if you haven’t already. There is a good chance that someone else has had this problem and could recommend ways to fix it.

      Dan.

  8. i got this error once i tried to use set-ipv4-method

    Traceback (most recent call last):
    File “./set-ipv4-method”, line 19, in
    properties = service.GetProperties()
    File “/usr/lib/python2.7/site-packages/dbus/proxies.py”, line 68, in __call__
    return self._proxy_method(*args, **keywords)
    File “/usr/lib/python2.7/site-packages/dbus/proxies.py”, line 143, in __call__
    **keywords)
    File “/usr/lib/python2.7/site-packages/dbus/connection.py”, line 630, in call_blocking
    message, timeout)
    dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method “GetProperties” with signature “” on interface “net.connman.Service” doesn’t exist

    and yes, i changed the service ID and the ip as needed but i got this error, i get the same error even if i tried a wrong service ID, so it seems that it doesn’t execute a thing at all

    • dwatts says:

      Hi,

      Are you sure that the connman daemon is installed and running?

      If you are using the Angstrom demo image, then Connman almost certainly is running (unless it crashed), but if you are using Ubuntu or you built a custom Angstrom image (e.g. using narcissus) then perhaps it isn’t.

      You can check if connman is running with

      # ps aux | grep “connmand”

      It should indicate that /usr/sbin/connmand is running.

      If it isn’t, then the good news is that you can set your IP address the normal way, by editing /etc/network/interfaces.

      If you can’t get connman configuration to work, then you might want to uninstall or disable the connman daemon – you can then set your address using /etc/network interfaces. I know that some Beaglebone users have done this rather than mess around with connman – you can check the Beagleboard Google Group for instructions.

      As far as I know, connman isn’t required in order to use any features of the Beaglebone or Beagleboard – it’s just a different way of configuring those services.

      Dan.

      • Amir says:

        I am having the same problem as “Mahmoud Tantawy “. Connman is running.

        How can I prevent connman in BeagleBone from starting up? I want to be able to enable later if I need to.

        • dwatts says:

          Hi,

          Connman is started by systemctl, so it can be stopped with “systemctl stop connman.service” and prevented from starting at bootup with “systemctl disable connman.service”. There is also a connman script in /etc/init.d — it appears that this script has no effect, but if connman is still running when you reboot then you should delete /etc/init.d/connman too.

          Dan.

  9. Roberto says:

    For the ./set-nameservers where did you get the two IP addresses?? 206.47.244.104
    206.47.199.155? Should i put the same.. if not, where can I find the nameservers that I should use? Sorry if this question seems silly. I really appreciate the post!

    • dwatts says:

      Roberto,

      Yes, you need to type in the address of the nameserver(s) for your network — the ones I put in my example won’t work for you.

      If your Beaglebone is currently using DHCP, you can see what nameservers it is using by running the ./getservices command. The output will look like this:

      root@beaglebone:/usr/lib/connman/test# ./get-services
      [ /net/connman/service/ethernet_405fc276b749_cable ]
      IPv6.Configuration = { Method=auto Privacy=disabled }
      AutoConnect = false
      Proxy.Configuration = { }
      Name = Wired
      Nameservers = [ 206.47.244.104 206.47.199.155 ]

      Whatever IPs appear in the “Nameservers” line are the ones you should enter in the set-nameservers command.

      Otherwise, if you can’t get the nameservers that way, you have a couple of options. The best thing would be to check what nameservers are configured for another PC on the network. You can Google for various articles on how to do this — here is one: http://www.cyberciti.biz/faq/how-to-find-out-what-my-dns-servers-address-is.

      Another approach would be to use public nameservers, like Google’s. The IP address of Google’s Public DNS are 8.8.8.8 and 8.8.4.4 — full details are here: https://developers.google.com/speed/public-dns/.

      Dan.

  10. Pingback: Building a Rover project day 6 – wifi | Flesh and machines

  11. steve g says:

    I tried your directions above on my Angstrom BeagleBone but they don’t work for the g_ether usb gadget for usb0. Is usb0 controlled some other way? I’d sure love to configure it to come up with a specific static IP address on boot.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>