0

I have just finished setting up my home SSH server and It's working nicely, all I need to do now is make it publicly available so I can access it when I'm on another network, now sounds simple enough right? Well I'm sure it is but I for some reason can not get it working for the life of me..

Here's what I have got configured for the port forwarding in RouterOS (v6.47.9):

Chain: dstnat
Dst. Address: (my public IP address)
Protocol: 6 (tcp)
Dst. Port: 1024

Action: dst-nat
To Addresses: 192.168.1.125 (my SSH server IP)
To Ports: 22

What I want to do is login to my SSH server via my public IP address, essentially in my mind this would be done like so:

ssh (machine username)@(public IP address) -p 1024

Anyway, any help would be much appreciated.

(If required my sshd_config file is located below)

#      $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_ho>
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues wi>
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
GatewayPorts yes
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp  /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
PasswordAuthentication yes
8
  • 1
    don't use port 1024. use a specific port well above 1024 (and below 16384). TCP/1024 will be used as the source port for the first out-bound connection to the first non-symmetric connection you establish upon boot. Commented Mar 14, 2022 at 4:37
  • Nothing wrong with port 1024, the Linux NAT used by RouterOS is fully capable of rewriting source ports as necessary, as well as using the same port both as srcport of outbound connections and dstport of inbound rules (conntrack will match an active connection state first, rules are processed last). Commented Mar 14, 2022 at 5:23
  • That being said, the usual questions: 1) How did you determine your public IP address? That is, is your public IP address also the router's assigned address? Does it show up in the router's /ip addr or not? 2) Are you trying the connection from inside of your LAN, or from outside? Commented Mar 14, 2022 at 5:25
  • To determine my routers IP address I used this website here: whatismyip.com Commented Mar 14, 2022 at 5:52
  • I have checked /ip addr and all that seems to be there is my local address (192.168.1.1). As for question two I am trying to connect from inside my LAN. Commented Mar 14, 2022 at 5:53

1 Answer 1

0

First is making sure your ISP isn't doing CGNAT, in which case you cannot forward ports at all without first asking them to do it in their end. You can check this by looking at what IP you've been given. If it starts with 10., 100., 172. or 192.168. then they're doing CGNAT.

If it's not CGNAT, then unless your WAN IP never changes you will have to reconfigure this every time your internet connection drops and reconnects (as your ISP assigns you a new WAN IP). Use the in-interface field with your WAN interface instead of dst-address so it always works no matter what your currently assigned IP is.

You can check if the port forwarding is working by the traffic counter in that firewall rule.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .