staging.inyokaproject.org

UFW

Status: Gelöst | Ubuntu-Version: Server 20.04 (Focal Fossa)
Antworten |

marsei85

Anmeldungsdatum:
3. November 2015

Beiträge: 148

Hallo,

ich habe immer mal wieder Ärger mit UFW, mein Eindruck ist, dass die Firewall zwar unkompliziert ist, aber of nicht funktioniert.

Ich wollte den SSH Port auf 5198 umstellen. In der VM kann ich mir folgendes bestätigen lassen:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
root@fm-xxxxxxx:^# ufw status
Status: active
To Action From
ーー  - -———
22 ALLOW Anywhere
5198 ALLOW Anywhere
80 ALLOW Anywhere
443 ALLOW Anywhere
22 (v6) ALLOW Anywhere (V6)
5198 (V6) ALLOW Anywhere (V6)
80 (v6) ALLOW Anywhere (V6)
443 (v6) ALLOW Anywhere (v6)

Anfragen mit

1
nc -zv 127.0.0.1 5198

und

1
nc -zv publicIP 5198

werden mit "succeeded!" beantwortet. Die VM läuft bei Ionos. Dort habe ich in den Firewall Einstellungen den Port ebenfalls geöffnet, wie ich es bei zahlreichen anderen VMs schon gemacht habe und wie es immer funktioniert.

Der Status des SSH Dienstes (systemctl status sshd) liefert mir dass der Dienst läuft unter Port 5198

Wenn ich jetzt von außen mich mit der VM verbinden möchte, bekomme ich:

1
ssh: connect to host publicIP port 5198: Connection refused

Das einzige was bisher hilft ist

1
iptables -I INPUT -m tcp -p tcp --dport 5198 -j ACCEPT

Wisst ihr wo der Fehler liegt?

lubux

Anmeldungsdatum:
21. November 2012

Beiträge: 14402

marsei85 schrieb:

Das einzige was bisher hilft ist

1
iptables -I INPUT -m tcp -p tcp --dport 5198 -j ACCEPT

Wisst ihr wo der Fehler liegt?

Der Fehler liegt in der Benutzung von UFW? Deaktiviere UFW und benutze iptables mit netfilter-persistent (aber Vorsicht, dass Du dich nicht aussperrst).

apt show netfilter-persistent

marsei85

(Themenstarter)

Anmeldungsdatum:
3. November 2015

Beiträge: 148

Danke, funktioniert!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Package: netfilter-persistent
Version: 1.0.14ubuntu1
Priority: optional
Section: universe/admin
Source: iptables-persistent
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: gustavo panizzo <gfa@zumbi.com.ar>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 38.9 kB
Pre-Depends: init-system-helpers (>= 1.54~)
Depends: lsb-base
Suggests: iptables-persistent
Breaks: iptables-persistent (<< 1~)
Replaces: iptables-persistent (<< 1~)
Download-Size: 7268 B
APT-Manual-Installed: yes
APT-Sources: http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
Description: boot-time loader for netfilter configuration
 This package provides a loader for netfilter configuration using a
 plugin-based architecture. It can load, flush and save a running
 configuration. Extending netfilter-persistent with plugins is trivial and can
 be done in any language.

N: There is 1 additional record. Please use the '-a' switch to see it

lubux

Anmeldungsdatum:
21. November 2012

Beiträge: 14402

marsei85 schrieb:

Danke, funktioniert!

Hmm, ... das war nur zur Info. Das ist noch keine Installation und schon gar keine Konfiguration von netfilter-persistent. ... und mit iptables (wegen den Regeln), muss man sich auch auskennen.
Wie sind jetzt die Ausgaben von:

apt policy netfilter-persistent ufw
systemctl status ufw
sudo iptables -nvx -L

?

marsei85

(Themenstarter)

Anmeldungsdatum:
3. November 2015

Beiträge: 148

ich meinte die iptables regel, habe es mit iptables-persistent Dauerhaft gemacht (hoffe ich). Über Ionos gibt es zum Glück noch eine VNC Konsole, falls man sich aussperrt.

marsei85

(Themenstarter)

Anmeldungsdatum:
3. November 2015

Beiträge: 148

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
root@fm-xxxxxx:~# apt policy netfilter-persistent ufw
netfilter-persistent:
  Installed: 1.0.14ubuntu1
  Candidate: 1.0.14ubuntu1
  Version table:
 *** 1.0.14ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
        100 /var/lib/dpkg/status
     1.0.14 500
        500 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages
ufw:
  Installed: (none)
  Candidate: 0.36-6ubuntu1.1
  Version table:
     0.36-6ubuntu1.1 500
        500 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
     0.36-6ubuntu1 -1
        100 /var/lib/dpkg/status
     0.36-6 500
        500 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
root@fm-xxxxxx:~# systemctl status ufw
● ufw.service
     Loaded: masked (Reason: Unit ufw.service is masked.)
     Active: inactive (dead)
