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.