I have a local machine in my network 192.168.0.30
and i ssh
over port 12121
, setting in my sshd_config
file.
I done changes to iptables
:
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 12121 -j ACCEPT
/sbin/iptables -P INPUT DROP
So my machine accept only input from port 12121
now, this works i can ssh into it
On this machine i run an autossh script
from a service
, for remote port forwarding
to get access from outside.
Command in my script:
/usr/bin/autossh -f -NT -o "ExitOnForwardFailure=yes" -R 20000:localhost:12121 \
-l [REMOTE-USER] [REMOTE-IP] -p 11111 -i [REMOTE-KEY]
When i try to connect it won't work, normal i accept only 12121
in iptables
So i add this to my iptables:
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 20000 -j ACCEPT
And even if i dont need this because it's the input port from the remote machine:
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 11111 -j ACCEPT
Local ssh works remote ssh not.
When i check the my service with:
systemctl status mysshservice
I see all exited status codes
, and the restart
from the service and i see my autossh
command with my options but i do see a second line with -L
with a different port selected by autossh
like 48328
so i do.
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 48328 -j ACCEPT
Now i can ssh from outside again.
I have 2 questions now about iptables
.
Is it possible to a accept the service by name, without a given port like
ACCEPT ALL SSH CONNECTIONS
?, so only ssh works without to ACCEPT
every PORT
i need.
My problme is the remote port changes every day so i have to generate new ACCEPT RULES every day
.
When i work with autossh, do i need a script to grep/awk/sed
the -R and -L ports every day
, or is there an other solution for?