Ask Your Question

Setting ROS_IP using roscpp

asked 2014-01-22 11:55:08 -0500

ISibboI gravatar image

updated 2014-01-28 17:19:07 -0500

ngrennan gravatar image

We found out, that to make our network communication work, ROS_IP has to be set to the ip of the machine. Otherwise the network communication won't work.

How can we set this value from within C++ code?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-01-22 17:29:58 -0500

ahendrix gravatar image

updated 2014-01-23 07:43:14 -0500

Don't. Setting up the configuration for your robot is executable code conflates configuration with software, and generally results in software that isn't portable.

There are several alternatives:

  • Add 'export ROS_IP=...' to your ~/.bashrc, so that ROS_IP will be set in every shell. You can either hardcode this to your IP address, or find one of the many examples of how to set it based on the output from ifconfig.
    • This has the disadvantage that if network interface that this IP is attached to goes down, all communication, both local and over the network, will stop because the IP address no longer exists.
  • Make hostnames work. You can do this in several ways:
    • Manually configure the /etc/hosts file on every machine, so that it knows the hostname to IP mapping for every other machine. This is tedious and fragile, but it's an option if you can't modify DNS
    • Set up DNS so that it matches your hostname. This requires a bit more configuration and network administration knowledge, but it means that all of your hostname to IP mappings are configured in a single place.
    • Set up your hostnames to match DNS. If you don't control your DNS server, but it has entries for each of your IP addresses, you may be able to change the hostnames on your machines to match the existing DNS.
    • Use zeroconf hostnames (host.local): install the avahi and nss-mdns packages so that hosts publish and can resolve zeroconf hostnames, and then change the hostnames on your machines to their zeroconf hostnames.
edit flag offensive delete link more



Adding a little bit on hostnames: If you're running Ubuntu then it probably has avahi, an implementation of zeroconf (, so you should be able to resolve a host name as: computer-name.local, where computer-name is the output of the command: hostname

Tim Sweet gravatar image Tim Sweet  ( 2014-01-22 18:20:28 -0500 )edit

Awesome! Added that to my answer.

ahendrix gravatar image ahendrix  ( 2014-01-23 07:43:34 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-01-22 11:55:08 -0500

Seen: 2,955 times

Last updated: Jan 23 '14