root@fm-xxxxxx:~# sudo iptables -nvx -L
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
      13     1010 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443
      36     2396 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
    1280    72049 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5198
   30568 202460240 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED,DNAT
     944    58668 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
     314    20359 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     314    20359 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       5      249 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
      29     3742 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
       0        0 ufw-before-logging-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-before-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-after-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-after-logging-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-reject-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-track-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED,DNAT
       0        0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
       0        0 FORWARD_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FORWARD_IN_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FORWARD_OUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
       0        0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
       0        0 ufw-before-logging-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-before-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-after-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-after-logging-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-reject-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ufw-track-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 6919 packets, 639641 bytes)
    pkts      bytes target     prot opt in     out     source               destination         
   17111  5218951 ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0           
   11294  3343106 OUTPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    9006  1492693 ufw-before-logging-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    9006  1492693 ufw-before-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    6996   650646 ufw-after-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    6996   650646 ufw-after-logging-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    6996   650646 ufw-reject-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    6996   650646 ufw-track-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD_IN_ZONES (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 FWDI_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_OUT_ZONES (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 FWDO_public  all  --  *      +       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_direct (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDI_public (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 FWDI_public_pre  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDI_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDI_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDI_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDI_public_post  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FWDI_public_allow (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDI_public_deny (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDI_public_log (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDI_public_post (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDI_public_pre (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDO_public (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
       0        0 FWDO_public_pre  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDO_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDO_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDO_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 FWDO_public_post  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FWDO_public_allow (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDO_public_deny (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDO_public_log (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDO_public_post (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain FWDO_public_pre (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain INPUT_ZONES (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
     314    20359 IN_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain INPUT_direct (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain IN_public (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
     314    20359 IN_public_pre  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     314    20359 IN_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     314    20359 IN_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
     314    20359 IN_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
      34     3991 IN_public_post  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
       0        0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain IN_public_allow (1 references)
    pkts      bytes target     prot opt in     out     source               destination         
     131     7660 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22 ctstate NEW,UNTRACKED
      74     4384 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 ctstate NEW,UNTRACKED
      75     4324 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443 ctstate NEW,UNTRACKED
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:2399 ctstate NEW,UNTRACKED
       0        0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5003 ctstate NEW,UNTRACKED

Chain IN_public_deny (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain IN_public_log (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain IN_public_post (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain IN_public_pre (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain OUTPUT_direct (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-forward (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-input (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-logging-forward (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-logging-input (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-logging-output (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-after-output (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-forward (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-input (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-forward (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-input (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-output (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-before-output (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-reject-forward (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-reject-input (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-reject-output (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-track-forward (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-track-input (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

Chain ufw-track-output (1 references)
    pkts      bytes target     prot opt in     out     source               destination  

kB Team-Icon

Supporter, Wikiteam
Avatar von kB

Anmeldungsdatum:
4. Oktober 2007

Beiträge: 9837

marsei85 schrieb:

ich meinte die iptables regel, habe es mit iptables-persistent Dauerhaft gemacht (hoffe ich).

Es ist eine ganz schlechte Idee, konkurrierende Programme (hier: UFW und iptables) zur Konfiguration von Netfilter gleichzeitig einzusetzen.

Bitte nicht das Arbeitsergebnis von UFW versuchen mit eigenen Regeln für iptables nachzubessern!

  • Wenn man UFW einsetzt, dann nur UFW.

  • Wenn man direkt mit iptables arbeitet, dann kein UFW verwenden.

lubux

Anmeldungsdatum:
21. November 2012

Beiträge: 14402

marsei85 schrieb:

root@fm-xxxxxx:~# apt policy netfilter-persistent ufw
netfilter-persistent:
  Installed: 1.0.14ubuntu1
ufw:
  Installed: (none)

     Loaded: masked (Reason: Unit ufw.service is masked.)

Chain ufw-after-input (1 references)
    pkts      bytes target     prot opt in     out     source               destination         

OK, aber es gibt noch chains von der ufw, was nicht so schön ist. Hast Du die service-unit der ufw, vor deren Deinstallation, auf masked gestellt?
Schau nach, was für iptables/ufw-Regeln Du jetzt im netfilter-persistent-Script (/etc/iptables/rules.v4) hast, die Du evtl. gar nicht brauchst.
M. E. wäre es besser gewesen, vor dem iptables-save, die nicht benötigten Regeln zu löschen, oder?

marsei85

(Themenstarter)

Anmeldungsdatum:
3. November 2015

Beiträge: 148

Falls noch jemand an iptables verzweifelt. Es liegt wahrscheinlich daran dass man firewall-cmd nehmen muss. Ich weiß nicht warum diese Karteileichen noch in den Betriebssystemen rumgeschleppt werden wenn sie nicht mehr funktionieren...

encbladexp Team-Icon

Ehemaliger
Avatar von encbladexp

Anmeldungsdatum:
16. Februar 2007

Beiträge: 17531

iptables und nftables sind halt direkte Frontends für netfilter bzw was auch immer gerade im Kernel läuft, firewalld/firewall-cmd ist ein anderes Frontend, was im Hintergrund auch nur dem Kernel sagt was Sache ist. Keines davon ist eine Karteileiche.

Antworten |