0

In my pc currently 3 different network interfaces exists (interface1,interface2,interface3 ).I want to start gpsd daemon such a way that it should bind to some specific interface which i want.

Currently iam running gpsd as below

gpsd -b -n   #Here gpsd binds to localhost.

My goal is to run gpsd something like

gpsd -b -n interface1_ip   #here gpsd should bind to only interface1. 

how can i do this?

rakd
  • 179
  • 1
  • 2
  • 12

2 Answers2

2

A quick and dirty way would be to start gpsd with the -G option, to enable monitoring all interfaces (by default, gpsd will only listen to localhost for security and privacy) and then disable access on unwanted interfaces by having proper firewall rules (disable access on two unneeded interfaces). Gpsd will listen on port 2947, you can change that with the -S option to fit your needs.

Rado
  • 66
  • 3
  • Is gpsd not having any options to specify to which interface/ip it should bind to? .i know -G enables monitoring all interfaces.If i don't pass this option , gpsd will bind to only localhost .But what i want is an option by which i can specify which interface gpsd should bind to. – rakd Mar 04 '20 at 09:42
  • I see no such option. Therefore, your workaround is to disable communication on other two networks that you do not want gpsd to listen to; it will still listen on all interfaces, but no packets will come through the firewalled interfaces. – Rado Mar 04 '20 at 09:53
  • yes. you can set up iptable rules on either that machine (to disable connection coming to it), or on the other side (assuming that you have a router/fw on the other two networks). The safest thing is to make rules on the local machine, so that you can have easy and full control over who can access gpsd. Just don't forget that you've set specific rules there and not somewhere else. :) – Rado Mar 04 '20 at 10:39
  • Under systemd, however, this does not seem to function as expected. Amending /etc/init.d/gpsd to add the GPSD_OPTIONS of "-G" has no effect at all. Systemd somehow limits which interfaces will listen to localhost only. If gpsd is run manually -G works as designed. Once could start it by crontab but that's sort of heavy handed. – guitarpicva May 31 '22 at 12:40
0

Systemd takes over (yet again)! The socket is configured in systemd thus:

In the user created (most likely) file: /etc/systemd/system/gpsd.socket.d/socket.conf

[Unit]
Description=GPS (Global Positioning System) Daemon Sockets

[Socket]
# First blank ListenStream clears the system defaults
ListenStream=
ListenStream=/var/run/gpsd.sock
#ListenStream=2947
ListenStream=0.0.0.0:2947
SocketMode=0600

[Install]
WantedBy=sockets.target
guitarpicva
  • 432
  • 3
  • 10