LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-30-2021, 11:41 AM   #1
Linus_Newb
LQ Newbie
 
Registered: Jun 2021
Posts: 1

Rep: Reputation: Disabled
Talking Firewall setup problem - newbie here, reading guides and learning.


Hello,

I was able to connect to my ubuntu server through ssh on port 369 no problem.

As soon as I begun setting up firewall with ufw command, can't connect to server again.

Here's my configuration :

<pre>sudo ufw status numbered
Status: active

To Action From
-- ------ ----
[ 1] 6000/tcp ALLOW IN Anywhere
[ 2] 123/udp ALLOW IN Anywhere
[ 3] 369/tcp ALLOW IN Anywhere
[ 4] 6000/tcp (v6) ALLOW IN Anywhere (v6)
[ 5] 123/udp (v6) ALLOW IN Anywhere (v6)
[ 6] 369/tcp (v6) ALLOW IN Anywhere (v6) </pre>


in the sshd_config

there's line
Port 369


And as soon as I disable firewall, I can log in BUT no longer on port 369 but on port 22?! ...

What is happening?!
 
Old 07-01-2021, 10:05 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730Reputation: 3730
Try checking what is really in your sshd configuration to see which port it is configured to use:

Code:
sudo /usr/sbin/sshd -T | grep -Ei 'port|listen'
The -T option does an extended configuration test and reports what the SSH server is actually deploying. See "man sshd"

Then you can double check with netstat and review the output to verify what sshd is actually listening. See "man netstat"

Code:
sudo netstat -lnpt | sed -n '1,2p; /sshd/p'
It should be the same as what you have in the configuration file. If not, you may have to have the SSH server reload its configuration.

Then if there is a mismatch between what the SSH server is using and what UFW is told to let in, one of those will have to be adjusted.

Last edited by Turbocapitalist; 07-01-2021 at 10:22 AM. Reason: sed, for headers too
 
Old 07-01-2021, 11:12 AM   #3
Trihexagonal
Member
 
Registered: Jul 2017
Posts: 362
Blog Entries: 1

Rep: Reputation: 334Reputation: 334Reputation: 334Reputation: 334
Quote:
Originally Posted by Linus_Newb View Post
Here's my configuration :

<pre>sudo ufw status numbered
Status: active

To Action From
-- ------ ----
[ 1] 6000/tcp ALLOW IN Anywhere
[ 2] 123/udp ALLOW IN Anywhere
[ 3] 369/tcp ALLOW IN Anywhere
[ 4] 6000/tcp (v6) ALLOW IN Anywhere (v6)
[ 5] 123/udp (v6) ALLOW IN Anywhere (v6)
[ 6] 369/tcp (v6) ALLOW IN Anywhere (v6) </pre>

What is happening?!
Looks like you're messing up to me. I'm not sure what you intended to do.

That's pretty nice of you to leave X-windows port TCP 6000 open like that. I'm sure somebody will make use of it.

Not to mention NTP. I'm pretty sure it uses TCP and UDP ports 123.


I've got a Kali box and use ufw on it, but it's busy ATM.

All you show is a little piece of not much of anything so I don't know what rules you're using.
However, these two rules at the top are supposed to go in there, the rest is how you make rules for ufw.
On Linux, just so you know I know you're using Linux:
Code:
ufw default deny incoming
ufw default allow outgoing

###Single port rules like this command will block known ports, TCP 22 in this case:
ufw block ssh

###Block ranges like this:
ufw block 6000:6010/tcp
ufw block 6000:6010/udp

###ABlock specific IP#'s like this
ufw block from 123.456.789.101
Here's the pf ruleset I use on my FreeBSD boxen:
Code:
### Macro name for external interface
ext_if = "em0"
netbios_tcp = "{ 22, 23, 25, 80, 110, 111, 123, 512, 513, 514, 515, 6000, 6010 }"
netbios_udp = "{ 123, 512, 513, 514, 515, 5353, 6000, 6010 }"

### Reassemble fragmented packets
scrub in on $ext_if all fragment reassemble

### Default deny everything
block log all

### Pass loopback
set skip on lo0

