-1

I have set up a communication system for my pi to receive commands from my computer with netcat running on the pi, and processing on the computer to control a robot. My issue is that I have my raspberry pi's IP address in the code on my computer, so if my pi moves to a different network, it will not connect. I want these two devices to connect across networks, so I am assuming that my best option would be to assign my raspberry pi a domain name such as "google.com" so that I can send data from anywhere to anywhere without needing an IP address. Is it possible to do this? If not, is there a better way to achieve this solution? How?

2

You COULD assign a domain name, if you have one, and want to address it over the internet. You need network services to enable domain name resolution.

What I suspect you actually want is to symbolically address your Pi on a local network.

The Pi, like most Linux systems, has a hostname; raspberrypi by default.

You can see this by entering hostname on the command line.

You can change it to something different (and preferably unique) in raspi-config.

Raspbian (you have not told us what you are using), by default, runs avahi as a Zero-conf client. This enables programs to discover hosts running on a local network.

You can easily connect from Linux and OS X with ssh pi@hostname.local (the default hostname is raspberrypi) This should work with popular GUI ssh programs. This is sometimes problematic with some versions of Windows and networks which use .local in a non-standard way. (See https://en.wikipedia.org/wiki/.local)

NOTE .local resolution does not work in some contexts e.g. in rsync. The following should resolve IP (and can be included in bash scripts) RemotePi=$(getent hosts hostname.local | awk '{ print $1 }')

.local resolution does work on some Windows systems, and there may be alternate solutions using the hostname on Windows.

  • Well butter my spinach, I wasn't aware of the hostname.local thing. Much nicer than using local network IP. – geotheory Jun 12 '18 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.