The problem is that all ssh connections look like they are coming from server’s public IP address instead of remote server’s IP address.
I made couple of logins from different servers and here are the results:
root@server:~> last | head
testuser pts/2 <server’s public IP> Thu Nov 5 11:11 still logged in
testuser pts/2 <server’s public IP> Thu Nov 5 11:09 - 11:10 (00:00)
testuser pts/1 <server’s public IP> Thu Nov 5 10:56 still logged in
testuser pts/0 <server’s public IP> Thu Nov 5 10:48 still logged in
testuser pts/0 <server’s public IP> Thu Nov 5 10:48 - 10:48 (00:00)
Same thing in /var/log/messages after every connection.
server sshd[3190]: Accepted keyboard-interactive/pam for testuser from <server’s public IP> port 56680 ssh2
So, what’s wrong with my server’s settings? I have no clue…
It is most likely something in your network equipment. You need to describe how you are connected to Internet, how you make access for other external servers available, what devices/software you are using for this before anyone can even hazard a guess.
The server is connected to Internet via Inteno FG500 router. Router has NAT enabled and port forwarding for ssh connections.
For test logins I have used different internet connection (mobile 4G) so that server and my laptop is not in the same local network.
It’s also impossible to trace & block brute force attacks because of missing remote hosts IP. Here is a sample of /var/log/messages:
sshd[13051]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=<server's public IP> user=root
sshd[13051]: Failed password for invalid user root from <server's public IP> port 55982 ssh2
sshd[13051]: Failed password for invalid user root from <server's public IP> port 55982 ssh2
sshd[13051]: Failed password for invalid user root from <server's public IP> port 55982 ssh2
sshd[13051]: Disconnected from invalid user root <server's public IP> port 55982 [preauth]
I have another server for testing purposes also running Leap 15.2. That server doesn’t have this kind of problem (router and Internet provider is not the same).
So your “server public IP” is likely not your server public IP, but your router public IP. You really need to ask support community of your router. It sounds like it performs SNAT when forwarding packets.
If you provide network packet capture during ssh connection it is possible to say exactly whether the issue is in your server or external to it.
Connected to the Internet or, connected to an ISP?
If an ISP, are you certain that, the ISP’s routers are forwarding the incoming packets without performing any address translation?
[HR][/HR]Given that, the Inteno FG500 is a residential gateway for Fiber to the Home, I suspect that, the Internet connection is via an ISP with a residential contract …
Connected to ISP with a residential contract… I’m not 100% sure what router does to incoming packets.
Anyway… I can filter certain incoming IP:s with firewall, I can see remote IP:s in firewall logs but for some reason with sshd all the connections look like they are coming from my public ip address (that one router gets from ISP).
And these servers are trying to connect to port 22 on your server? We only see IP addresses, nothing more. We have no information to decide whether this is “correct” or not.