LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-06-2016, 04:56 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 527

Rep: Reputation: Disabled
Hosts file syntax when want to deny multiple IP subnets or partial hostnames?


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
 
Old 02-06-2016, 05:19 AM   #2
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Code:
man hosts.allow
 
Old 02-06-2016, 07:00 AM   #3
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Quote:
man hosts.allow
thanks, i already found this, but i cant find it in that

---

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

Quote:
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
 
Old 02-06-2016, 02:22 PM   #4
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
The service "ssh" is defined as port 22, so your hosts rule won't apply to port 1234.
 
Old 02-07-2016, 04:59 AM   #5
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by descendant_command View Post
The service "ssh" is defined as port 22, so your hosts rule won't apply to port 1234.
my ssh listens on nonstandard port, i modified sshd config..
 
Old 02-07-2016, 08:33 AM   #6
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Code:
grep ssh /etc/services
 
Old 02-08-2016, 09:16 AM   #7
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by descendant_command View Post
Code:
grep ssh /etc/services
Quote:
ssh 22/tcp # The Secure Shell (SSH) Protocol
ssh 22/udp # The Secure Shell (SSH) Protocol
x11-ssh-offset 6010/tcp # SSH X11 forwarding offset
ssh 22/sctp # SSH
sshell 614/tcp # SSLshell
sshell 614/udp # SSLshell
netconf-ssh 830/tcp # NETCONF over SSH
netconf-ssh 830/udp # NETCONF over SSH
sdo-ssh 3897/tcp # Simple Distributed Objects over SSH
sdo-ssh 3897/udp # Simple Distributed Objects over SSH
snmpssh 5161/tcp # SNMP over SSH Transport Model
snmpssh-trap 5162/tcp # SNMP Notification over SSH Transport Model
tl1-ssh 6252/tcp # TL1 over SSH
tl1-ssh 6252/udp # TL1 over SSH
ssh-mgmt 17235/tcp # SSH Tectia Manager
ssh-mgmt 17235/udp # SSH Tectia Manager
????
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to 'include file' in hosts.allow or hosts.deny? arfon Linux - Security 8 01-19-2018 09:54 PM
Info on /etc/hosts.deny file tnjones Linux - Software 2 09-24-2008 02:49 PM
Need a little advice on the hosts.deny file binarybob0001 Linux - Networking 0 11-05-2007 10:22 AM
Entries in hosts.deny file tensigh Linux - Security 8 05-02-2006 04:52 PM
hosts file reverses IP and hostnames mike114327 Linux - Networking 0 10-12-2004 02:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration