I'd like to make a git-daemon go through a permanent ssh tunnel. I accomplished this task. How do I block any remote untunneled connection to the GIT_DAEMON port (9418 in my case)?
I already tried simple rules in iptables (block everything except localhost):
$ iptables -A INPUT -p tcp -d ! localhost --destination-port 9418 -j DROP
But it also blocks a tunnel (since it saves source ip address). If I have one more host for firewall it can be simply done by blocking any remote connection to this port, but I need this host to do this job.
The tunnel is created in one of two ways:
For Windows:
plink.exe -N -i <key> -L 127.0.0.1:9418:192.168.1.69:9418 [email protected]
For Linux:
ssh -N -i <key> -L 127.0.0.1:9418:192.168.1.69:9418 [email protected]
You can actually achieve this without using iptables at all, by simply making git-daemon
bind to the loopback interface, eg.
git daemon --listen=127.0.0.1
This will make it so it is only connectable from localhost, and does not require root privileges to set up.
You might try this (untested):
# accept localhost
iptables -A INPUT -p tcp -d localhost --destination-port 9418 -j ACCEPT
# send everyone else packing
iptables -A INPUT -p tcp --destination-port 9418 -j DROP
Using that iptables -L
says:
ACCEPT tcp -- anywhere localhost.localdomain tcp dpt:git
DROP tcp -- anywhere anywhere tcp dpt:git
EDIT
This is (probably) how your tunnel should be setup:
ssh -N -i <key> -L 127.0.0.1:9418:127.0.0.1:9418 [email protected]
It's important that the second half is 127.0.0.1
and NOT a normal IP
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With