Hosts file syntax when want to deny multiple IP subnets or partial hostnames?

P

postcd

Guest
Hello,

i would like to use /etc/hosts.deny / hosts.allow

to block all connections except connections from two IP subnets and one hostname (partial match).

these i want to allow:

1.2.3.0/24
4.3.2.0/24
*.tmc*

.tmc is a part of the hostname

So far i found this to add into hosts.deny:

sockd : ALL EXCEPT 1.2.3.0/24

but i need to add two more allow rules..

Can i do:

sockd : ALL EXCEPT /etc/hosts.allow

and into /etc/hosts.allow add:

1.2.3.0/24
4.3.2.0/24
*.tmc*

i assume *.tmc* is wrong syntax
 


I assume my hosts file syntax is wrong as i tried to disable ssh port 1234 connections but they are still there :(

# echo "" && echo "Number of connections per port" && netstat -tuna | awk -F':+| +' 'NR>2{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n | grep 1234 && echo "" && echo "Netstat port 1234:" && netstat -tlnp | grep 1234 && echo "" && echo "Hosts.deny and ssh contianing lines:" && cat /etc/hosts.deny|grep ssh

Number of connections per port
51 1234

Netstat port 1234:
tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN 1865/ssh

Hosts.deny and ssh contianing lines:
ssh : ALL EXCEPT /etc/hosts.allow2
 


Top