### Block spooks
antispoof for lo0
antispoof for $ext_if inet
block in from no-route to any
block in from urpf-failed to any
block in quick on $ext_if from any to 255.255.255.255
block in quick log on $ext_if from { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 255.255.255.255/32 } to any

### Block all IPv6
block in quick inet6 all
block out quick inet6 all

### Block to and from port 0
block quick proto { tcp, udp } from any port = 0 to any
block quick proto { tcp, udp } from any to any port = 0

### Block specific ports
block in quick log on $ext_if proto tcp from any to any port $netbios_tcp
block in quick log on $ext_if proto udp from any to any port $netbios_udp

### Keep and modulate state of outbound tcp, udp and icmp traffic
pass out on $ext_if proto { tcp, udp, icmp } from any to any modulate state
That will work an an OpenBSD box with a change in syntax of one word in the egress rule, out to egress (of course).


Here's what it looks like when it's at work on the FreeBSD box I'm using now:
Code:
root@bakemono:/ # pfctl -s all
FILTER RULES:
scrub in on em0 all fragment reassemble
block drop log all
block drop in on ! lo0 inet from 127.0.0.0/8 to any
block drop in on ! em0 inet from 192.168.1.0/24 to any
block drop in inet from 192.168.1.24 to any
block drop in on ! lo0 inet6 from ::1 to any
block drop in from no-route to any
block drop in from urpf-failed to any
block drop in quick on em0 inet from any to 255.255.255.255
block drop in log quick on em0 inet from 10.0.0.0/8 to any
block drop in log quick on em0 inet from 172.16.0.0/12 to any
block drop in log quick on em0 inet from 192.168.0.0/16 to any
block drop in log quick on em0 inet from 255.255.255.255 to any
block drop in quick inet6 all
block drop out quick inet6 all
block drop quick proto tcp from any port = 0 to any
block drop quick proto tcp from any to any port = 0
block drop quick proto udp from any port = 0 to any
block drop quick proto udp from any to any port = 0
block drop in log quick on em0 proto tcp from any to any port = ssh
block drop in log quick on em0 proto tcp from any to any port = telnet
block drop in log quick on em0 proto tcp from any to any port = smtp
block drop in log quick on em0 proto tcp from any to any port = http
block drop in log quick on em0 proto tcp from any to any port = pop3
block drop in log quick on em0 proto tcp from any to any port = sunrpc
block drop in log quick on em0 proto tcp from any to any port = ntp
block drop in log quick on em0 proto tcp from any to any port = exec
block drop in log quick on em0 proto tcp from any to any port = login
block drop in log quick on em0 proto tcp from any to any port = shell
block drop in log quick on em0 proto tcp from any to any port = printer
block drop in log quick on em0 proto tcp from any to any port = x11
block drop in log quick on em0 proto tcp from any to any port = x11-ssh
block drop in log quick on em0 proto udp from any to any port = ntp
block drop in log quick on em0 proto udp from any to any port = biff
block drop in log quick on em0 proto udp from any to any port = who
block drop in log quick on em0 proto udp from any to any port = syslog
block drop in log quick on em0 proto udp from any to any port = printer
block drop in log quick on em0 proto udp from any to any port = mdns
block drop in log quick on em0 proto udp from any to any port = x11
block drop in log quick on em0 proto udp from any to any port = x11-ssh
pass out on em0 proto tcp all flags S/SA modulate state
pass out on em0 proto udp all keep state
pass out on em0 proto icmp all keep state

Last edited by Trihexagonal; 07-01-2021 at 11:13 AM.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need better learning manuals or guides for Linux Mint and Linux Mint KDE Im here Linux - Newbie 2 01-18-2016 11:41 AM
seeking comprehensive guides to software sources and software installation guides geniuspenguis Linux - General 6 04-30-2015 06:14 AM
ethereal + packet capture reading guides ? kurrupt Linux - Networking 1 10-24-2005 12:34 PM
good newbie qmail/vpopmail setup guides? neocookie Linux - Newbie 1 08-22-2005 08:51 PM
help with client side NFS-firewall setup and server side NIS-firewall setup niverson Linux - Networking 3 02-02-2004 08:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:05 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