0

My /etc/hosts.allow file contains:

sshd: 225.73. , 164.41.

My /etc/hosts.deny file contains:

sshd: 225.73.24.25 , 164.41.45.63

The problem I'm facing is that if I try to SSH from 225.73.24.25 or 164.41.45.63 the server is allowing me to SSH in.

The scenario I want is that all IPs in the range 225.73. or 164.41. are allowed in except hosts with the IPs 225.73.24.25 or 164.41.45.63.

I would be grateful if someone could help with this.

CP3O
  • 101
  • 1
  • Because access rules in hosts.allow are applied first, they take precedence over rules specified in hosts.deny. https://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-rg-en-4/s1-tcpwrappers-access.html Use firewall instead – gapsf Oct 17 '22 at 17:15
  • Try except operator https://www.mankier.com/5/hosts_access#Operators or deny, allow order https://www.mankier.com/5/hosts_options#Access_Control – gapsf Oct 17 '22 at 17:22
  • I was about to say calculate the subnets without one given IP, but EXCEPT appears to be a better way to excluding :) – jabbson Oct 17 '22 at 17:25

2 Answers2

1

You can use the EXCEPT operator in hosts.allow like this:

sshd: 225.73. , 164.41. EXCEPT 225.73.24.25 , 164.41.45.63

See man hosts.allow:

EXCEPT Intended use is of the form: list_1 EXCEPT list_2; this construct matches anything that matches list_1 unless it matches list_2.

TommyPeanuts
  • 472
  • 1
  • 7
  • 24
-1

225.73. or 164.41. are allowed in except hosts with the IPs 225.73.24.25 or 164.41.45.63. all of this ips will still able to log in change filter sshd: 225.73.24.25 - 164.41.45.63 , 192.168.1.1 , 192.168.100.1 - 192.168.100.255

kiksee
  • 1